Skip to content
Merged
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
2 changes: 1 addition & 1 deletion gapic-libraries-bom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1245,7 +1245,7 @@
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-spanner-bom</artifactId>
<version>6.112.1-SNAPSHOT</version><!-- {x-version-update:google-cloud-spanner:current} -->
<version>6.113.1-SNAPSHOT</version><!-- {x-version-update:google-cloud-spanner:current} -->
<type>pom</type>
<scope>import</scope>
</dependency>
Expand Down
6 changes: 3 additions & 3 deletions java-spanner-jdbc/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-spanner</artifactId>
<version>6.112.1-SNAPSHOT</version><!-- {x-version-update:google-cloud-spanner:current} -->
<version>6.113.1-SNAPSHOT</version><!-- {x-version-update:google-cloud-spanner:current} -->
</dependency>
<dependency>
<groupId>io.grpc</groupId>
Expand Down Expand Up @@ -137,7 +137,7 @@
<dependency>
<groupId>com.google.api.grpc</groupId>
<artifactId>proto-google-cloud-spanner-v1</artifactId>
<version>6.112.1-SNAPSHOT</version><!-- {x-version-update:proto-google-cloud-spanner-v1:current} -->
<version>6.113.1-SNAPSHOT</version><!-- {x-version-update:proto-google-cloud-spanner-v1:current} -->
</dependency>
<dependency>
<groupId>io.opentelemetry</groupId>
Expand All @@ -147,7 +147,7 @@
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-spanner</artifactId>
<version>6.112.1-SNAPSHOT</version><!-- {x-version-update:google-cloud-spanner:current} -->
<version>6.113.1-SNAPSHOT</version><!-- {x-version-update:google-cloud-spanner:current} -->
<type>test-jar</type>
<scope>test</scope>
</dependency>
Expand Down
4 changes: 2 additions & 2 deletions java-spanner/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ If you are using Maven with [BOM][libraries-bom], add this to your pom.xml file:
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>libraries-bom</artifactId>
<version>26.76.0</version>
<version>26.78.0</version>
<type>pom</type>
<scope>import</scope>
</dependency>
Expand All @@ -41,7 +41,7 @@ If you are using Maven without the BOM, add this to your dependencies:
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-spanner</artifactId>
<version>6.110.0</version>
<version>6.112.0</version>
</dependency>

```
Expand Down
2 changes: 1 addition & 1 deletion java-spanner/benchmarks/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<parent>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-spanner-parent</artifactId>
<version>6.112.1-SNAPSHOT</version><!-- {x-version-update:google-cloud-spanner:current} -->
<version>6.113.1-SNAPSHOT</version><!-- {x-version-update:google-cloud-spanner:current} -->
</parent>

<properties>
Expand Down
18 changes: 9 additions & 9 deletions java-spanner/google-cloud-spanner-bom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-spanner-bom</artifactId>
<version>6.112.1-SNAPSHOT</version><!-- {x-version-update:google-cloud-spanner:current} -->
<version>6.113.1-SNAPSHOT</version><!-- {x-version-update:google-cloud-spanner:current} -->
<packaging>pom</packaging>
<parent>
<groupId>com.google.cloud</groupId>
Expand Down Expand Up @@ -53,43 +53,43 @@
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-spanner</artifactId>
<version>6.112.1-SNAPSHOT</version><!-- {x-version-update:google-cloud-spanner:current} -->
<version>6.113.1-SNAPSHOT</version><!-- {x-version-update:google-cloud-spanner:current} -->
</dependency>
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-spanner</artifactId>
<type>test-jar</type>
<version>6.112.1-SNAPSHOT</version><!-- {x-version-update:google-cloud-spanner:current} -->
<version>6.113.1-SNAPSHOT</version><!-- {x-version-update:google-cloud-spanner:current} -->
</dependency>
<dependency>
<groupId>com.google.api.grpc</groupId>
<artifactId>grpc-google-cloud-spanner-v1</artifactId>
<version>6.112.1-SNAPSHOT</version><!-- {x-version-update:grpc-google-cloud-spanner-v1:current} -->
<version>6.113.1-SNAPSHOT</version><!-- {x-version-update:grpc-google-cloud-spanner-v1:current} -->
</dependency>
<dependency>
<groupId>com.google.api.grpc</groupId>
<artifactId>grpc-google-cloud-spanner-admin-instance-v1</artifactId>
<version>6.112.1-SNAPSHOT</version><!-- {x-version-update:grpc-google-cloud-spanner-admin-instance-v1:current} -->
<version>6.113.1-SNAPSHOT</version><!-- {x-version-update:grpc-google-cloud-spanner-admin-instance-v1:current} -->
</dependency>
<dependency>
<groupId>com.google.api.grpc</groupId>
<artifactId>grpc-google-cloud-spanner-admin-database-v1</artifactId>
<version>6.112.1-SNAPSHOT</version><!-- {x-version-update:grpc-google-cloud-spanner-admin-database-v1:current} -->
<version>6.113.1-SNAPSHOT</version><!-- {x-version-update:grpc-google-cloud-spanner-admin-database-v1:current} -->
</dependency>
<dependency>
<groupId>com.google.api.grpc</groupId>
<artifactId>proto-google-cloud-spanner-admin-instance-v1</artifactId>
<version>6.112.1-SNAPSHOT</version><!-- {x-version-update:proto-google-cloud-spanner-admin-instance-v1:current} -->
<version>6.113.1-SNAPSHOT</version><!-- {x-version-update:proto-google-cloud-spanner-admin-instance-v1:current} -->
</dependency>
<dependency>
<groupId>com.google.api.grpc</groupId>
<artifactId>proto-google-cloud-spanner-v1</artifactId>
<version>6.112.1-SNAPSHOT</version><!-- {x-version-update:proto-google-cloud-spanner-v1:current} -->
<version>6.113.1-SNAPSHOT</version><!-- {x-version-update:proto-google-cloud-spanner-v1:current} -->
</dependency>
<dependency>
<groupId>com.google.api.grpc</groupId>
<artifactId>proto-google-cloud-spanner-admin-database-v1</artifactId>
<version>6.112.1-SNAPSHOT</version><!-- {x-version-update:proto-google-cloud-spanner-admin-database-v1:current} -->
<version>6.113.1-SNAPSHOT</version><!-- {x-version-update:proto-google-cloud-spanner-admin-database-v1:current} -->
</dependency>
</dependencies>
</dependencyManagement>
Expand Down
4 changes: 2 additions & 2 deletions java-spanner/google-cloud-spanner-executor/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-spanner-executor</artifactId>
<version>6.112.1-SNAPSHOT</version><!-- {x-version-update:google-cloud-spanner-executor:current} -->
<version>6.113.1-SNAPSHOT</version><!-- {x-version-update:google-cloud-spanner-executor:current} -->
<packaging>jar</packaging>
<name>Google Cloud Spanner Executor</name>

<parent>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-spanner-parent</artifactId>
<version>6.112.1-SNAPSHOT</version><!-- {x-version-update:google-cloud-spanner:current} -->
<version>6.113.1-SNAPSHOT</version><!-- {x-version-update:google-cloud-spanner:current} -->
</parent>

<properties>
Expand Down
4 changes: 2 additions & 2 deletions java-spanner/google-cloud-spanner/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-spanner</artifactId>
<version>6.112.1-SNAPSHOT</version><!-- {x-version-update:google-cloud-spanner:current} -->
<version>6.113.1-SNAPSHOT</version><!-- {x-version-update:google-cloud-spanner:current} -->
<packaging>jar</packaging>
<name>Google Cloud Spanner</name>
<url>https://github.com/googleapis/google-cloud-java</url>
<description>Java idiomatic client for Google Cloud Spanner.</description>
<parent>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-spanner-parent</artifactId>
<version>6.112.1-SNAPSHOT</version><!-- {x-version-update:google-cloud-spanner:current} -->
<version>6.113.1-SNAPSHOT</version><!-- {x-version-update:google-cloud-spanner:current} -->
</parent>
<properties>
<site.installationModule>google-cloud-spanner</site.installationModule>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public class BuiltInMetricsConstant {

public static final String METER_NAME = "spanner.googleapis.com/internal/client";
public static final String GAX_METER_NAME = OpenTelemetryMetricsRecorder.GAX_METER_NAME;
public static final String GRPC_GCP_METER_NAME = "grpc-gcp";
static final String SPANNER_METER_NAME = "spanner-java";
static final String GRPC_METER_NAME = "grpc-java";
static final String GFE_LATENCIES_NAME = "gfe_latencies";
Expand All @@ -53,6 +54,8 @@ public class BuiltInMetricsConstant {
static final String ATTEMPT_LATENCY_NAME = "attempt_latency";
static final String OPERATION_COUNT_NAME = "operation_count";
static final String ATTEMPT_COUNT_NAME = "attempt_count";
static final String EEF_FALLBACK_COUNT_NAME = "eef.fallback_count";
static final String EEF_CALL_STATUS_NAME = "eef.call_status";

public static final Set<String> SPANNER_METRICS =
ImmutableSet.of(
Expand Down Expand Up @@ -117,6 +120,29 @@ public class BuiltInMetricsConstant {
"grpc.xds_client.resource_updates_invalid",
"grpc.xds_client.resource_updates_valid");

public static final AttributeKey<String> CHANNEL_NAME_KEY =
AttributeKey.stringKey("channel_name");
public static final AttributeKey<String> FROM_CHANNEL_NAME_KEY =
AttributeKey.stringKey("from_channel_name");
public static final AttributeKey<String> TO_CHANNEL_NAME_KEY =
AttributeKey.stringKey("to_channel_name");
public static final AttributeKey<String> STATUS_CODE_KEY = AttributeKey.stringKey("status_code");

static final Set<String> GRPC_GCP_EEF_FALLBACK_COUNT_ATTRIBUTES =
ImmutableSet.of(FROM_CHANNEL_NAME_KEY.getKey(), TO_CHANNEL_NAME_KEY.getKey());

static final Set<String> GRPC_GCP_EEF_CALL_STATUS_ATTRIBUTES =
ImmutableSet.of(CHANNEL_NAME_KEY.getKey(), STATUS_CODE_KEY.getKey());

static final Map<String, Set<String>> GRPC_GCP_METRIC_ADDITIONAL_ATTRIBUTES =
ImmutableMap.<String, Set<String>>builder()
.put(EEF_FALLBACK_COUNT_NAME, GRPC_GCP_EEF_FALLBACK_COUNT_ATTRIBUTES)
.put(EEF_CALL_STATUS_NAME, GRPC_GCP_EEF_CALL_STATUS_ATTRIBUTES)
.build();

static final Collection<String> GRPC_GCP_METRICS_TO_ENABLE =
ImmutableList.of(EEF_FALLBACK_COUNT_NAME, EEF_CALL_STATUS_NAME);

public static final String SPANNER_RESOURCE_TYPE = "spanner_instance_client";

public static final AttributeKey<String> PROJECT_ID_KEY = AttributeKey.stringKey("project_id");
Expand Down Expand Up @@ -215,6 +241,7 @@ static Map<InstrumentSelector, View> getAllViews() {
"1");
defineSpannerView(views);
defineGRPCView(views);
defineGrpcGcpView(views);
return views.build();
}

Expand Down Expand Up @@ -281,4 +308,31 @@ private static void defineGRPCView(ImmutableMap.Builder<InstrumentSelector, View
viewMap.put(selector, view);
}
}

private static void defineGrpcGcpView(ImmutableMap.Builder<InstrumentSelector, View> viewMap) {
for (String metric : GRPC_GCP_METRICS_TO_ENABLE) {
InstrumentSelector selector =
InstrumentSelector.builder()
.setName(metric)
.setMeterName(BuiltInMetricsConstant.GRPC_GCP_METER_NAME)
.build();

Set<String> attributesFilter =
BuiltInMetricsConstant.COMMON_ATTRIBUTES.stream()
.map(AttributeKey::getKey)
.collect(Collectors.toSet());

attributesFilter.addAll(
GRPC_GCP_METRIC_ADDITIONAL_ATTRIBUTES.getOrDefault(metric, ImmutableSet.of()));

View view =
View.builder()
.setName(BuiltInMetricsConstant.METER_NAME + '/' + metric.replace(".", "/"))
.setAggregation(Aggregation.sum())
.setAttributeFilter(attributesFilter)
.build();

viewMap.put(selector, view);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import static com.google.api.MetricDescriptor.ValueType.INT64;
import static com.google.cloud.spanner.BuiltInMetricsConstant.ALLOWED_EXEMPLARS_ATTRIBUTES;
import static com.google.cloud.spanner.BuiltInMetricsConstant.GAX_METER_NAME;
import static com.google.cloud.spanner.BuiltInMetricsConstant.GRPC_GCP_METER_NAME;
import static com.google.cloud.spanner.BuiltInMetricsConstant.GRPC_METER_NAME;
import static com.google.cloud.spanner.BuiltInMetricsConstant.PROJECT_ID_KEY;
import static com.google.cloud.spanner.BuiltInMetricsConstant.SPANNER_METER_NAME;
Expand Down Expand Up @@ -86,7 +87,8 @@ static List<TimeSeries> convertToSpannerTimeSeries(
// Get metrics data from GAX library, GRPC library and Spanner library
if (!(metricData.getInstrumentationScopeInfo().getName().equals(GAX_METER_NAME)
|| metricData.getInstrumentationScopeInfo().getName().equals(SPANNER_METER_NAME)
|| metricData.getInstrumentationScopeInfo().getName().equals(GRPC_METER_NAME))) {
|| metricData.getInstrumentationScopeInfo().getName().equals(GRPC_METER_NAME)
|| metricData.getInstrumentationScopeInfo().getName().equals(GRPC_GCP_METER_NAME))) {
// Filter out metric data for instruments that are not part of the spanner metrics list
continue;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2380,6 +2380,13 @@ public ApiTracerFactory getApiTracerFactory() {
return createApiTracerFactory(false, false);
}

/** Returns the internal OpenTelemetry instance used for built-in metrics. */
@InternalApi
public OpenTelemetry getBuiltInOpenTelemetry() {
return this.builtInMetricsProvider.getOrCreateOpenTelemetry(
this.getProjectId(), getCredentials(), this.monitoringHost, getUniverseDomain());
}

public void enablegRPCMetrics(InstantiatingGrpcChannelProvider.Builder channelProviderBuilder) {
if (SpannerOptions.environment.isEnableGRPCBuiltInMetrics()) {
this.builtInMetricsProvider.enableGrpcMetrics(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,18 @@
import com.google.api.core.InternalApi;
import com.google.spanner.v1.BeginTransactionRequest;
import com.google.spanner.v1.CacheUpdate;
import com.google.spanner.v1.CommitRequest;
import com.google.spanner.v1.DirectedReadOptions;
import com.google.spanner.v1.ExecuteSqlRequest;
import com.google.spanner.v1.Mutation;
import com.google.spanner.v1.ReadRequest;
import com.google.spanner.v1.RoutingHint;
import com.google.spanner.v1.TransactionOptions;
import com.google.spanner.v1.TransactionSelector;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.concurrent.ThreadLocalRandom;
import java.util.concurrent.atomic.AtomicLong;

/**
Expand Down Expand Up @@ -95,31 +100,59 @@ public ChannelEndpoint findServer(BeginTransactionRequest.Builder reqBuilder) {
if (!reqBuilder.hasMutationKey()) {
return null;
}
TargetRange target = recipeCache.mutationToTargetRange(reqBuilder.getMutationKey());
if (target == null) {
return routeMutation(
reqBuilder.getMutationKey(),
preferLeader(reqBuilder.getOptions()),
reqBuilder.getRoutingHintBuilder());
}

public ChannelEndpoint fillRoutingHint(CommitRequest.Builder reqBuilder) {
Mutation mutation = selectMutationForRouting(reqBuilder.getMutationsList());
if (mutation == null) {
return null;
}
RoutingHint.Builder hintBuilder = RoutingHint.newBuilder();
hintBuilder.setKey(target.start);
if (!target.limit.isEmpty()) {
hintBuilder.setLimitKey(target.limit);
return routeMutation(mutation, /* preferLeader= */ true, reqBuilder.getRoutingHintBuilder());
}

private static Mutation selectMutationForRouting(List<Mutation> mutations) {
if (mutations.isEmpty()) {
return null;
}
List<Mutation> mutationsExcludingInsert = new ArrayList<>();
Mutation largestInsertMutation = null;
for (Mutation mutation : mutations) {
if (!mutation.hasInsert()) {
mutationsExcludingInsert.add(mutation);
continue;
}
if (largestInsertMutation == null
|| mutation.getInsert().getValuesCount()
> largestInsertMutation.getInsert().getValuesCount()) {
largestInsertMutation = mutation;
}
}
if (!mutationsExcludingInsert.isEmpty()) {
return mutationsExcludingInsert.get(
ThreadLocalRandom.current().nextInt(mutationsExcludingInsert.size()));
}
return largestInsertMutation;
}

private ChannelEndpoint routeMutation(
Mutation mutation, boolean preferLeader, RoutingHint.Builder hintBuilder) {
recipeCache.applySchemaGeneration(hintBuilder);
TargetRange target = recipeCache.mutationToTargetRange(mutation);
if (target == null) {
return null;
}
recipeCache.applyTargetRange(hintBuilder, target);
return fillRoutingHint(
preferLeader(reqBuilder.getOptions()),
preferLeader,
KeyRangeCache.RangeMode.COVERING_SPLIT,
DirectedReadOptions.getDefaultInstance(),
hintBuilder);
}

private ChannelEndpoint fillRoutingHint(
TransactionSelector transactionSelector,
DirectedReadOptions directedReadOptions,
KeyRangeCache.RangeMode rangeMode,
RoutingHint.Builder hintBuilder) {
return fillRoutingHint(
preferLeader(transactionSelector), rangeMode, directedReadOptions, hintBuilder);
}

private ChannelEndpoint fillRoutingHint(
boolean preferLeader,
KeyRangeCache.RangeMode rangeMode,
Expand Down
Loading
Loading