Skip to content

Commit 8f145ed

Browse files
authored
feat(bigtable): Add application blocking latencies (#11349)
1 parent dd45fd7 commit 8f145ed

3 files changed

Lines changed: 298 additions & 25 deletions

File tree

bigtable/bigtable.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1079,8 +1079,12 @@ func (t *Table) readRows(ctx context.Context, arg RowSet, f func(Row) bool, mt *
10791079
continue
10801080
}
10811081
prevRowKey = row.Key()
1082+
1083+
appBlockingLatencyStart := time.Now()
10821084
continueReading := f(row)
10831085
numRowsRead++
1086+
mt.currOp.incrementAppBlockingLatency(convertToMs(time.Since(appBlockingLatencyStart)))
1087+
10841088
if !continueReading {
10851089
// Cancel and drain stream.
10861090
cancel()
@@ -2246,6 +2250,10 @@ func recordOperationCompletion(mt *builtinMetricsTracer) {
22462250
// graph will be less confusing
22472251
mt.instrumentRetryCount.Add(mt.ctx, mt.currOp.attemptCount-1, metric.WithAttributeSet(retryCntAttrs))
22482252
}
2253+
2254+
// Record application_latencies
2255+
appBlockingLatAttrs, _ := mt.toOtelMetricAttrs(metricNameAppBlockingLatencies)
2256+
mt.instrumentAppBlockingLatencies.Record(mt.ctx, mt.currOp.appBlockingLatency, metric.WithAttributeSet(appBlockingLatAttrs))
22492257
}
22502258

22512259
// gaxInvokeWithRecorder:

bigtable/metrics.go

Lines changed: 46 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,13 @@ const (
5757
metricLabelKeyClientUID = "client_uid"
5858

5959
// Metric names
60-
metricNameOperationLatencies = "operation_latencies"
61-
metricNameAttemptLatencies = "attempt_latencies"
62-
metricNameServerLatencies = "server_latencies"
63-
metricNameRetryCount = "retry_count"
64-
metricNameDebugTags = "debug_tags"
65-
metricNameConnErrCount = "connectivity_error_count"
60+
metricNameOperationLatencies = "operation_latencies"
61+
metricNameAttemptLatencies = "attempt_latencies"
62+
metricNameServerLatencies = "server_latencies"
63+
metricNameAppBlockingLatencies = "application_latencies"
64+
metricNameRetryCount = "retry_count"
65+
metricNameDebugTags = "debug_tags"
66+
metricNameConnErrCount = "connectivity_error_count"
6667

6768
// Metric units
6869
metricUnitMS = "ms"
@@ -108,6 +109,7 @@ var (
108109
},
109110
recordedPerAttempt: true,
110111
},
112+
metricNameAppBlockingLatencies: {},
111113
metricNameRetryCount: {
112114
additionalAttrs: []string{
113115
metricLabelKeyStatus,
@@ -164,12 +166,13 @@ type builtinMetricsTracerFactory struct {
164166
// do not change across different function calls on client
165167
clientAttributes []attribute.KeyValue
166168

167-
operationLatencies metric.Float64Histogram
168-
serverLatencies metric.Float64Histogram
169-
attemptLatencies metric.Float64Histogram
170-
retryCount metric.Int64Counter
171-
connErrCount metric.Int64Counter
172-
debugTags metric.Int64Counter
169+
operationLatencies metric.Float64Histogram
170+
serverLatencies metric.Float64Histogram
171+
attemptLatencies metric.Float64Histogram
172+
appBlockingLatencies metric.Float64Histogram
173+
retryCount metric.Int64Counter
174+
connErrCount metric.Int64Counter
175+
debugTags metric.Int64Counter
173176
}
174177

175178
func newBuiltinMetricsTracerFactory(ctx context.Context, project, instance, appProfile string, metricsProvider MetricsProvider, opts ...option.ClientOption) (*builtinMetricsTracerFactory, error) {
@@ -269,6 +272,17 @@ func (tf *builtinMetricsTracerFactory) createInstruments(meter metric.Meter) err
269272
return err
270273
}
271274

275+
// Create application_latencies
276+
tf.appBlockingLatencies, err = meter.Float64Histogram(
277+
metricNameAppBlockingLatencies,
278+
metric.WithDescription("The latency of the client application consuming available response data."),
279+
metric.WithUnit(metricUnitMS),
280+
metric.WithExplicitBucketBoundaries(bucketBounds...),
281+
)
282+
if err != nil {
283+
return err
284+
}
285+
272286
// Create retry_count
273287
tf.retryCount, err = meter.Int64Counter(
274288
metricNameRetryCount,
@@ -306,12 +320,13 @@ type builtinMetricsTracer struct {
306320
// do not change across different operations on client
307321
clientAttributes []attribute.KeyValue
308322

309-
instrumentOperationLatencies metric.Float64Histogram
310-
instrumentServerLatencies metric.Float64Histogram
311-
instrumentAttemptLatencies metric.Float64Histogram
312-
instrumentRetryCount metric.Int64Counter
313-
instrumentConnErrCount metric.Int64Counter
314-
instrumentDebugTags metric.Int64Counter
323+
instrumentOperationLatencies metric.Float64Histogram
324+
instrumentServerLatencies metric.Float64Histogram
325+
instrumentAttemptLatencies metric.Float64Histogram
326+
instrumentAppBlockingLatencies metric.Float64Histogram
327+
instrumentRetryCount metric.Int64Counter
328+
instrumentConnErrCount metric.Int64Counter
329+
instrumentDebugTags metric.Int64Counter
315330

316331
tableName string
317332
method string
@@ -336,6 +351,8 @@ type opTracer struct {
336351
status string
337352

338353
currAttempt attemptTracer
354+
355+
appBlockingLatency float64
339356
}
340357

341358
func (o *opTracer) setStartTime(t time.Time) {
@@ -350,6 +367,10 @@ func (o *opTracer) incrementAttemptCount() {
350367
o.attemptCount++
351368
}
352369

370+
func (o *opTracer) incrementAppBlockingLatency(latency float64) {
371+
o.appBlockingLatency += latency
372+
}
373+
353374
// attemptTracer is used to record metrics for each individual attempt of the operation.
354375
// Attempt corresponds to an attempt of an RPC.
355376
type attemptTracer struct {
@@ -404,12 +425,13 @@ func (tf *builtinMetricsTracerFactory) createBuiltinMetricsTracer(ctx context.Co
404425
currOp: currOpTracer,
405426
clientAttributes: tf.clientAttributes,
406427

407-
instrumentOperationLatencies: tf.operationLatencies,
408-
instrumentServerLatencies: tf.serverLatencies,
409-
instrumentAttemptLatencies: tf.attemptLatencies,
410-
instrumentRetryCount: tf.retryCount,
411-
instrumentConnErrCount: tf.connErrCount,
412-
instrumentDebugTags: tf.debugTags,
428+
instrumentOperationLatencies: tf.operationLatencies,
429+
instrumentServerLatencies: tf.serverLatencies,
430+
instrumentAttemptLatencies: tf.attemptLatencies,
431+
instrumentAppBlockingLatencies: tf.appBlockingLatencies,
432+
instrumentRetryCount: tf.retryCount,
433+
instrumentConnErrCount: tf.connErrCount,
434+
instrumentDebugTags: tf.debugTags,
413435

414436
tableName: tableName,
415437
isStreaming: isStreaming,

0 commit comments

Comments
 (0)