Skip to content

Migrate metrics to use pkg/metrics helpers #2798

@ghost

Description

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/metricsRelated to prometheus metrics

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions