Skip to content

fix(metrics): skip unsupported Prometheus metric types - #1384

Closed
MartinForReal wants to merge 1 commit into
kubernetes:masterfrom
MartinForReal:fix/opencensus-typeless-metrics
Closed

MartinForReal wants to merge 1 commit into
kubernetes:masterfrom
MartinForReal:fix/opencensus-typeless-metrics

Conversation

@MartinForReal

Copy link
Copy Markdown
Member

What type of PR is this?

/kind bug

What this PR does / why we need it:

This replaces the stale #1210. Current master already uses OpenTelemetry: #1297 merged the OpenCensus -> OpenTelemetry metrics migration, and the remaining OpenCensus references are historical comments. The original #1210 branch was therefore reduced to the one behavior on top of current master that is still missing.

ParsePrometheusMetrics (used by the e2e helper that scrapes NPD /metrics) currently returns an error for any family type it does not recognize. A Prometheus exposition may contain a sample without a # TYPE line; the text parser reports that family as UNTYPED. One such family therefore fails parsing of the whole scrape, even when all NPD counters/gauges parsed successfully.

This PR makes ParsePrometheusMetrics skip family types it does not support instead of aborting, while keeping the existing handling:

  • COUNTER and GAUGE values;
  • SUMMARY sample sums;
  • HISTOGRAM sample sums.

Malformed exposition (bad labels, duplicate TYPE lines, trailing garbage) still returns a parse error.

Which issue(s) this PR fixes:

Refs #1008. The migration itself landed in #1297; this PR remains as a parsing robustness fix discovered during that migration. Refs #1210 for history.

Special notes for your reviewer:

Changes

  • pkg/util/metrics/helpers.go: unsupported family types are skipped, and the function documentation states which family types are returned.
  • pkg/util/metrics/helpers_test.go: table tests cover explicit UNTYPED and implicit (no TYPE) families, and pin SUMMARY/HISTOGRAM sample sums.

Behavior

No change to the metrics NPD emits, its metric names, labels, or OpenTelemetry configuration. The change only affects parsing of Prometheus text by this helper.

Validation

  • Linux unit suite (all packages except the live GCP test/e2e suites): pass.
  • Focused Windows packages (pkg/util/metrics/..., pkg/exporters/..., pkg/problemmetrics/...): pass, and go vet passes.
  • go.mod, go.sum, vendor/: unchanged relative to upstream master.
  • Final whole-branch review: no blocking findings.

Does this PR introduce a user-facing change?

NONE

ParsePrometheusMetrics currently fails the whole parse when a scrape contains a metric family type it does not handle. A Prometheus exposition may contain a sample without a # TYPE line, which the text parser reports as UNTYPED, so one such family currently breaks parsing of every other metric in the scrape.

Return only the family types this helper supports. COUNTER, GAUGE, SUMMARY, and HISTOGRAM handling is unchanged, and malformed exposition still returns an error. Add regression tests for explicit and implicit UNTYPED families and for SUMMARY/HISTOGRAM sample sums.
@kubernetes-prow kubernetes-prow Bot added kind/bug Categorizes issue or PR as related to a bug. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Oct 26, 2026
@kubernetes-prow

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: MartinForReal
Once this PR has been reviewed and has the lgtm label, please assign klueska for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@MartinForReal

Copy link
Copy Markdown
Member Author

Closing as requested. The remaining parsing fix is not being pursued in this PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/bug Categorizes issue or PR as related to a bug. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant