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

stats/opentelemetry: enable otel dial option to pass empty MetricOptions{} #7952

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

aranjans
Copy link
Contributor

@aranjans aranjans commented Dec 19, 2024

This PR addresses the issue where users cannot pass empty MetricOptions in the gRPC-Go OpenTelemetry implementation, leading to runtime errors. This allows user to pass empty MetricOptions which enhances flexibility for users who want to disable metrics collection without a full configuration.

Changes Made

  • No-Op Metric Recorder: Introduced a NoOpMetricsRecorder to handle cases where metrics are not enabled.
  • Test Coverage: Added tests to verify correct behavior with empty MetricOptions.

RELEASE NOTES:

  • stats/opentelemetry: enable otel dial option to pass empty MetricOptions{}.

@aranjans aranjans added Type: Bug Area: Observability Includes Stats, Tracing, Channelz, Healthz, Binlog, Reflection, Admin, GCP Observability labels Dec 19, 2024
@aranjans aranjans added this to the 1.70 Release milestone Dec 19, 2024
@aranjans aranjans requested review from arjan-bal and removed request for arjan-bal December 19, 2024 07:23
Copy link

codecov bot commented Dec 19, 2024

Codecov Report

Attention: Patch coverage is 79.41176% with 7 lines in your changes missing coverage. Please review.

Project coverage is 82.17%. Comparing base (56a14ba) to head (f5af085).
Report is 10 commits behind head on master.

Files with missing lines Patch % Lines
stats/opentelemetry/opentelemetry.go 0.00% 5 Missing ⚠️
stats/opentelemetry/client_metrics.go 93.75% 1 Missing ⚠️
stats/opentelemetry/server_metrics.go 92.30% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #7952      +/-   ##
==========================================
+ Coverage   82.09%   82.17%   +0.08%     
==========================================
  Files         379      381       +2     
  Lines       38261    38558     +297     
==========================================
+ Hits        31409    31686     +277     
- Misses       5549     5570      +21     
+ Partials     1303     1302       -1     
Files with missing lines Coverage Δ
stats/opentelemetry/client_metrics.go 88.46% <93.75%> (+0.53%) ⬆️
stats/opentelemetry/server_metrics.go 91.56% <92.30%> (+2.19%) ⬆️
stats/opentelemetry/opentelemetry.go 73.33% <0.00%> (-2.53%) ⬇️

... and 32 files with indirect coverage changes

Comment on lines -44 to -46
if h.options.MetricsOptions.MeterProvider == nil {
return
}
Copy link
Contributor

@arjan-bal arjan-bal Dec 19, 2024

Choose a reason for hiding this comment

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

I think the only changes needed may be to set the metrics and the MetricsProvider to no-op versions, rest of the changes can be reverted.

Suggested change
if h.options.MetricsOptions.MeterProvider == nil {
return
}
if h.options.MetricsOptions.MeterProvider == nil {
h.clientMetrics.attemptStarted = noop.Int64Counter{}
h.clientMetrics.attemptDuration = noop.Float64Histogram{}
h.clientMetrics.attemptSentTotalCompressedMessageSize = noop.Int64Histogram{}
h.clientMetrics.attemptRcvdTotalCompressedMessageSize = noop.Int64Histogram{}
h.clientMetrics.callDuration = noop.Float64Histogram{}
h.MetricsRecorder = &registryMetrics{}
return
}

Copy link
Contributor

Choose a reason for hiding this comment

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

If we set the metrics in setClientMetrics to an empty set using stats.NewMetricSet(), we end up getting no-op implementations for the clientMetrics and registryMetrics. We can use this fact to unify the code paths for MeterProvider == nil and MeterProvider != nil.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@arjan-bal I have updated the PR with suggested change above. Could you clarify this comment?

Copy link
Contributor

Choose a reason for hiding this comment

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

With the current approach, the list of metrics (attemptStarted, attemptDuration, attemptSentTotalCompressedMessageSize etc.) is duplicated. If we set metrics to an empty set using stats.NewMetricSet(), the existing code will set every metric to the corresponding noop histogram, avoiding duplication.

@arjan-bal arjan-bal assigned aranjans and unassigned arjan-bal Dec 19, 2024
@aranjans aranjans assigned arjan-bal and unassigned aranjans Jan 3, 2025
@arjan-bal arjan-bal assigned aranjans and unassigned arjan-bal Jan 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: Observability Includes Stats, Tracing, Channelz, Healthz, Binlog, Reflection, Admin, GCP Observability Type: Bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants