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

Ansible add metrics #5438

Merged
merged 19 commits into from
Jan 26, 2022
Merged

Conversation

asmacdo
Copy link
Member

@asmacdo asmacdo commented Dec 8, 2021

Description of the change:

Motivation for the change:

Checklist

If the pull request includes user-facing changes, extra documentation is required:

Copy link
Member

@jmrodri jmrodri left a 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.

@openshift-ci openshift-ci bot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jan 7, 2022
@asmacdo asmacdo added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jan 21, 2022
@asmacdo asmacdo force-pushed the ansible-add-metrics branch from c8c1b15 to dbb8434 Compare January 24, 2022 02:20
@openshift-ci openshift-ci bot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jan 24, 2022
@asmacdo asmacdo force-pushed the ansible-add-metrics branch from dbb8434 to 545da23 Compare January 24, 2022 02:21
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]>
@asmacdo asmacdo force-pushed the ansible-add-metrics branch from 545da23 to a2e6412 Compare January 24, 2022 02:31
Signed-off-by: austin <[email protected]>
Signed-off-by: austin <[email protected]>
Signed-off-by: austin <[email protected]>
Copy link
Contributor

@ryantking ryantking left a 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]>
@jmrodri jmrodri dismissed their stale review January 25, 2022 20:52

My items were addressed.

Signed-off-by: austin <[email protected]>
@asmacdo asmacdo force-pushed the ansible-add-metrics branch from bdcc650 to 90f0035 Compare January 25, 2022 21:07
Copy link
Contributor

@ryantking ryantking left a 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

Comment on lines +225 to +240
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
}
}
Copy link
Contributor

@ryantking ryantking Jan 26, 2022

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.

Copy link
Member Author

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?

Copy link
Contributor

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?

Copy link
Member Author

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.

Copy link
Member

@fabianvf fabianvf left a comment

Choose a reason for hiding this comment

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

lgtm

Copy link
Contributor

@ryantking ryantking left a comment

Choose a reason for hiding this comment

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

lgtm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants