Skip to content

Commit 7b49412

Browse files
authored
fix: Refine connecitivity metrics to capture RPCs with no response he… (googleapis#4252)
* fix: Refine connecitivity metrics to capture RPCs with no response headers * test fix
1 parent 102cb4c commit 7b49412

File tree

8 files changed

+157
-188
lines changed

8 files changed

+157
-188
lines changed

google-cloud-spanner/clirr-ignored-differences.xml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1062,4 +1062,34 @@
10621062
<className>com/google/cloud/spanner/connection/Connection</className>
10631063
<method>java.lang.Object getConnectionPropertyValue(com.google.cloud.spanner.connection.ConnectionProperty)</method>
10641064
</difference>
1065+
<!-- (Remove since these methods has no usage. CompositeTracer interface is annotated as internal API) -->
1066+
<difference>
1067+
<differenceType>7002</differenceType>
1068+
<className>com/google/cloud/spanner/CompositeTracer</className>
1069+
<method>void recordAFELatency(java.lang.Long)</method>
1070+
</difference>
1071+
<difference>
1072+
<differenceType>7002</differenceType>
1073+
<className>com/google/cloud/spanner/CompositeTracer</className>
1074+
<method>void recordAFELatency(java.lang.Float)</method>
1075+
</difference>
1076+
<difference>
1077+
<differenceType>7002</differenceType>
1078+
<className>com/google/cloud/spanner/CompositeTracer</className>
1079+
<method>void recordAfeHeaderMissingCount(java.lang.Long)</method>
1080+
</difference>
1081+
<difference>
1082+
<differenceType>7002</differenceType>
1083+
<className>com/google/cloud/spanner/CompositeTracer</className>
1084+
<method>void recordGFELatency(java.lang.Long)</method>
1085+
</difference>
1086+
<difference>
1087+
<differenceType>7002</differenceType>
1088+
<className>com/google/cloud/spanner/CompositeTracer</className>
1089+
<method>void recordGFELatency(java.lang.Float)</method>
1090+
</difference><difference>
1091+
<differenceType>7002</differenceType>
1092+
<className>com/google/cloud/spanner/CompositeTracer</className>
1093+
<method>void recordGfeHeaderMissingCount(java.lang.Long)</method>
1094+
</difference>
10651095
</differences>

google-cloud-spanner/src/main/java/com/google/cloud/spanner/BuiltInMetricsRecorder.java

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -99,21 +99,23 @@ class BuiltInMetricsRecorder extends OpenTelemetryMetricsRecorder {
9999
void recordServerTimingHeaderMetrics(
100100
Float gfeLatency,
101101
Float afeLatency,
102-
Long gfeHeaderMissingCount,
103-
Long afeHeaderMissingCount,
104-
Map<String, String> attributes) {
102+
Map<String, String> attributes,
103+
boolean isDirectPathUsed,
104+
boolean isAfeEnabled) {
105105
io.opentelemetry.api.common.Attributes otelAttributes = toOtelAttributes(attributes);
106-
if (gfeLatency != null) {
107-
gfeLatencyRecorder.record(gfeLatency, otelAttributes);
106+
if (!isDirectPathUsed) {
107+
if (gfeLatency != null) {
108+
gfeLatencyRecorder.record(gfeLatency, otelAttributes);
109+
} else {
110+
gfeHeaderMissingCountRecorder.add(1, otelAttributes);
111+
}
108112
}
109-
if (gfeHeaderMissingCount > 0) {
110-
gfeHeaderMissingCountRecorder.add(gfeHeaderMissingCount, otelAttributes);
111-
}
112-
if (afeLatency != null) {
113-
afeLatencyRecorder.record(afeLatency, otelAttributes);
114-
}
115-
if (afeHeaderMissingCount > 0) {
116-
afeHeaderMissingCountRecorder.add(afeHeaderMissingCount, otelAttributes);
113+
if (isAfeEnabled) {
114+
if (afeLatency != null) {
115+
afeLatencyRecorder.record(afeLatency, otelAttributes);
116+
} else {
117+
afeHeaderMissingCountRecorder.add(1, otelAttributes);
118+
}
117119
}
118120
}
119121

google-cloud-spanner/src/main/java/com/google/cloud/spanner/BuiltInMetricsTracer.java

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,10 @@ class BuiltInMetricsTracer extends MetricsTracer implements ApiTracer {
3939
private final Map<String, String> attributes = new HashMap<>();
4040
private Float gfeLatency = null;
4141
private Float afeLatency = null;
42-
private TraceWrapper traceWrapper;
43-
private long gfeHeaderMissingCount = 0;
44-
private long afeHeaderMissingCount = 0;
42+
private final TraceWrapper traceWrapper;
4543
private final ISpan currentSpan;
44+
private boolean isDirectPathUsed;
45+
private boolean isAfeEnabled;
4646

4747
BuiltInMetricsTracer(
4848
MethodName methodName,
@@ -66,7 +66,7 @@ public void attemptSucceeded() {
6666
super.attemptSucceeded();
6767
attributes.put(STATUS_ATTRIBUTE, StatusCode.Code.OK.toString());
6868
builtInOpenTelemetryMetricsRecorder.recordServerTimingHeaderMetrics(
69-
gfeLatency, afeLatency, gfeHeaderMissingCount, afeHeaderMissingCount, attributes);
69+
gfeLatency, afeLatency, attributes, isDirectPathUsed, isAfeEnabled);
7070
}
7171
}
7272

@@ -80,7 +80,7 @@ public void attemptCancelled() {
8080
super.attemptCancelled();
8181
attributes.put(STATUS_ATTRIBUTE, StatusCode.Code.CANCELLED.toString());
8282
builtInOpenTelemetryMetricsRecorder.recordServerTimingHeaderMetrics(
83-
gfeLatency, afeLatency, gfeHeaderMissingCount, afeHeaderMissingCount, attributes);
83+
gfeLatency, afeLatency, attributes, isDirectPathUsed, isAfeEnabled);
8484
}
8585
}
8686

@@ -98,7 +98,7 @@ public void attemptFailedDuration(Throwable error, java.time.Duration delay) {
9898
super.attemptFailedDuration(error, delay);
9999
attributes.put(STATUS_ATTRIBUTE, extractStatus(error));
100100
builtInOpenTelemetryMetricsRecorder.recordServerTimingHeaderMetrics(
101-
gfeLatency, afeLatency, gfeHeaderMissingCount, afeHeaderMissingCount, attributes);
101+
gfeLatency, afeLatency, attributes, isDirectPathUsed, isAfeEnabled);
102102
}
103103
}
104104

@@ -115,7 +115,7 @@ public void attemptFailedRetriesExhausted(Throwable error) {
115115
super.attemptFailedRetriesExhausted(error);
116116
attributes.put(STATUS_ATTRIBUTE, extractStatus(error));
117117
builtInOpenTelemetryMetricsRecorder.recordServerTimingHeaderMetrics(
118-
gfeLatency, afeLatency, gfeHeaderMissingCount, afeHeaderMissingCount, attributes);
118+
gfeLatency, afeLatency, attributes, isDirectPathUsed, isAfeEnabled);
119119
}
120120
}
121121

@@ -132,24 +132,16 @@ public void attemptPermanentFailure(Throwable error) {
132132
super.attemptPermanentFailure(error);
133133
attributes.put(STATUS_ATTRIBUTE, extractStatus(error));
134134
builtInOpenTelemetryMetricsRecorder.recordServerTimingHeaderMetrics(
135-
gfeLatency, afeLatency, gfeHeaderMissingCount, afeHeaderMissingCount, attributes);
135+
gfeLatency, afeLatency, attributes, isDirectPathUsed, isAfeEnabled);
136136
}
137137
}
138138

139-
void recordGFELatency(Float gfeLatency) {
139+
public void recordServerTimingHeaderMetrics(
140+
Float gfeLatency, Float afeLatency, boolean isDirectPathUsed, boolean isAfeEnabled) {
140141
this.gfeLatency = gfeLatency;
141-
}
142-
143-
void recordAFELatency(Float afeLatency) {
142+
this.isDirectPathUsed = isDirectPathUsed;
144143
this.afeLatency = afeLatency;
145-
}
146-
147-
void recordGfeHeaderMissingCount(Long value) {
148-
this.gfeHeaderMissingCount = value;
149-
}
150-
151-
void recordAfeHeaderMissingCount(Long value) {
152-
this.afeHeaderMissingCount = value;
144+
this.isAfeEnabled = isAfeEnabled;
153145
}
154146

155147
@Override

google-cloud-spanner/src/main/java/com/google/cloud/spanner/CompositeTracer.java

Lines changed: 5 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -191,50 +191,13 @@ public void addAttributes(Map<String, String> attributes) {
191191
}
192192
}
193193

194-
public void recordGFELatency(Long gfeLatency) {
194+
public void recordServerTimingHeaderMetrics(
195+
Float gfeLatency, Float afeLatency, boolean isDirectPathUsed, boolean isAfeEnabled) {
195196
for (ApiTracer child : children) {
196197
if (child instanceof BuiltInMetricsTracer) {
197-
((BuiltInMetricsTracer) child).recordGFELatency(Float.valueOf(gfeLatency));
198-
}
199-
}
200-
}
201-
202-
public void recordGfeHeaderMissingCount(Long value) {
203-
for (ApiTracer child : children) {
204-
if (child instanceof BuiltInMetricsTracer) {
205-
((BuiltInMetricsTracer) child).recordGfeHeaderMissingCount(value);
206-
}
207-
}
208-
}
209-
210-
public void recordAFELatency(Long afeLatency) {
211-
for (ApiTracer child : children) {
212-
if (child instanceof BuiltInMetricsTracer) {
213-
((BuiltInMetricsTracer) child).recordAFELatency(Float.valueOf(afeLatency));
214-
}
215-
}
216-
}
217-
218-
public void recordAfeHeaderMissingCount(Long value) {
219-
for (ApiTracer child : children) {
220-
if (child instanceof BuiltInMetricsTracer) {
221-
((BuiltInMetricsTracer) child).recordAfeHeaderMissingCount(value);
222-
}
223-
}
224-
}
225-
226-
public void recordGFELatency(Float gfeLatency) {
227-
for (ApiTracer child : children) {
228-
if (child instanceof BuiltInMetricsTracer) {
229-
((BuiltInMetricsTracer) child).recordGFELatency(gfeLatency);
230-
}
231-
}
232-
}
233-
234-
public void recordAFELatency(Float afeLatency) {
235-
for (ApiTracer child : children) {
236-
if (child instanceof BuiltInMetricsTracer) {
237-
((BuiltInMetricsTracer) child).recordAFELatency(afeLatency);
198+
((BuiltInMetricsTracer) child)
199+
.recordServerTimingHeaderMetrics(
200+
gfeLatency, afeLatency, isDirectPathUsed, isAfeEnabled);
238201
}
239202
}
240203
}

0 commit comments

Comments
 (0)