Skip to content

Commit 6f34867

Browse files
authored
feat(bigtable): Create first response latencies instrument (#12706)
1 parent 710d269 commit 6f34867

2 files changed

Lines changed: 33 additions & 8 deletions

File tree

bigtable/bigtable.go

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,15 @@ import (
4949
"google.golang.org/protobuf/types/known/timestamppb"
5050
)
5151

52-
// UNIVERSE_DOMAIN placeholder is replaced by the UniverseDomain from DialSettings while creating GRPC connection/dial pool.
53-
const prodAddr = "bigtable.UNIVERSE_DOMAIN:443"
54-
const mtlsProdAddr = "bigtable.mtls.googleapis.com:443"
55-
const featureFlagsHeaderKey = "bigtable-features"
56-
const queryExpiredViolationType = "PREPARED_QUERY_EXPIRED"
57-
const preparedQueryExpireEarlyDuration = time.Second
52+
const (
53+
// UNIVERSE_DOMAIN placeholder is replaced by the UniverseDomain from DialSettings while creating GRPC connection/dial pool.
54+
prodAddr = "bigtable.UNIVERSE_DOMAIN:443"
55+
mtlsProdAddr = "bigtable.mtls.googleapis.com:443"
56+
featureFlagsHeaderKey = "bigtable-features"
57+
queryExpiredViolationType = "PREPARED_QUERY_EXPIRED"
58+
preparedQueryExpireEarlyDuration = time.Second
59+
methodNameReadRows = "ReadRows"
60+
)
5861

5962
var errNegativeRowLimit = errors.New("bigtable: row limit cannot be negative")
6063

@@ -987,7 +990,7 @@ func (t *Table) readRows(ctx context.Context, arg RowSet, f func(Row) bool, mt *
987990
return errNegativeRowLimit
988991
}
989992

990-
err = gaxInvokeWithRecorder(ctx, mt, "ReadRows", func(ctx context.Context, headerMD, trailerMD *metadata.MD, _ gax.CallSettings) error {
993+
err = gaxInvokeWithRecorder(ctx, mt, methodNameReadRows, func(ctx context.Context, headerMD, trailerMD *metadata.MD, _ gax.CallSettings) error {
991994
if rowLimitSet && numRowsRead >= intialRowLimit {
992995
return nil
993996
}

bigtable/metrics.go

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ const (
3939
locationMDKey = "x-goog-ext-425905942-bin"
4040
serverTimingMDKey = "server-timing"
4141
serverTimingValPrefix = "gfet4t7; dur="
42+
metricMethodPrefix = "Bigtable."
4243

4344
// Monitored resource labels
4445
monitoredResLabelKeyProject = "project_id"
@@ -61,6 +62,7 @@ const (
6162
metricNameAttemptLatencies = "attempt_latencies"
6263
metricNameServerLatencies = "server_latencies"
6364
metricNameAppBlockingLatencies = "application_latencies"
65+
metricNameFirstRespLatencies = "first_response_latencies"
6466
metricNameRetryCount = "retry_count"
6567
metricNameDebugTags = "debug_tags"
6668
metricNameConnErrCount = "connectivity_error_count"
@@ -109,6 +111,12 @@ var (
109111
},
110112
recordedPerAttempt: true,
111113
},
114+
metricNameFirstRespLatencies: {
115+
additionalAttrs: []string{
116+
metricLabelKeyStatus,
117+
},
118+
recordedPerAttempt: false,
119+
},
112120
metricNameAppBlockingLatencies: {},
113121
metricNameRetryCount: {
114122
additionalAttrs: []string{
@@ -169,6 +177,7 @@ type builtinMetricsTracerFactory struct {
169177
operationLatencies metric.Float64Histogram
170178
serverLatencies metric.Float64Histogram
171179
attemptLatencies metric.Float64Histogram
180+
firstRespLatencies metric.Float64Histogram
172181
appBlockingLatencies metric.Float64Histogram
173182
retryCount metric.Int64Counter
174183
connErrCount metric.Int64Counter
@@ -278,6 +287,17 @@ func (tf *builtinMetricsTracerFactory) createInstruments(meter metric.Meter) err
278287
return err
279288
}
280289

290+
// Create first_response_latencies
291+
tf.firstRespLatencies, err = meter.Float64Histogram(
292+
metricNameFirstRespLatencies,
293+
metric.WithDescription("Latency from operation start until the response headers were received. The publishing of the measurement will be delayed until the attempt response has been received."),
294+
metric.WithUnit(metricUnitMS),
295+
metric.WithExplicitBucketBoundaries(bucketBounds...),
296+
)
297+
if err != nil {
298+
return err
299+
}
300+
281301
// Create application_latencies
282302
tf.appBlockingLatencies, err = meter.Float64Histogram(
283303
metricNameAppBlockingLatencies,
@@ -329,6 +349,7 @@ type builtinMetricsTracer struct {
329349
instrumentOperationLatencies metric.Float64Histogram
330350
instrumentServerLatencies metric.Float64Histogram
331351
instrumentAttemptLatencies metric.Float64Histogram
352+
instrumentFirstRespLatencies metric.Float64Histogram
332353
instrumentAppBlockingLatencies metric.Float64Histogram
333354
instrumentRetryCount metric.Int64Counter
334355
instrumentConnErrCount metric.Int64Counter
@@ -342,7 +363,7 @@ type builtinMetricsTracer struct {
342363
}
343364

344365
func (b *builtinMetricsTracer) setMethod(m string) {
345-
b.method = "Bigtable." + m
366+
b.method = metricMethodPrefix + m
346367
}
347368

348369
// opTracer is used to record metrics for the entire operation, including retries.
@@ -437,6 +458,7 @@ func (tf *builtinMetricsTracerFactory) createBuiltinMetricsTracer(ctx context.Co
437458
instrumentOperationLatencies: tf.operationLatencies,
438459
instrumentServerLatencies: tf.serverLatencies,
439460
instrumentAttemptLatencies: tf.attemptLatencies,
461+
instrumentFirstRespLatencies: tf.firstRespLatencies,
440462
instrumentAppBlockingLatencies: tf.appBlockingLatencies,
441463
instrumentRetryCount: tf.retryCount,
442464
instrumentConnErrCount: tf.connErrCount,

0 commit comments

Comments
 (0)