fix(bigtable): Fix NoopMetricsProvider panic#12709
Merged
Merged
Conversation
bhshkh
commented
Aug 14, 2025
Comment on lines
-140
to
-155
| asyncRefreshMetricAttrs := metricsTracerFactory.clientAttributes | ||
| asyncRefreshMetricAttrs = append(asyncRefreshMetricAttrs, | ||
| attribute.String(metricLabelKeyTag, "async_refresh_dry_run"), | ||
| // Table, cluster and zone are unknown at this point | ||
| // Use default values | ||
| attribute.String(monitoredResLabelKeyTable, defaultTable), | ||
| attribute.String(monitoredResLabelKeyCluster, defaultCluster), | ||
| attribute.String(monitoredResLabelKeyZone, defaultZone), | ||
| ) | ||
| o = append(o, internaloption.EnableAsyncRefreshDryRun(func() { | ||
| metricsTracerFactory.debugTags.Add(context.Background(), 1, | ||
| metric.WithAttributes(asyncRefreshMetricAttrs...)) | ||
| })) |
Contributor
Author
There was a problem hiding this comment.
Moved to newAsyncRefreshErrHandler
bhshkh
commented
Aug 14, 2025
Comment on lines
-2227
to
-2257
| // recordOperationCompletion records as many operation specific metrics as it can | ||
| // Ignores error seen while creating metric attributes since metric can still | ||
| // be recorded with rest of the attributes | ||
| func recordOperationCompletion(mt *builtinMetricsTracer) { | ||
| if !mt.builtInEnabled { | ||
| return | ||
| } | ||
|
|
||
| // Calculate elapsed time | ||
| elapsedTimeMs := convertToMs(time.Since(mt.currOp.startTime)) | ||
|
|
||
| // Record operation_latencies | ||
| opLatAttrs, _ := mt.toOtelMetricAttrs(metricNameOperationLatencies) | ||
| mt.instrumentOperationLatencies.Record(mt.ctx, elapsedTimeMs, metric.WithAttributeSet(opLatAttrs)) | ||
|
|
||
| // Record retry_count | ||
| retryCntAttrs, _ := mt.toOtelMetricAttrs(metricNameRetryCount) | ||
| if mt.currOp.attemptCount > 1 { | ||
| // Only record when retry count is greater than 0 so the retry | ||
| // graph will be less confusing | ||
| mt.instrumentRetryCount.Add(mt.ctx, mt.currOp.attemptCount-1, metric.WithAttributeSet(retryCntAttrs)) | ||
| } | ||
|
|
||
| // Record application_latencies | ||
| appBlockingLatAttrs, _ := mt.toOtelMetricAttrs(metricNameAppBlockingLatencies) | ||
| mt.instrumentAppBlockingLatencies.Record(mt.ctx, mt.currOp.appBlockingLatency, metric.WithAttributeSet(appBlockingLatAttrs)) | ||
| } | ||
|
|
bhshkh
commented
Aug 14, 2025
Comment on lines
-2275
to
-2284
| // Increment number of attempts | ||
| mt.currOp.incrementAttemptCount() | ||
|
|
||
| mt.currOp.currAttempt = attemptTracer{} | ||
|
|
||
| // record start time | ||
| mt.currOp.currAttempt.setStartTime(time.Now()) |
Contributor
Author
There was a problem hiding this comment.
Moved to recordAttemptStart
bhshkh
commented
Aug 14, 2025
Comment on lines
-2286
to
-2302
| // Set attempt status | ||
| statusCode, _ := convertToGrpcStatusErr(err) | ||
| mt.currOp.currAttempt.setStatus(statusCode.String()) | ||
| callWrapper := func(ctx context.Context, callSettings gax.CallSettings) error { | ||
| mt.recordAttemptStart() | ||
|
|
||
| // Get location attributes from metadata and set it in tracer | ||
| // Ignore get location error since the metric can still be recorded with rest of the attributes | ||
| clusterID, zoneID, _ := extractLocation(attemptHeaderMD, attempTrailerMD) | ||
| mt.currOp.currAttempt.setClusterID(clusterID) | ||
| mt.currOp.currAttempt.setZoneID(zoneID) | ||
| // f makes calls to CBT service | ||
| err := f(ctx, &attemptHeaderMD, &attempTrailerMD, callSettings) | ||
|
|
||
| // Set server latency in tracer | ||
| serverLatency, serverLatencyErr := extractServerLatency(attemptHeaderMD, attempTrailerMD) | ||
| mt.currOp.currAttempt.setServerLatencyErr(serverLatencyErr) | ||
| mt.currOp.currAttempt.setServerLatency(serverLatency) |
Contributor
Author
There was a problem hiding this comment.
Moved to recordAttemptCompletion
bhshkh
commented
Aug 14, 2025
| // recordAttemptCompletion records as many attempt specific metrics as it can | ||
| // Ignore errors seen while creating metric attributes since metric can still | ||
| // be recorded with rest of the attributes | ||
| func recordAttemptCompletion(mt *builtinMetricsTracer) { |
hongalex
approved these changes
Aug 14, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes: #12687
Issue:
panic seen when using
NoopMetricsProviderduring bigtable client creationCause:
In
NewClientWithConfig, we callnewBuiltinMetricsTracerFactorygoogle-cloud-go/bigtable/bigtable.go
Line 116 in b3b8f70
newBuiltinMetricsTracerFactorydoes not setdebugTagsfield sinceNoopMetricsProvideris usedgoogle-cloud-go/bigtable/metrics.go
Lines 189 to 193 in 969cc74
In
NewClientWithConfig, after callingnewBuiltinMetricsTracerFactory, we try to callAddondebugTagsi.e. onnilresulting into panicgoogle-cloud-go/bigtable/bigtable.go
Line 150 in b3b8f70
Fix:
builtinMetricsTracerFactoryhas a fieldenabledwhich denotes where client side metrics areenabled.Everywhere in the library, we should be checking this field to be
truebefore recording any metrics.