Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨📖 [plugins]: Create monitoring plugin #3106

Closed

Conversation

avlitman
Copy link

We would like to add a new monitoring plugin that will help operators developer with setting up Prometheus based monitoring for their operator, will provide them with best practices and tooling to shorten their time to get up to speed with monitoring requirements and help with standardizing the way monitoring is implemented in operators.

Signed-off-by: Aviv Litman [email protected]

@k8s-ci-robot k8s-ci-robot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Nov 30, 2022
@linux-foundation-easycla
Copy link

linux-foundation-easycla bot commented Nov 30, 2022

CLA Not Signed

@k8s-ci-robot k8s-ci-robot added cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. labels Nov 30, 2022
@k8s-ci-robot
Copy link
Contributor

Hi @avlitman. Thanks for your PR.

I'm waiting for a kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: avlitman
Once this PR has been reviewed and has the lgtm label, please assign jmrodri for approval by writing /assign @jmrodri in a comment. For more information see the Kubernetes Code Review Process.

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@avlitman
Copy link
Author

avlitman commented Nov 30, 2022

Hi @machadovilaca @sradco @varshaprasad96 @everettraven @assafad.

Notes:
@varshaprasad96 @everettraven Please focus on the plugin structure and not the content yet in your review.

@machadovilaca:
I will appreciate if your review will also refer to the comments.
And in /monitoring/tools/metricsdocs.go
I need help with extracting the repo name substring from {{ .Repo }} since I want to use it in the consts part of the file,
I was not able to find the right way to use filepath.Base( {{ .Repo }} ).
last thing, I added summary and Histogram in util.go and we need to verify that the syntax is correct, and will work with real metrics.

@avlitman avlitman force-pushed the create-monitoring-plugin branch 3 times, most recently from a36bb60 to dba9c2b Compare December 1, 2022 12:15
@avlitman avlitman changed the title [WIP] ✨📖 [plugins]: Create monitoring plugin ✨📖 [plugins]: Create monitoring plugin Dec 1, 2022
@k8s-ci-robot k8s-ci-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Dec 1, 2022
@avlitman avlitman force-pushed the create-monitoring-plugin branch from dba9c2b to e5df7f7 Compare December 1, 2022 13:05
Copy link
Member

@camilamacedo86 camilamacedo86 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We will need to discuss this one. So, just putting in hold for we are able to properly get the review and discuss the initiative.

@@ -132,16 +135,17 @@ scaffold_test_project project-v2 --project-version=2
# [Currently, default CLI plugin] - Project version 3 (default) uses plugin go/v3 (default).
scaffold_test_project project-v3
scaffold_test_project project-v3-multigroup
scaffold_test_project project-v3-declarative-v1 --plugins="go/v3,declarative,grafana/v1-alpha"
scaffold_test_project project-v3-declarative-v1 --plugins="go/v3,declarative,grafana/v1-alpha,monitoring/v1-alpha"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we you please do not add this plugin here? we should have in the declarative one juts the declarative.
Therefore, we need to remove the grafana/v1-alpha from master branch.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@camilamacedo86
We need to test both the init and edit commands with the new monitoring plugin.
at first I used scaffold_test_project project-v4-monitoring --plugins="go/v4-alpha,monitoring.kubebuilder.io/v1-alpha" to test the init commend.

but it created a confusing naming under testdata folder
project-v*-monitoring
project-v*-with-monitoring

Later I followed @varshaprasad96 suggestion:
"
I would suggest to test both the init and edit commands. We should have scaffold_test_project project-v4-with-monitoring and the other scaffolding which calls this command chained with other plugins (whichever seems fit), probably `scaffold_test_project project-v4-declarative-v1 --plugins="go/v4-alpha,declarative,grafana/v1-alpha,monitoring/v1-alpha". This will make sure that a user with pre-scaffolded project is able to add the monitoring plugin with the edit command, as well as someone who is scaffolding their project for the first time can chain this plugin with existing ones during init.
"

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@varshaprasad96 and @everettraven suggested this to test all the plugins together, in oreder to see there are no conflicts.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So thinking about this again (I now think I understand the original problem better than I did before), I understand @camilamacedo86's reasoning for wanting them separate (definitely better for testing/maintenance IMO).

I don't feel particularly strongly one way or another but if I had to choose I would probably vote for separate project scaffolds. I understand that it could be confusing names under the testdata folder but in the end I think we need to do what is better for testing and maintenance. I think maybe naming the projects project-v*-init-monitoring and project-v*-edit-monitoring might make it a bit more clear which project was created with which subcommand.

scaffold_test_project project-v3-config --component-config
scaffold_test_project project-v3-with-deploy-image
scaffold_test_project project-v3-with-metrics
scaffold_test_project project-v3-with-monitoring
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please add this new plugin to the metrics sample with seems the category releated and allow us to check only the diff scaffolds that will be done by it?

Copy link
Author

@avlitman avlitman Dec 1, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@camilamacedo86 This is the plan, and it will be done in later PR.

// constant parts of the file
const (
title = "# sigs.k8s.io/kubebuilder/testdata/project-v4-declarative-v1 Operator Metrics\n"
background = "This document aims to help users that are not familiar with metrics exposed by the sigs.k8s.io/kubebuilder/testdata/project-v4-declarative-v1 operator.\n" +
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we cannot scaffold it by default.
The final result of the plugin should not point out users for the master samples.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, same of : https://github.com/kubernetes-sigs/kubebuilder/pull/3106/files#r1037114035

It does not fit to an end-project scaffold. It should be a lib, tool and etc.

Copy link
Author

@avlitman avlitman Dec 1, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The plan is to give an example scaffold for adding new metrics, the files can be commented also.
but it's not by default, the user will need to init/edit with monitoring plugin in order to get these files.

footer = footerHeading + footerContent
)

func main() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is really required to implement a util to do that?
If that is a common good practice so have not tools and etc that does it already?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@camilamacedo86 Yes, This is a very useful addition for creating an automated metrics documentation.
It we be automatically updated after every new metric is added.
We plan to also add to it the recording rules, since they are used the same as metrics

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think what @camilamacedo86 is trying to point out here is that if every operator project that wants to create/use metrics needs to use this tooling, it might be better to instead have a library/binary with this functionality that can import/download/build and be used instead of scaffolding it in every operator project.

I agree with @camilamacedo86 here that we should probably consider finding a way to make this code reusable by many operator projects without actually scaffolding this code in every operator project.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, @avlitman @sradco,

If is a good practice to generate the docs so do not exist projects that are responsible for that already? Is really required to implement and build a binary for it ?

@@ -0,0 +1,145 @@
package util
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should not this kind of implementation fit better in a lib such as controller-runtime or operator-lib or a new one since prometheus-lib?

If all projects would need to use this func so that does not seems reasonable to be scaffolded in a plugin for the final projects. That really seems to be more appropriated in a lib (ihmo)

Copy link
Author

@avlitman avlitman Dec 1, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@camilamacedo86 Not sure I understand right your comment, but this implementation (util) is only for adding Prometheus metrics to the operator.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think what @camilamacedo86 is trying to point out here is that if every operator that wants to use metrics will have to use these utility functions, it may be better to make them a Go library that can be imported rather than scaffolded in every project.

I guess this ends up posing the question - Will every operator that wants to use metrics need to implement these utility functions?

Copy link
Member

@camilamacedo86 camilamacedo86 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(ihmo) what is proposed by this plugin do the scaffold fit better in libs/tools and not to the final "Operator" project itself. The project itself could take benefit and use the lib to generate the metrics and/or the binary to build the docs. Therefore, explain the good practices and how to use the libs / tools that could fit in docs.

However, if you would like to have a plugin to scaffold that and does not go along within the above thought then I think that is good case for external plugins. @varshaprasad96 @everettraven @Kavinjsir @erikgb wdyt? What are your thoughts about this one?

@avlitman
Copy link
Author

avlitman commented Dec 1, 2022

We will need to discuss this one. So, just putting in hold for we are able to properly get the review and discuss the initiative.

Hi @camilamacedo86 , thank you so much for reviewing this PR!
We did discuses this issue and got approved from the community see #3078

@avlitman avlitman force-pushed the create-monitoring-plugin branch 2 times, most recently from cff5220 to 85cdb6e Compare December 1, 2022 15:32
Copy link
Contributor

@everettraven everettraven left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First round. Overall everything looks good, but I share a few of the concerns @camilamacedo86 has regarding scaffolding code in every operator project that may be better suited to being a library.


- `monitoring/`
- `main.go`
- `MakeFile`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit:

Suggested change
- `MakeFile`
- `Makefile`


var OperatorMetrics = []util.Metric{
// When adding new metrics, Please follow the naming conventions best practices
// TODO: Add the link to the Observability Best Practices - Metrics Naming
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would recommend moving this TODO comment out of this template. Having it in the template makes it seem like it is something the user of the monitoring plugin will have to do, but should instead be something that is included in the template (once it is available).

}
}

// TODO: add here a comment about the functions to explain what they do
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This TODO comment seems more related to the maintainers of the monitoring plugin and not the user. I would recommend moving it out of the scaffold template.

Comment on lines +40 to +45
_out/metricsdocs > docs/monitoring/metrics.md

.PHONY: build-metricsdocs
build-metricsdocs:
go build -ldflags="${LDFLAGS}" -o _out/metricsdocs ./monitoring/tools/metricsdocs.go
`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this is specifically a tool for development purposes (i.e not running in production as part of the operator) I think it might be a bit overkill to actually build a binary for generating the metrics docs.

I would personally prefer something like:

Suggested change
_out/metricsdocs > docs/monitoring/metrics.md
.PHONY: build-metricsdocs
build-metricsdocs:
go build -ldflags="${LDFLAGS}" -o _out/metricsdocs ./monitoring/tools/metricsdocs.go
`
go run ./monitoring/tools/metricsdocs.go > docs/monitoring/metrics.md
`

Thoughts?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that would fit well as a third-party project with the lib.
Therefore it shows too much Prometheus specific why not add those in the Prometheus project (https://github.com/prometheus/) and allow anyone that is using kubebuilder or not to take advantage of it?

@@ -132,16 +135,17 @@ scaffold_test_project project-v2 --project-version=2
# [Currently, default CLI plugin] - Project version 3 (default) uses plugin go/v3 (default).
scaffold_test_project project-v3
scaffold_test_project project-v3-multigroup
scaffold_test_project project-v3-declarative-v1 --plugins="go/v3,declarative,grafana/v1-alpha"
scaffold_test_project project-v3-declarative-v1 --plugins="go/v3,declarative,grafana/v1-alpha,monitoring/v1-alpha"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So thinking about this again (I now think I understand the original problem better than I did before), I understand @camilamacedo86's reasoning for wanting them separate (definitely better for testing/maintenance IMO).

I don't feel particularly strongly one way or another but if I had to choose I would probably vote for separate project scaffolds. I understand that it could be confusing names under the testdata folder but in the end I think we need to do what is better for testing and maintenance. I think maybe naming the projects project-v*-init-monitoring and project-v*-edit-monitoring might make it a bit more clear which project was created with which subcommand.

@@ -0,0 +1,145 @@
package util
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think what @camilamacedo86 is trying to point out here is that if every operator that wants to use metrics will have to use these utility functions, it may be better to make them a Go library that can be imported rather than scaffolded in every project.

I guess this ends up posing the question - Will every operator that wants to use metrics need to implement these utility functions?

footer = footerHeading + footerContent
)

func main() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think what @camilamacedo86 is trying to point out here is that if every operator project that wants to create/use metrics needs to use this tooling, it might be better to instead have a library/binary with this functionality that can import/download/build and be used instead of scaffolding it in every operator project.

I agree with @camilamacedo86 here that we should probably consider finding a way to make this code reusable by many operator projects without actually scaffolding this code in every operator project.

@avlitman avlitman force-pushed the create-monitoring-plugin branch from 85cdb6e to eb95c9b Compare December 1, 2022 15:53
GitHub-issue: kubernetes-sigs#3078
Signed-off-by: Aviv Litman <[email protected]>

Uncomment monitoring go files

Signed-off-by: João Vilaça <[email protected]>

Generate working monitoring scaffolding

Signed-off-by: João Vilaça <[email protected]>

Allow kubebuilder init with monitoring bundle

Signed-off-by: João Vilaça <[email protected]>

Add metrics register to main file

Signed-off-by: João Vilaça <[email protected]>

Update testdata

Signed-off-by: João Vilaça <[email protected]>

Improve comments

Signed-off-by: Aviv Litman <[email protected]>
@avlitman avlitman force-pushed the create-monitoring-plugin branch from eb95c9b to 28fe31e Compare December 1, 2022 17:14
@Kavinjsir
Copy link
Contributor

(ihmo) what is proposed by this plugin do the scaffold fit better in libs/tools and not to the final "Operator" project itself. The project itself could take benefit and use the lib to generate the metrics and/or the binary to build the docs. Therefore, explain the good practices and how to use the libs / tools that could fit in docs.

@avlitman I have a similar idea to what @camilamacedo86 brought:
It feels more flexible to have this feature as a library, in that case, any operator project can imported. (so that they don't necessarily to be an origin scaffold layout from kubebuilder).

@varshaprasad96
Copy link
Member

@camilamacedo86 @Kavinjsir I have added the questions based on our discussions and some of my thoughts here: #3078 (comment).

@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Dec 9, 2022
@k8s-ci-robot
Copy link
Contributor

@avlitman: PR needs rebase.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@avlitman
Copy link
Author

avlitman commented Dec 19, 2022

Hi @camilamacedo86 @everettraven @varshaprasad96 @Kavinjsir @sradco
First I want to thank you for taking the time to help and review this issue.

Since we still discussing the implementation method, and the capacity to maintain this by our team.
I would suggested closing this PR, and open a new one in case we decide to go foreword with a new method.

@camilamacedo86
Copy link
Member

Closing this one as not accepted, for further information see: #3078.
Thank you for your contribution and understanding.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add Monitoring Plugin
7 participants