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

Migrate metrics to use pkg/metrics helpers #2798

Open
lambdanis opened this issue Aug 14, 2024 · 0 comments
Open

Migrate metrics to use pkg/metrics helpers #2798

lambdanis opened this issue Aug 14, 2024 · 0 comments
Labels
area/metrics Related to prometheus metrics

Comments

@lambdanis
Copy link
Contributor

lambdanis commented Aug 14, 2024

pkg/metrics package provides functions to define metrics, which provide a few features on top of regular prometheus functions:

  • define possible values for labels with known values
  • define example values for metrics with unknown values
  • initialize metrics with known labelsets at startup - for metrics with only constrained labels this is done automatically for all label combinations, but initialization function can be also provided explicitly

Ideally metrics with variable labels (defined with prometheus.New*Vec) should be migrated to use new helpers. This gives us a few benefits:

  • Metrics are initialized at startup without the need for a separate initialization function defined and called somewhere else in the code (this was the tricky part of defining metrics so far, devs just needed to know that they should write initialization code).
  • Metrics reference doc is generated using labels provided in the metric definition, not a separate initialization function (this is particularly useful for metrics with unconstrained labels, as they needed separate "example" label values for docs, and custom collectors, they needed whole separate types for docs).
  • For labels with known values these values are constrained at runtime (this ensures that metrics cardinality and related resources usage are stable).

Note that there's little point in migrating metrics with no variable labels (defined e.g. with prometheus.NewCounter no Vec).

Examples:
tetragon_policyfilter_operations_total: 6feacec

@lambdanis lambdanis added the area/metrics Related to prometheus metrics label Aug 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/metrics Related to prometheus metrics
Projects
Development

No branches or pull requests

1 participant