Skip to content

Commit 3b83448

Browse files
committed
rebase fix
1 parent 7b9ad7d commit 3b83448

File tree

2 files changed

+14
-19
lines changed

2 files changed

+14
-19
lines changed

google-cloud-spanner/src/main/java/com/google/cloud/spanner/spi/v1/HeaderInterceptor.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -123,9 +123,9 @@ public void start(Listener<RespT> responseListener, Metadata headers) {
123123
Span span = Span.current();
124124
DatabaseName databaseName = extractDatabaseName(headers);
125125
String key = databaseName + method.getFullMethodName();
126-
TagContext tagContext = getTagContext(key, method.getFullMethodName(), databaseName);
127-
Attributes attributes =
128-
getMetricAttributes(key, method.getFullMethodName(), databaseName);
126+
TagContext openCensusTagContext = getOpenCensusTagContext(key, method.getFullMethodName(), databaseName);
127+
Attributes customMetricAttributes =
128+
getCustomMetricAttributes(key, method.getFullMethodName(), databaseName);
129129
Map<String, String> builtInMetricsAttributes =
130130
getBuiltInMetricAttributes(key, databaseName);
131131
addBuiltInMetricAttributes(compositeTracer, builtInMetricsAttributes);
@@ -154,12 +154,12 @@ public void onHeaders(Metadata metadata) {
154154
};
155155
}
156156

157-
private void processServerTimingHeader(
157+
private void processHeader(
158158
Metadata metadata,
159159
TagContext tagContext,
160160
Attributes attributes,
161161
Span span,
162-
Map<String, String> builtInMetricsAttributes,
162+
Map<String, String> builtInMetricsAttributes,
163163
Boolean isDirectPathUsed) {
164164
MeasureMap measureMap = STATS_RECORDER.newMeasureMap();
165165
String serverTiming = metadata.get(SERVER_TIMING_HEADER_KEY);
@@ -182,7 +182,7 @@ private void processServerTimingHeader(
182182
spannerRpcMetrics.recordGfeLatency(gfeLatency, attributes);
183183
spannerRpcMetrics.recordGfeHeaderMissingCount(0L, attributes);
184184
// TODO: Also pass directpath used
185-
builtInOpenTelemetryMetricsRecorder.recordGFELatency(latency, builtInMetricsAttributes);
185+
builtInOpenTelemetryMetricsRecorder.recordGFELatency(gfeLatency, builtInMetricsAttributes);
186186

187187
if (span != null) {
188188
span.setAttribute("gfe_latency", String.valueOf(gfeLatency));
@@ -254,7 +254,7 @@ private TagContext getOpenCensusTagContext(String key, String method, DatabaseNa
254254
.build());
255255
}
256256

257-
private Attributes buildCustomMetricAttributes(
257+
private Attributes getCustomMetricAttributes(
258258
String key, String method, DatabaseName databaseName) throws ExecutionException {
259259
return attributesCache.get(
260260
key,

google-cloud-spanner/src/test/java/com/google/cloud/spanner/OpenTelemetryBuiltInMetricsTracerTest.java

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -106,13 +106,13 @@ public static void setup() {
106106
.put(BuiltInMetricsConstant.CLIENT_NAME_KEY, client_name)
107107
.put(BuiltInMetricsConstant.CLIENT_UID_KEY, attributes.get("client_uid"))
108108
.put(BuiltInMetricsConstant.CLIENT_HASH_KEY, attributes.get("client_hash"))
109+
.put(BuiltInMetricsConstant.INSTANCE_ID_KEY, "i")
110+
.put(BuiltInMetricsConstant.DATABASE_KEY, "d")
111+
.put(BuiltInMetricsConstant.DIRECT_PATH_ENABLED_KEY, "false")
109112
.build();
110113

111114
expectedCommonRequestAttributes =
112115
Attributes.builder()
113-
.put(BuiltInMetricsConstant.INSTANCE_ID_KEY, "i")
114-
.put(BuiltInMetricsConstant.DATABASE_KEY, "d")
115-
.put(BuiltInMetricsConstant.DIRECT_PATH_ENABLED_KEY, "false")
116116
.put(BuiltInMetricsConstant.DIRECT_PATH_USED_KEY, "false")
117117
.build();
118118
}
@@ -308,7 +308,7 @@ public void testNoNetworkConnection() {
308308
.setApiTracerFactory(metricsTracerFactory)
309309
.build()
310310
.getService();
311-
String instance = "test-instance";
311+
String instance = "i";
312312
DatabaseClient client = spanner.getDatabaseClient(DatabaseId.of("test-project", instance, "d"));
313313

314314
// Using this client will return UNAVAILABLE, as the server is not reachable and we have
@@ -319,29 +319,24 @@ public void testNoNetworkConnection() {
319319
assertEquals(ErrorCode.UNAVAILABLE, exception.getErrorCode());
320320

321321
Attributes expectedAttributesCreateSessionOK =
322-
expectedBaseAttributes
322+
expectedCommonBaseAttributes
323323
.toBuilder()
324+
.putAll(expectedCommonRequestAttributes)
324325
.put(BuiltInMetricsConstant.STATUS_KEY, "OK")
325326
.put(BuiltInMetricsConstant.METHOD_KEY, "Spanner.CreateSession")
326327
// Include the additional attributes that are added by the HeaderInterceptor in the
327328
// filter. Note that the DIRECT_PATH_USED attribute is not added, as the request never
328329
// leaves the client.
329-
.put(BuiltInMetricsConstant.INSTANCE_ID_KEY, instance)
330-
.put(BuiltInMetricsConstant.DATABASE_KEY, "d")
331-
.put(BuiltInMetricsConstant.DIRECT_PATH_ENABLED_KEY, "false")
332330
.build();
333331

334332
Attributes expectedAttributesCreateSessionFailed =
335-
expectedBaseAttributes
333+
expectedCommonBaseAttributes
336334
.toBuilder()
337335
.put(BuiltInMetricsConstant.STATUS_KEY, "UNAVAILABLE")
338336
.put(BuiltInMetricsConstant.METHOD_KEY, "Spanner.CreateSession")
339337
// Include the additional attributes that are added by the HeaderInterceptor in the
340338
// filter. Note that the DIRECT_PATH_USED attribute is not added, as the request never
341339
// leaves the client.
342-
.put(BuiltInMetricsConstant.INSTANCE_ID_KEY, instance)
343-
.put(BuiltInMetricsConstant.DATABASE_KEY, "d")
344-
.put(BuiltInMetricsConstant.DIRECT_PATH_ENABLED_KEY, "false")
345340
.build();
346341

347342
MetricData attemptCountMetricData =

0 commit comments

Comments
 (0)