Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions google-cloud-spanner/clirr-ignored-differences.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1062,4 +1062,34 @@
<className>com/google/cloud/spanner/connection/Connection</className>
<method>java.lang.Object getConnectionPropertyValue(com.google.cloud.spanner.connection.ConnectionProperty)</method>
</difference>
<!-- (Remove since these methods has no usage. CompositeTracer interface is annotated as internal API) -->
<difference>
<differenceType>7002</differenceType>
<className>com/google/cloud/spanner/CompositeTracer</className>
<method>void recordAFELatency(java.lang.Long)</method>
</difference>
<difference>
<differenceType>7002</differenceType>
<className>com/google/cloud/spanner/CompositeTracer</className>
<method>void recordAFELatency(java.lang.Float)</method>
</difference>
<difference>
<differenceType>7002</differenceType>
<className>com/google/cloud/spanner/CompositeTracer</className>
<method>void recordAfeHeaderMissingCount(java.lang.Long)</method>
</difference>
<difference>
<differenceType>7002</differenceType>
<className>com/google/cloud/spanner/CompositeTracer</className>
<method>void recordGFELatency(java.lang.Long)</method>
</difference>
<difference>
<differenceType>7002</differenceType>
<className>com/google/cloud/spanner/CompositeTracer</className>
<method>void recordGFELatency(java.lang.Float)</method>
</difference><difference>

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

For better readability and to maintain consistent XML formatting, it's recommended to place each <difference> tag on a new line.

Suggested change
</difference><difference>
</difference>
<difference>

<differenceType>7002</differenceType>
<className>com/google/cloud/spanner/CompositeTracer</className>
<method>void recordGfeHeaderMissingCount(java.lang.Long)</method>
</difference>
</differences>
Original file line number Diff line number Diff line change
Expand Up @@ -99,21 +99,23 @@ class BuiltInMetricsRecorder extends OpenTelemetryMetricsRecorder {
void recordServerTimingHeaderMetrics(
Float gfeLatency,
Float afeLatency,
Long gfeHeaderMissingCount,
Long afeHeaderMissingCount,
Map<String, String> attributes) {
Map<String, String> attributes,
boolean isDirectPathUsed,
boolean isAfeEnabled) {
io.opentelemetry.api.common.Attributes otelAttributes = toOtelAttributes(attributes);
if (gfeLatency != null) {
gfeLatencyRecorder.record(gfeLatency, otelAttributes);
if (!isDirectPathUsed) {
if (gfeLatency != null) {
gfeLatencyRecorder.record(gfeLatency, otelAttributes);
} else {
gfeHeaderMissingCountRecorder.add(1, otelAttributes);
}
}
if (gfeHeaderMissingCount > 0) {
gfeHeaderMissingCountRecorder.add(gfeHeaderMissingCount, otelAttributes);
}
if (afeLatency != null) {
afeLatencyRecorder.record(afeLatency, otelAttributes);
}
if (afeHeaderMissingCount > 0) {
afeHeaderMissingCountRecorder.add(afeHeaderMissingCount, otelAttributes);
if (isAfeEnabled) {
if (afeLatency != null) {
afeLatencyRecorder.record(afeLatency, otelAttributes);
} else {
afeHeaderMissingCountRecorder.add(1, otelAttributes);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ class BuiltInMetricsTracer extends MetricsTracer implements ApiTracer {
private final Map<String, String> attributes = new HashMap<>();
private Float gfeLatency = null;
private Float afeLatency = null;
private TraceWrapper traceWrapper;
private long gfeHeaderMissingCount = 0;
private long afeHeaderMissingCount = 0;
private final TraceWrapper traceWrapper;
private final ISpan currentSpan;
private boolean isDirectPathUsed;
private boolean isAfeEnabled;

BuiltInMetricsTracer(
MethodName methodName,
Expand All @@ -66,7 +66,7 @@ public void attemptSucceeded() {
super.attemptSucceeded();
attributes.put(STATUS_ATTRIBUTE, StatusCode.Code.OK.toString());
builtInOpenTelemetryMetricsRecorder.recordServerTimingHeaderMetrics(
gfeLatency, afeLatency, gfeHeaderMissingCount, afeHeaderMissingCount, attributes);
gfeLatency, afeLatency, attributes, isDirectPathUsed, isAfeEnabled);
}
}

Expand All @@ -80,7 +80,7 @@ public void attemptCancelled() {
super.attemptCancelled();
attributes.put(STATUS_ATTRIBUTE, StatusCode.Code.CANCELLED.toString());
builtInOpenTelemetryMetricsRecorder.recordServerTimingHeaderMetrics(
gfeLatency, afeLatency, gfeHeaderMissingCount, afeHeaderMissingCount, attributes);
gfeLatency, afeLatency, attributes, isDirectPathUsed, isAfeEnabled);
}
}

Expand All @@ -98,7 +98,7 @@ public void attemptFailedDuration(Throwable error, java.time.Duration delay) {
super.attemptFailedDuration(error, delay);
attributes.put(STATUS_ATTRIBUTE, extractStatus(error));
builtInOpenTelemetryMetricsRecorder.recordServerTimingHeaderMetrics(
gfeLatency, afeLatency, gfeHeaderMissingCount, afeHeaderMissingCount, attributes);
gfeLatency, afeLatency, attributes, isDirectPathUsed, isAfeEnabled);
}
}

Expand All @@ -115,7 +115,7 @@ public void attemptFailedRetriesExhausted(Throwable error) {
super.attemptFailedRetriesExhausted(error);
attributes.put(STATUS_ATTRIBUTE, extractStatus(error));
builtInOpenTelemetryMetricsRecorder.recordServerTimingHeaderMetrics(
gfeLatency, afeLatency, gfeHeaderMissingCount, afeHeaderMissingCount, attributes);
gfeLatency, afeLatency, attributes, isDirectPathUsed, isAfeEnabled);
}
}

Expand All @@ -132,24 +132,16 @@ public void attemptPermanentFailure(Throwable error) {
super.attemptPermanentFailure(error);
attributes.put(STATUS_ATTRIBUTE, extractStatus(error));
builtInOpenTelemetryMetricsRecorder.recordServerTimingHeaderMetrics(
gfeLatency, afeLatency, gfeHeaderMissingCount, afeHeaderMissingCount, attributes);
gfeLatency, afeLatency, attributes, isDirectPathUsed, isAfeEnabled);
}
}

void recordGFELatency(Float gfeLatency) {
public void recordServerTimingHeaderMetrics(
Float gfeLatency, Float afeLatency, boolean isDirectPathUsed, boolean isAfeEnabled) {
this.gfeLatency = gfeLatency;
}

void recordAFELatency(Float afeLatency) {
this.isDirectPathUsed = isDirectPathUsed;
this.afeLatency = afeLatency;
}

void recordGfeHeaderMissingCount(Long value) {
this.gfeHeaderMissingCount = value;
}

void recordAfeHeaderMissingCount(Long value) {
this.afeHeaderMissingCount = value;
this.isAfeEnabled = isAfeEnabled;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,50 +191,13 @@ public void addAttributes(Map<String, String> attributes) {
}
}

public void recordGFELatency(Long gfeLatency) {
public void recordServerTimingHeaderMetrics(
Float gfeLatency, Float afeLatency, boolean isDirectPathUsed, boolean isAfeEnabled) {
for (ApiTracer child : children) {
if (child instanceof BuiltInMetricsTracer) {
((BuiltInMetricsTracer) child).recordGFELatency(Float.valueOf(gfeLatency));
}
}
}

public void recordGfeHeaderMissingCount(Long value) {
for (ApiTracer child : children) {
if (child instanceof BuiltInMetricsTracer) {
((BuiltInMetricsTracer) child).recordGfeHeaderMissingCount(value);
}
}
}

public void recordAFELatency(Long afeLatency) {
for (ApiTracer child : children) {
if (child instanceof BuiltInMetricsTracer) {
((BuiltInMetricsTracer) child).recordAFELatency(Float.valueOf(afeLatency));
}
}
}

public void recordAfeHeaderMissingCount(Long value) {
for (ApiTracer child : children) {
if (child instanceof BuiltInMetricsTracer) {
((BuiltInMetricsTracer) child).recordAfeHeaderMissingCount(value);
}
}
}

public void recordGFELatency(Float gfeLatency) {
for (ApiTracer child : children) {
if (child instanceof BuiltInMetricsTracer) {
((BuiltInMetricsTracer) child).recordGFELatency(gfeLatency);
}
}
}

public void recordAFELatency(Float afeLatency) {
for (ApiTracer child : children) {
if (child instanceof BuiltInMetricsTracer) {
((BuiltInMetricsTracer) child).recordAFELatency(afeLatency);
((BuiltInMetricsTracer) child)
.recordServerTimingHeaderMetrics(
gfeLatency, afeLatency, isDirectPathUsed, isAfeEnabled);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ public class TransactionMutationLimitExceededException extends SpannerException

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

private static final String TRANSACTION_RESOURCE_LIMIT_EXCEEDED_MESSAGE =
"Transaction resource limits exceeded";

/** Private constructor. Use {@link SpannerExceptionFactory} to create instances. */
TransactionMutationLimitExceededException(
DoNotConstructDirectly token,
Expand All @@ -40,13 +43,17 @@ public class TransactionMutationLimitExceededException extends SpannerException
}

static boolean isTransactionMutationLimitException(ErrorCode code, String message) {
return code == ErrorCode.INVALID_ARGUMENT && message != null && message.contains(ERROR_MESSAGE);
return code == ErrorCode.INVALID_ARGUMENT
&& message != null
&& (message.contains(ERROR_MESSAGE)
|| message.contains(TRANSACTION_RESOURCE_LIMIT_EXCEEDED_MESSAGE));
}

static boolean isTransactionMutationLimitException(Throwable cause, ApiException apiException) {
if (cause == null
|| cause.getMessage() == null
|| !cause.getMessage().contains(ERROR_MESSAGE)) {
|| !(cause.getMessage().contains(ERROR_MESSAGE)
|| cause.getMessage().contains(TRANSACTION_RESOURCE_LIMIT_EXCEEDED_MESSAGE))) {
return false;
}
// Spanner includes a hint that points to the Spanner limits documentation page when the error
Expand All @@ -66,6 +73,9 @@ static boolean isTransactionMutationLimitException(Throwable cause, ApiException
.getLinks(0)
.getUrl()
.equals("https://cloud.google.com/spanner/docs/limits");
} else if (cause.getMessage().contains(TRANSACTION_RESOURCE_LIMIT_EXCEEDED_MESSAGE)) {
// This more generic error does not contain any additional details.
return true;
}
return false;
}
Expand Down
Loading