-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Ansible add metrics #5438
Ansible add metrics #5438
Conversation
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 think the logs need to get cleaned up before merging. And I found a typo as well.
c8c1b15
to
dbb8434
Compare
dbb8434
to
545da23
Compare
Metrics are created with the osdk_metrics module in operator-sdk-ansible-util which communicates with an ansible API server. Signed-off-by: austin <[email protected]>
545da23
to
a2e6412
Compare
Signed-off-by: austin <[email protected]>
Signed-off-by: austin <[email protected]>
Signed-off-by: austin <[email protected]>
Signed-off-by: austin <[email protected]>
Signed-off-by: austin <[email protected]>
Signed-off-by: austin <[email protected]>
Signed-off-by: austin <[email protected]>
Signed-off-by: austin <[email protected]>
Signed-off-by: austin <[email protected]>
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 only change that I think really needs to be made is un-go-routining the server function and letting the caller decide to run it. Everything else is refactoring and style things to make the function more clear/readable. I think at least you should break the main HandleUserMetric
function into some helper functions to make it more self-documenting.
Signed-off-by: austin <[email protected]>
Signed-off-by: austin <[email protected]>
bdcc650
to
90f0035
Compare
Signed-off-by: austin <[email protected]>
Signed-off-by: austin <[email protected]>
Signed-off-by: austin <[email protected]>
Signed-off-by: austin <[email protected]>
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.
Two small fixes then LGTM
switch v := collector.(type) { | ||
// Gauge must be first, because a Counter is a Gauge, but a Gauge is not a Counter. | ||
case prometheus.Gauge: | ||
if err := handleGauge(metricSpec, v); err != nil { | ||
return err | ||
} | ||
case prometheus.Counter: | ||
if err := handleCounter(metricSpec, v); err != nil { | ||
return err | ||
} | ||
// Histogram and Summary interfaces are identical, so we accept either case. | ||
case prometheus.Histogram: | ||
if err := handleSummaryOrHistogram(metricSpec, v); err != nil { | ||
return err | ||
} | ||
} |
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.
Instead of the type switch, you can do:
switch {
case metricSpec.Gauge != nil:
// gauge stuff
case metricSpec.Counter != nil:
// counter stuff
// etc
}
Not a blocker for this PR, but would allow you to split the summary and histogram helper functions.
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 dont think that will work in edge cases where the user is erroneously mixing types. For example, if the user creates a metric "my_counter_metric", and then calls the gauge function on "my_counter_metric". In this case, the current code will see that it is a counter, and handle it as a counter, and send a failure message that "you cant change counter to gauge". For your suggestion, it will attempt to handle it as a gauge, which could cause silent problems I think?
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.
Gotcha, do we validate anywhere else that for existing metrics, the type doesn't change?
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.
We didn't collect custom metrics from users, so AFAIK it hasn't come up before.
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
Signed-off-by: austin <[email protected]>
Signed-off-by: austin <[email protected]>
Signed-off-by: austin <[email protected]>
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
Description of the change:
Motivation for the change:
Checklist
If the pull request includes user-facing changes, extra documentation is required:
changelog/fragments
(seechangelog/fragments/00-template.yaml
)website/content/en/docs