Skip to content

feat(exporters): replace opencensus with opentelemetry#1297

Open
hakman wants to merge 20 commits into
kubernetes:masterfrom
hakman:pr-1141-fixes
Open

feat(exporters): replace opencensus with opentelemetry#1297
hakman wants to merge 20 commits into
kubernetes:masterfrom
hakman:pr-1141-fixes

Conversation

@hakman

@hakman hakman commented Jul 5, 2026

Copy link
Copy Markdown
Member

Based on @daveoy's #1141, adding remaining fixes.
Closes #1008
/cc @SergeyKanzhelev @wangzhen127

@kubernetes-prow

Copy link
Copy Markdown
Contributor

@hakman: GitHub didn't allow me to request PR reviews from the following users: daveoy.

Note that only kubernetes members and repo collaborators can review this PR, and authors cannot review their own PRs.

Details

In response to this:

Based on #1141, adding remaining fixes.
Closes #1008
/cc @SergeyKanzhelev @wangzhen127 @daveoy

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-sigs/prow repository.

@kubernetes-prow kubernetes-prow Bot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Jul 5, 2026
@kubernetes-prow

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: hakman

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

The pull request process is described 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

@kubernetes-prow kubernetes-prow Bot added approved Indicates a PR has been approved by an approver from all required OWNERS files. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. labels Jul 5, 2026
@hakman
hakman force-pushed the pr-1141-fixes branch 5 times, most recently from a537ec6 to ee90453 Compare July 5, 2026 16:52
@hakman

hakman commented Jul 5, 2026

Copy link
Copy Markdown
Member Author

/test pull-npd-e2e-test

@kubernetes-prow kubernetes-prow Bot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jul 9, 2026
@kubernetes-prow kubernetes-prow Bot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jul 11, 2026
@hakman
hakman force-pushed the pr-1141-fixes branch 3 times, most recently from 8284a46 to a12139a Compare July 11, 2026 21:34
daveoy and others added 10 commits July 12, 2026 00:43
* feat(exporters): replace opencensus with opentelemetry

* fix(stackdriver_exporter): use metrics util constants

* chore:  use global meter and init

* feat(exporters): add resource info, use global meter

* chore: update deps

* fix: use a gauge directly, narrow scope info

* cleanup: deps

* fix: try initOnce pattern for global problem metrics

* fix(problemmetrics): init is being called too late

* fix(gauge): remove _ratio suffix

* fix: clean up after rebase

* fix: cleanup after rebase

* fix: cleanup after rebase

* fix: cleanup after rebase

* fix: remove nodename

* fix(test): remove instance id check

* fix(test): add attr values

* fix(test): unexported resources

* fix(test): initialize global problem metrics manager

* fix(lint): make the linter happy
hakman added 8 commits July 12, 2026 00:43
disk_percent_used declared only device_name but recorded four labels
(device_name, fs_type, mount_option, state). With per-metric label
validation, Record now rejects the undeclared labels and the metric is
dropped from the export (caught by the metriconly e2e).

Record only device_name, preserving the schema NPD has exported since the
metric was introduced: the OpenCensus view aggregated by device_name and
dropped the other tags, so on the wire this metric has always had a single
label. It also maps to the Google-owned
compute.googleapis.com/guest/disk/percent_used descriptor, which can reject
writes carrying undeclared label keys. Add a regression test pinning the
schema.
@hakman hakman added the tide/merge-method-squash Denotes a PR that should be squashed by tide when it merges. label Jul 11, 2026

@DigitalVeer DigitalVeer left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for this! I work with NPD at GKE and I hope I can add my two cents here.

// Create Prometheus exporter with options to prevent automatic suffixing
promExporter, err := otelprometheus.New(
otelprometheus.WithRegisterer(reg), // Use a dedicated registry
otelprometheus.WithTranslationStrategy(otlptranslator.NoTranslation), // Don't add suffixes or escape

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I recorded the same metric and took a diff on the output between this PR & master.

# any plain scraper w/o escaping
curl -s localhost:20257/metrics | grep uptime
#   host_uptime 12345.6            (same on both branches)

# when using Prometheus 3.x 
curl -s -H 'Accept: text/plain; version=1.0.0; escaping=allow-utf-8' \
     localhost:20257/metrics | grep uptime
#   PR head:  {"host/uptime"} 12345.6     <- renamed
#   master:   host_uptime 12345.6          <- unchanged

We should account for users scraping with Prometheus 3.x.

Given that Prometheus 3.x supports utf-8 and has escaping=allow-utf-8 by default, we should make sure the metric sent out is the same before and after this change.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Good catch. Fixed.

Comment thread pkg/util/otel/common.go
globalMeterProvider = sdkmetric.NewMeterProvider(opts...)

// Set as global meter provider
otel.SetMeterProvider(globalMeterProvider)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

We should pass option.WithTelemetryDisabled() in monitoringClientOptions.

By default, google.golang.org/api adds an otelgrpc handler to each gRPC client. Thus the exporter makes rpc.client.* metrics for its own calls. These metric names are not in NPDMetricToSDMetric.

Cloud Monitoring rejects unknown metrics on export cycles and each failed export makes more rpc.client.* metrics so this can cause a failure loop.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Sounds good, done.

@linux-foundation-easycla

linux-foundation-easycla Bot commented Jul 22, 2026

Copy link
Copy Markdown

CLA Signed
The committers listed above are authorized under a signed CLA.

@kubernetes-prow kubernetes-prow Bot added cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. and removed cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Jul 22, 2026
@kubernetes-prow kubernetes-prow Bot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. and removed cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. labels Jul 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. tide/merge-method-squash Denotes a PR that should be squashed by tide when it merges.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Migrate OpenCensus to OpenTelemetry

3 participants