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

Use AllMetrics for enable & disable lists instead of ignoreWhitelist #2910

Merged
merged 7 commits into from
Aug 20, 2021

Conversation

eero-t
Copy link
Contributor

@eero-t eero-t commented Jul 15, 2021

Use of AllMetrics instead of ignoreWhitelist, adds CpuUsageMetrics ("cpu") & AppMetrics ("app"), which are already checked by prometheus export code, to metrics that can be disabled/enabled from command line.

That also makes metricSetValue type redundant, as it can now be replaced with MetricSet use. Removing it requires moving String() & Set() methods, used for options texts and validating given metrics options, to factory.go.

toIncludedMetrics() one-line wrapper is also removed, as inlining container.AllMetrics.Difference() call makes the code intent more explicit, and is about same amount of code.

@k8s-ci-robot
Copy link
Collaborator

Hi @eero-t. Thanks for your PR.

I'm waiting for a google 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.

Comment on lines 122 to 136
func (ms *MetricSet) Set(value string) error {
*ms = MetricSet{}
if value == "" {
return nil
}
for _, metric := range strings.Split(value, ",") {
if AllMetrics.Has(MetricKind(metric)) {
(*ms).Add(MetricKind(metric))
} else {
return fmt.Errorf("unsupported metric %q specified", metric)
}
}
return nil
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you add a comment to MetricSet and state that the struct is not thread safe? And make sure that the struct is not accessed from multiple goroutines in cAdvisor?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I added couple of commits clarifying & documenting MericSet thread-safety (removing unused Append() method, changing Add() method to private one and documenting Set() method usage).

@iwankgb
Copy link
Collaborator

iwankgb commented Aug 14, 2021

/ok-to-test

Fixes also -disable_metrics 'process' metric name in running.md,
and updates list of '-disable_metrics' option metrics. Metrics
names are now listed in sorted order.

Note: I've followed the existing documentation convention of giving
cAdvisor option names with two dashes (--enable_metrics) although
current cAdvisor uses only one dash (-enable_metrics).
Use of AllMetrics instead of ignoreWhitelist, adds CpuUsageMetrics
("cpu") & AppMetrics ("app") to metrics that can be disabled/enabled
from command line.  Whether they are enabled is already checked by
prometheus export code.

That also makes metricSetValue type redundant, as it can now be
replaced with MetricSet use.  Removing it requires moving String() &
Set() methods used by flag package for option handling and validating
given metrics options, to factory.go.
Inlining container.AllMetrics.Difference() call makes the code intent
more explicit, and is about same amount of code.
Both Add() and Set() methods modify the existing mapping.

As Add() method is used only by Set() and Difference(), and
in latter it's done thread-safely, make add private method
and document that Set() is not thread-safe.

Set() is used only by flag package through Value interface,
which is documented to be called only once, i.e. it's safe.
Add app & cpu metrics to relevant places.
@eero-t
Copy link
Contributor Author

eero-t commented Aug 19, 2021

Changes:

  • Split toInclude() removal to a separate commit as it's unrelated change touching same lines of code
  • Added commit clarifying MetricSet thread-safety (see commit message!)
  • Related to that, added commit removing unused MetricSet.Append() method
  • Added commit updating the documentation => this PR is now rebased on other PR that fixes documentation for an earlier merged PR

@Creatone Creatone self-requested a review August 20, 2021 09:37
Copy link
Collaborator

@Creatone Creatone 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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants