-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Add helm prometheus metrics support and handle MultiNamespace scenario for metrics #2603
Add helm prometheus metrics support and handle MultiNamespace scenario for metrics #2603
Conversation
serveCRMetrics
bfe93ad
to
c34f6aa
Compare
c34f6aa
to
082a4c2
Compare
082a4c2
to
ad4ce32
Compare
Hi @lilic, Really tks for your review. All your suggestions are addressed, feel free to check it again. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/lgtm
internal/scaffold/cmd_test.go
Outdated
// Generate and serve custom resource specific metrics. | ||
err = kubemetrics.GenerateAndServeCRMetrics(cfg, ns, filteredGVK, metricsHost, operatorMetricsPort) | ||
if err != nil { | ||
return err | ||
} | ||
return nil | ||
} | ||
|
||
// getNamespacesForMetrics wil return all namespaces which will be used to export the metrics |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I may be missing something, why is this function duplicated here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The cmd_test.go needs to be == cmd.go. It will verify the scaffold impl.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like a lot of the metrics code is duplicated, is there a way we can centralize the pieces of logic that are shared to make this easier to maintain in the future? If that sort of refactor is out of scope I'd still like to track it somewhere
pkg/ansible/run.go
Outdated
@@ -285,3 +283,20 @@ func getAnsibleDebugLog() bool { | |||
} | |||
return val | |||
} | |||
|
|||
// getNamespacesForMetrics wil return all namespaces which will be used to export the metrics |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a way we can centralize this logic? It seems like it's duplicated several times
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved to the lib.
pkg/helm/run.go
Outdated
} | ||
return nil | ||
} | ||
|
||
// getNamespacesForMetrics wil return all namespaces which will be used to export the metrics | ||
func getNamespacesForMetrics(operatorNs string) ([]string, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fourth time this is implemented
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The same implementation to generate the metrics is used for Ansible, Helm and GO.
The other is the tests which are updated with the changes made.
// Generate and serve custom resource specific metrics. | ||
err = kubemetrics.GenerateAndServeCRMetrics(cfg, ns, filteredGVK, metricsHost, operatorMetricsPort) | ||
if err != nil { | ||
return err | ||
} | ||
return nil | ||
} | ||
|
||
// getNamespacesForMetrics wil return all namespaces which will be used to export the metrics | ||
func getNamespacesForMetrics(operatorNs string) ([]string, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we move this to a library function and just call it repeatedly?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
|
||
// serveCRMetrics gets the Operator/CustomResource GVKs and generates metrics based on those types. | ||
// It serves those metrics on "http://metricsHost:operatorMetricsPort". | ||
func serveCRMetrics(cfg *rest.Config, operatorNs string, gvks []schema.GroupVersionKind) error { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does the implementation of this function vary by operator type or can we use a single implementation?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The implementation is quite similar for all types.
However, Ansible and Helm will pass the gvks when in the GO we will filter it.
|
||
// Generate metrics from the WATCH_NAMESPACES value if it contains multiple namespaces | ||
if strings.Contains(watchNamespace, ",") { | ||
ns = strings.Split(watchNamespace, ",") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we want to always export metrics in the operatorNs
or is it intentional that we leave it out if specific watchNamespaces are set?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The WATCH_NAMESPACES can be the operator namespace (namespaced-scope), empty in the case of cluster-scoped or the multi namespace scenario.
So, the idea here is:
By default export the metrics from the operator namespace unless it is the multi namespace which is the case that we know the List of namespaces that the operator will be dealing wth.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/lgtm
New changes are detected. LGTM label has been removed. |
Description of the change:
Motivation for the change: