Skip to content
This repository was archived by the owner on Apr 7, 2026. It is now read-only.

Commit 4cb1192

Browse files
authored
Merge branch 'main' into default-enable-grpc-gcp
2 parents 0380118 + f9505a9 commit 4cb1192

14 files changed

Lines changed: 212 additions & 200 deletions

.github/workflows/hermetic_library_generation.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ jobs:
3737
with:
3838
fetch-depth: 0
3939
token: ${{ secrets.CLOUD_JAVA_BOT_TOKEN }}
40-
- uses: googleapis/sdk-platform-java/.github/scripts@v2.64.1
40+
- uses: googleapis/sdk-platform-java/.github/scripts@v2.64.2
4141
if: env.SHOULD_RUN == 'true'
4242
with:
4343
base_ref: ${{ github.base_ref }}

.github/workflows/unmanaged_dependency_check.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,6 @@ jobs:
1717
# repository
1818
.kokoro/build.sh
1919
- name: Unmanaged dependency check
20-
uses: googleapis/sdk-platform-java/java-shared-dependencies/unmanaged-dependency-check@google-cloud-shared-dependencies/v3.54.1
20+
uses: googleapis/sdk-platform-java/java-shared-dependencies/unmanaged-dependency-check@google-cloud-shared-dependencies/v3.54.2
2121
with:
2222
bom-path: google-cloud-spanner-bom/pom.xml

google-cloud-spanner-bom/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
<parent>
99
<groupId>com.google.cloud</groupId>
1010
<artifactId>sdk-platform-java-config</artifactId>
11-
<version>3.54.1</version>
11+
<version>3.54.2</version>
1212
</parent>
1313

1414
<name>Google Cloud Spanner BOM</name>

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
}

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

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ public class TransactionMutationLimitExceededException extends SpannerException
2828

2929
private static final String ERROR_MESSAGE = "The transaction contains too many mutations.";
3030

31+
private static final String TRANSACTION_RESOURCE_LIMIT_EXCEEDED_MESSAGE =
32+
"Transaction resource limits exceeded";
33+
3134
/** Private constructor. Use {@link SpannerExceptionFactory} to create instances. */
3235
TransactionMutationLimitExceededException(
3336
DoNotConstructDirectly token,
@@ -40,13 +43,17 @@ public class TransactionMutationLimitExceededException extends SpannerException
4043
}
4144

4245
static boolean isTransactionMutationLimitException(ErrorCode code, String message) {
43-
return code == ErrorCode.INVALID_ARGUMENT && message != null && message.contains(ERROR_MESSAGE);
46+
return code == ErrorCode.INVALID_ARGUMENT
47+
&& message != null
48+
&& (message.contains(ERROR_MESSAGE)
49+
|| message.contains(TRANSACTION_RESOURCE_LIMIT_EXCEEDED_MESSAGE));
4450
}
4551

4652
static boolean isTransactionMutationLimitException(Throwable cause, ApiException apiException) {
4753
if (cause == null
4854
|| cause.getMessage() == null
49-
|| !cause.getMessage().contains(ERROR_MESSAGE)) {
55+
|| !(cause.getMessage().contains(ERROR_MESSAGE)
56+
|| cause.getMessage().contains(TRANSACTION_RESOURCE_LIMIT_EXCEEDED_MESSAGE))) {
5057
return false;
5158
}
5259
// Spanner includes a hint that points to the Spanner limits documentation page when the error
@@ -66,6 +73,9 @@ static boolean isTransactionMutationLimitException(Throwable cause, ApiException
6673
.getLinks(0)
6774
.getUrl()
6875
.equals("https://cloud.google.com/spanner/docs/limits");
76+
} else if (cause.getMessage().contains(TRANSACTION_RESOURCE_LIMIT_EXCEEDED_MESSAGE)) {
77+
// This more generic error does not contain any additional details.
78+
return true;
6979
}
7080
return false;
7181
}

0 commit comments

Comments
 (0)