Skip to content

Commit fd48725

Browse files
Merge branch 'mux-partitioned-ops-fallback' of github.com:pratickchokhani/java-spanner into mux-partitioned-ops-fallback
2 parents 70fc234 + 74d7abd commit fd48725

File tree

46 files changed

+6581
-379
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+6581
-379
lines changed

generation_config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
gapic_generator_version: 2.52.0
2-
googleapis_commitish: 2a3db2e19f48a139db9f40278c0217df110add9b
2+
googleapis_commitish: 3cf61b2df20eace09e6336c23f9e08859c0d87ae
33
libraries_bom_version: 26.53.0
44
libraries:
55
- api_shortname: spanner

google-cloud-spanner-executor/src/main/resources/META-INF/native-image/com.google.cloud.spanner.executor.v1/reflect-config.json

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1700,6 +1700,42 @@
17001700
"allDeclaredClasses": true,
17011701
"allPublicClasses": true
17021702
},
1703+
{
1704+
"name": "com.google.spanner.admin.database.v1.AddSplitPointsRequest",
1705+
"queryAllDeclaredConstructors": true,
1706+
"queryAllPublicConstructors": true,
1707+
"queryAllDeclaredMethods": true,
1708+
"allPublicMethods": true,
1709+
"allDeclaredClasses": true,
1710+
"allPublicClasses": true
1711+
},
1712+
{
1713+
"name": "com.google.spanner.admin.database.v1.AddSplitPointsRequest$Builder",
1714+
"queryAllDeclaredConstructors": true,
1715+
"queryAllPublicConstructors": true,
1716+
"queryAllDeclaredMethods": true,
1717+
"allPublicMethods": true,
1718+
"allDeclaredClasses": true,
1719+
"allPublicClasses": true
1720+
},
1721+
{
1722+
"name": "com.google.spanner.admin.database.v1.AddSplitPointsResponse",
1723+
"queryAllDeclaredConstructors": true,
1724+
"queryAllPublicConstructors": true,
1725+
"queryAllDeclaredMethods": true,
1726+
"allPublicMethods": true,
1727+
"allDeclaredClasses": true,
1728+
"allPublicClasses": true
1729+
},
1730+
{
1731+
"name": "com.google.spanner.admin.database.v1.AddSplitPointsResponse$Builder",
1732+
"queryAllDeclaredConstructors": true,
1733+
"queryAllPublicConstructors": true,
1734+
"queryAllDeclaredMethods": true,
1735+
"allPublicMethods": true,
1736+
"allDeclaredClasses": true,
1737+
"allPublicClasses": true
1738+
},
17031739
{
17041740
"name": "com.google.spanner.admin.database.v1.Backup",
17051741
"queryAllDeclaredConstructors": true,
@@ -2618,6 +2654,42 @@
26182654
"allDeclaredClasses": true,
26192655
"allPublicClasses": true
26202656
},
2657+
{
2658+
"name": "com.google.spanner.admin.database.v1.SplitPoints",
2659+
"queryAllDeclaredConstructors": true,
2660+
"queryAllPublicConstructors": true,
2661+
"queryAllDeclaredMethods": true,
2662+
"allPublicMethods": true,
2663+
"allDeclaredClasses": true,
2664+
"allPublicClasses": true
2665+
},
2666+
{
2667+
"name": "com.google.spanner.admin.database.v1.SplitPoints$Builder",
2668+
"queryAllDeclaredConstructors": true,
2669+
"queryAllPublicConstructors": true,
2670+
"queryAllDeclaredMethods": true,
2671+
"allPublicMethods": true,
2672+
"allDeclaredClasses": true,
2673+
"allPublicClasses": true
2674+
},
2675+
{
2676+
"name": "com.google.spanner.admin.database.v1.SplitPoints$Key",
2677+
"queryAllDeclaredConstructors": true,
2678+
"queryAllPublicConstructors": true,
2679+
"queryAllDeclaredMethods": true,
2680+
"allPublicMethods": true,
2681+
"allDeclaredClasses": true,
2682+
"allPublicClasses": true
2683+
},
2684+
{
2685+
"name": "com.google.spanner.admin.database.v1.SplitPoints$Key$Builder",
2686+
"queryAllDeclaredConstructors": true,
2687+
"queryAllPublicConstructors": true,
2688+
"queryAllDeclaredMethods": true,
2689+
"allPublicMethods": true,
2690+
"allDeclaredClasses": true,
2691+
"allPublicClasses": true
2692+
},
26212693
{
26222694
"name": "com.google.spanner.admin.database.v1.UpdateBackupRequest",
26232695
"queryAllDeclaredConstructors": true,

google-cloud-spanner/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,7 @@
371371
<artifactId>junit</artifactId>
372372
<scope>test</scope>
373373
</dependency>
374-
374+
375375
<!-- Executor tests - The 'provided' scope is overwritten to compile time scope for the profile 'executor-tests' -->
376376
<dependency>
377377
<groupId>com.google.api.grpc</groupId>

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

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@
3434
public class BuiltInMetricsConstant {
3535

3636
public static final String METER_NAME = "spanner.googleapis.com/internal/client";
37-
3837
public static final String GAX_METER_NAME = OpenTelemetryMetricsRecorder.GAX_METER_NAME;
39-
38+
static final String SPANNER_METER_NAME = "spanner-java";
39+
static final String GFE_LATENCIES_NAME = "gfe_latencies";
4040
static final String OPERATION_LATENCIES_NAME = "operation_latencies";
4141
static final String ATTEMPT_LATENCIES_NAME = "attempt_latencies";
4242
static final String OPERATION_LATENCY_NAME = "operation_latency";
@@ -49,7 +49,8 @@ public class BuiltInMetricsConstant {
4949
OPERATION_LATENCIES_NAME,
5050
ATTEMPT_LATENCIES_NAME,
5151
OPERATION_COUNT_NAME,
52-
ATTEMPT_COUNT_NAME)
52+
ATTEMPT_COUNT_NAME,
53+
GFE_LATENCIES_NAME)
5354
.stream()
5455
.map(m -> METER_NAME + '/' + m)
5556
.collect(Collectors.toSet());
@@ -114,27 +115,39 @@ static Map<InstrumentSelector, View> getAllViews() {
114115
ImmutableMap.Builder<InstrumentSelector, View> views = ImmutableMap.builder();
115116
defineView(
116117
views,
118+
BuiltInMetricsConstant.GAX_METER_NAME,
117119
BuiltInMetricsConstant.OPERATION_LATENCY_NAME,
118120
BuiltInMetricsConstant.OPERATION_LATENCIES_NAME,
119121
BuiltInMetricsConstant.AGGREGATION_WITH_MILLIS_HISTOGRAM,
120122
InstrumentType.HISTOGRAM,
121123
"ms");
122124
defineView(
123125
views,
126+
BuiltInMetricsConstant.GAX_METER_NAME,
124127
BuiltInMetricsConstant.ATTEMPT_LATENCY_NAME,
125128
BuiltInMetricsConstant.ATTEMPT_LATENCIES_NAME,
126129
BuiltInMetricsConstant.AGGREGATION_WITH_MILLIS_HISTOGRAM,
127130
InstrumentType.HISTOGRAM,
128131
"ms");
129132
defineView(
130133
views,
134+
BuiltInMetricsConstant.SPANNER_METER_NAME,
135+
BuiltInMetricsConstant.GFE_LATENCIES_NAME,
136+
BuiltInMetricsConstant.GFE_LATENCIES_NAME,
137+
BuiltInMetricsConstant.AGGREGATION_WITH_MILLIS_HISTOGRAM,
138+
InstrumentType.HISTOGRAM,
139+
"ms");
140+
defineView(
141+
views,
142+
BuiltInMetricsConstant.GAX_METER_NAME,
131143
BuiltInMetricsConstant.OPERATION_COUNT_NAME,
132144
BuiltInMetricsConstant.OPERATION_COUNT_NAME,
133145
Aggregation.sum(),
134146
InstrumentType.COUNTER,
135147
"1");
136148
defineView(
137149
views,
150+
BuiltInMetricsConstant.GAX_METER_NAME,
138151
BuiltInMetricsConstant.ATTEMPT_COUNT_NAME,
139152
BuiltInMetricsConstant.ATTEMPT_COUNT_NAME,
140153
Aggregation.sum(),
@@ -145,6 +158,7 @@ static Map<InstrumentSelector, View> getAllViews() {
145158

146159
private static void defineView(
147160
ImmutableMap.Builder<InstrumentSelector, View> viewMap,
161+
String meterName,
148162
String metricName,
149163
String metricViewName,
150164
Aggregation aggregation,
@@ -153,7 +167,7 @@ private static void defineView(
153167
InstrumentSelector selector =
154168
InstrumentSelector.builder()
155169
.setName(BuiltInMetricsConstant.METER_NAME + '/' + metricName)
156-
.setMeterName(BuiltInMetricsConstant.GAX_METER_NAME)
170+
.setMeterName(meterName)
157171
.setType(type)
158172
.setUnit(unit)
159173
.build();
Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,25 +46,24 @@
4646
import java.util.logging.Logger;
4747
import javax.annotation.Nullable;
4848

49-
final class BuiltInOpenTelemetryMetricsProvider {
49+
final class BuiltInMetricsProvider {
5050

51-
static BuiltInOpenTelemetryMetricsProvider INSTANCE = new BuiltInOpenTelemetryMetricsProvider();
51+
static BuiltInMetricsProvider INSTANCE = new BuiltInMetricsProvider();
5252

53-
private static final Logger logger =
54-
Logger.getLogger(BuiltInOpenTelemetryMetricsProvider.class.getName());
53+
private static final Logger logger = Logger.getLogger(BuiltInMetricsProvider.class.getName());
5554

5655
private static String taskId;
5756

5857
private OpenTelemetry openTelemetry;
5958

60-
private BuiltInOpenTelemetryMetricsProvider() {}
59+
private BuiltInMetricsProvider() {}
6160

6261
OpenTelemetry getOrCreateOpenTelemetry(
6362
String projectId, @Nullable Credentials credentials, @Nullable String monitoringHost) {
6463
try {
6564
if (this.openTelemetry == null) {
6665
SdkMeterProviderBuilder sdkMeterProviderBuilder = SdkMeterProvider.builder();
67-
BuiltInOpenTelemetryMetricsView.registerBuiltinMetrics(
66+
BuiltInMetricsView.registerBuiltinMetrics(
6867
SpannerCloudMonitoringExporter.create(projectId, credentials, monitoringHost),
6968
sdkMeterProviderBuilder);
7069
SdkMeterProvider sdkMeterProvider = sdkMeterProviderBuilder.build();
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
/*
2+
* Copyright 2025 Google LLC
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package com.google.cloud.spanner;
18+
19+
import com.google.api.gax.core.GaxProperties;
20+
import com.google.api.gax.tracing.OpenTelemetryMetricsRecorder;
21+
import com.google.common.base.Preconditions;
22+
import io.opentelemetry.api.OpenTelemetry;
23+
import io.opentelemetry.api.common.Attributes;
24+
import io.opentelemetry.api.common.AttributesBuilder;
25+
import io.opentelemetry.api.metrics.DoubleHistogram;
26+
import io.opentelemetry.api.metrics.Meter;
27+
import java.util.Map;
28+
29+
/**
30+
* Implementation for recording built in metrics.
31+
*
32+
* <p>This class extends the {@link OpenTelemetryMetricsRecorder} which implements the *
33+
* measurements related to the lifecyle of an RPC.
34+
*/
35+
class BuiltInMetricsRecorder extends OpenTelemetryMetricsRecorder {
36+
37+
private final DoubleHistogram gfeLatencyRecorder;
38+
39+
/**
40+
* Creates the following instruments for the following metrics:
41+
*
42+
* <ul>
43+
* <li>GFE Latency: Histogram
44+
* </ul>
45+
*
46+
* @param openTelemetry OpenTelemetry instance
47+
* @param serviceName Service Name
48+
*/
49+
BuiltInMetricsRecorder(OpenTelemetry openTelemetry, String serviceName) {
50+
super(openTelemetry, serviceName);
51+
Meter meter =
52+
openTelemetry
53+
.meterBuilder(BuiltInMetricsConstant.SPANNER_METER_NAME)
54+
.setInstrumentationVersion(GaxProperties.getLibraryVersion(getClass()))
55+
.build();
56+
this.gfeLatencyRecorder =
57+
meter
58+
.histogramBuilder(serviceName + '/' + BuiltInMetricsConstant.GFE_LATENCIES_NAME)
59+
.setDescription(
60+
"Latency between Google's network receiving an RPC and reading back the first byte of the response")
61+
.setUnit("ms")
62+
.build();
63+
}
64+
65+
/**
66+
* Record the latency between Google's network receiving an RPC and reading back the first byte of
67+
* the response. Data is stored in a Histogram.
68+
*
69+
* @param gfeLatency Attempt Latency in ms
70+
* @param attributes Map of the attributes to store
71+
*/
72+
void recordGFELatency(double gfeLatency, Map<String, String> attributes) {
73+
gfeLatencyRecorder.record(gfeLatency, toOtelAttributes(attributes));
74+
}
75+
76+
Attributes toOtelAttributes(Map<String, String> attributes) {
77+
Preconditions.checkNotNull(attributes, "Attributes map cannot be null");
78+
AttributesBuilder attributesBuilder = Attributes.builder();
79+
attributes.forEach(attributesBuilder::put);
80+
return attributesBuilder.build();
81+
}
82+
}

0 commit comments

Comments
 (0)