Skip to content

Commit 943045f

Browse files
committed
Merge branch 'main' of https://github.com/googleapis/java-spanner into e2e-tracing-systest
2 parents 71626ed + 438f837 commit 943045f

File tree

22 files changed

+7045
-708
lines changed

22 files changed

+7045
-708
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ If you are using Maven without the BOM, add this to your dependencies:
5050
If you are using Gradle 5.x or later, add this to your dependencies:
5151

5252
```Groovy
53-
implementation platform('com.google.cloud:libraries-bom:26.47.0')
53+
implementation platform('com.google.cloud:libraries-bom:26.48.0')
5454
5555
implementation 'com.google.cloud:google-cloud-spanner'
5656
```

generation_config.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
gapic_generator_version: 2.46.1
2-
googleapis_commitish: 16a1580c06b3b32e8ab33c39d846bba7e21bfae3
3-
libraries_bom_version: 26.47.0
2+
googleapis_commitish: b6a27d13a2f0223051ef720e4e9d0d52323560e6
3+
libraries_bom_version: 26.48.0
44
libraries:
55
- api_shortname: spanner
66
name_pretty: Cloud 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
@@ -2717,6 +2717,42 @@
27172717
"allDeclaredClasses": true,
27182718
"allPublicClasses": true
27192719
},
2720+
{
2721+
"name": "com.google.spanner.admin.instance.v1.AutoscalingConfig$AsymmetricAutoscalingOption",
2722+
"queryAllDeclaredConstructors": true,
2723+
"queryAllPublicConstructors": true,
2724+
"queryAllDeclaredMethods": true,
2725+
"allPublicMethods": true,
2726+
"allDeclaredClasses": true,
2727+
"allPublicClasses": true
2728+
},
2729+
{
2730+
"name": "com.google.spanner.admin.instance.v1.AutoscalingConfig$AsymmetricAutoscalingOption$AutoscalingConfigOverrides",
2731+
"queryAllDeclaredConstructors": true,
2732+
"queryAllPublicConstructors": true,
2733+
"queryAllDeclaredMethods": true,
2734+
"allPublicMethods": true,
2735+
"allDeclaredClasses": true,
2736+
"allPublicClasses": true
2737+
},
2738+
{
2739+
"name": "com.google.spanner.admin.instance.v1.AutoscalingConfig$AsymmetricAutoscalingOption$AutoscalingConfigOverrides$Builder",
2740+
"queryAllDeclaredConstructors": true,
2741+
"queryAllPublicConstructors": true,
2742+
"queryAllDeclaredMethods": true,
2743+
"allPublicMethods": true,
2744+
"allDeclaredClasses": true,
2745+
"allPublicClasses": true
2746+
},
2747+
{
2748+
"name": "com.google.spanner.admin.instance.v1.AutoscalingConfig$AsymmetricAutoscalingOption$Builder",
2749+
"queryAllDeclaredConstructors": true,
2750+
"queryAllPublicConstructors": true,
2751+
"queryAllDeclaredMethods": true,
2752+
"allPublicMethods": true,
2753+
"allDeclaredClasses": true,
2754+
"allPublicClasses": true
2755+
},
27202756
{
27212757
"name": "com.google.spanner.admin.instance.v1.AutoscalingConfig$AutoscalingLimits",
27222758
"queryAllDeclaredConstructors": true,
@@ -3338,6 +3374,24 @@
33383374
"allDeclaredClasses": true,
33393375
"allPublicClasses": true
33403376
},
3377+
{
3378+
"name": "com.google.spanner.admin.instance.v1.ReplicaComputeCapacity",
3379+
"queryAllDeclaredConstructors": true,
3380+
"queryAllPublicConstructors": true,
3381+
"queryAllDeclaredMethods": true,
3382+
"allPublicMethods": true,
3383+
"allDeclaredClasses": true,
3384+
"allPublicClasses": true
3385+
},
3386+
{
3387+
"name": "com.google.spanner.admin.instance.v1.ReplicaComputeCapacity$Builder",
3388+
"queryAllDeclaredConstructors": true,
3389+
"queryAllPublicConstructors": true,
3390+
"queryAllDeclaredMethods": true,
3391+
"allPublicMethods": true,
3392+
"allDeclaredClasses": true,
3393+
"allPublicClasses": true
3394+
},
33413395
{
33423396
"name": "com.google.spanner.admin.instance.v1.ReplicaInfo",
33433397
"queryAllDeclaredConstructors": true,
@@ -3365,6 +3419,24 @@
33653419
"allDeclaredClasses": true,
33663420
"allPublicClasses": true
33673421
},
3422+
{
3423+
"name": "com.google.spanner.admin.instance.v1.ReplicaSelection",
3424+
"queryAllDeclaredConstructors": true,
3425+
"queryAllPublicConstructors": true,
3426+
"queryAllDeclaredMethods": true,
3427+
"allPublicMethods": true,
3428+
"allDeclaredClasses": true,
3429+
"allPublicClasses": true
3430+
},
3431+
{
3432+
"name": "com.google.spanner.admin.instance.v1.ReplicaSelection$Builder",
3433+
"queryAllDeclaredConstructors": true,
3434+
"queryAllPublicConstructors": true,
3435+
"queryAllDeclaredMethods": true,
3436+
"allPublicMethods": true,
3437+
"allDeclaredClasses": true,
3438+
"allPublicClasses": true
3439+
},
33683440
{
33693441
"name": "com.google.spanner.admin.instance.v1.UpdateInstanceConfigMetadata",
33703442
"queryAllDeclaredConstructors": true,

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

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
import com.google.cloud.opentelemetry.detection.AttributeKeys;
2929
import com.google.cloud.opentelemetry.detection.DetectedPlatform;
3030
import com.google.cloud.opentelemetry.detection.GCPPlatformDetector;
31+
import com.google.common.hash.HashFunction;
32+
import com.google.common.hash.Hashing;
3133
import io.opentelemetry.api.OpenTelemetry;
3234
import io.opentelemetry.sdk.OpenTelemetrySdk;
3335
import io.opentelemetry.sdk.metrics.SdkMeterProvider;
@@ -83,11 +85,40 @@ Map<String, String> createClientAttributes(String projectId, String client_name)
8385
// TODO: Replace this with real value.
8486
clientAttributes.put(INSTANCE_CONFIG_ID_KEY.getKey(), "unknown");
8587
clientAttributes.put(CLIENT_NAME_KEY.getKey(), client_name);
86-
clientAttributes.put(CLIENT_UID_KEY.getKey(), getDefaultTaskValue());
87-
clientAttributes.put(CLIENT_HASH_KEY.getKey(), "cloud_spanner_client_raw_metrics");
88+
String clientUid = getDefaultTaskValue();
89+
clientAttributes.put(CLIENT_UID_KEY.getKey(), clientUid);
90+
clientAttributes.put(CLIENT_HASH_KEY.getKey(), generateClientHash(clientUid));
8891
return clientAttributes;
8992
}
9093

94+
/**
95+
* Generates a 6-digit zero-padded all lower case hexadecimal representation of hash of the
96+
* accounting group. The hash utilizes the 10 most significant bits of the value returned by
97+
* `Hashing.goodFastHash(64).hashBytes()`, so effectively the returned values are uniformly
98+
* distributed in the range [000000, 0003ff].
99+
*
100+
* <p>The primary purpose of this function is to generate a hash value for the `client_hash`
101+
* resource label using `client_uid` metric field. The range of values is chosen to be small
102+
* enough to keep the cardinality of the Resource targets under control. Note: If at later time
103+
* the range needs to be increased, it can be done by increasing the value of `kPrefixLength` to
104+
* up to 24 bits without changing the format of the returned value.
105+
*
106+
* @return Returns a 6-digit zero-padded all lower case hexadecimal representation of hash of the
107+
* accounting group.
108+
*/
109+
static String generateClientHash(String clientUid) {
110+
if (clientUid == null) {
111+
return "000000";
112+
}
113+
114+
HashFunction hashFunction = Hashing.goodFastHash(64);
115+
Long hash = hashFunction.hashBytes(clientUid.getBytes()).asLong();
116+
// Don't change this value without reading above comment
117+
int kPrefixLength = 10;
118+
long shiftedValue = hash >>> (64 - kPrefixLength);
119+
return String.format("%06x", shiftedValue);
120+
}
121+
91122
static String detectClientLocation() {
92123
GCPPlatformDetector detector = GCPPlatformDetector.DEFAULT_INSTANCE;
93124
DetectedPlatform detectedPlatform = detector.detectPlatform();

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

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1628,6 +1628,42 @@
16281628
"allDeclaredClasses": true,
16291629
"allPublicClasses": true
16301630
},
1631+
{
1632+
"name": "com.google.spanner.admin.instance.v1.AutoscalingConfig$AsymmetricAutoscalingOption",
1633+
"queryAllDeclaredConstructors": true,
1634+
"queryAllPublicConstructors": true,
1635+
"queryAllDeclaredMethods": true,
1636+
"allPublicMethods": true,
1637+
"allDeclaredClasses": true,
1638+
"allPublicClasses": true
1639+
},
1640+
{
1641+
"name": "com.google.spanner.admin.instance.v1.AutoscalingConfig$AsymmetricAutoscalingOption$AutoscalingConfigOverrides",
1642+
"queryAllDeclaredConstructors": true,
1643+
"queryAllPublicConstructors": true,
1644+
"queryAllDeclaredMethods": true,
1645+
"allPublicMethods": true,
1646+
"allDeclaredClasses": true,
1647+
"allPublicClasses": true
1648+
},
1649+
{
1650+
"name": "com.google.spanner.admin.instance.v1.AutoscalingConfig$AsymmetricAutoscalingOption$AutoscalingConfigOverrides$Builder",
1651+
"queryAllDeclaredConstructors": true,
1652+
"queryAllPublicConstructors": true,
1653+
"queryAllDeclaredMethods": true,
1654+
"allPublicMethods": true,
1655+
"allDeclaredClasses": true,
1656+
"allPublicClasses": true
1657+
},
1658+
{
1659+
"name": "com.google.spanner.admin.instance.v1.AutoscalingConfig$AsymmetricAutoscalingOption$Builder",
1660+
"queryAllDeclaredConstructors": true,
1661+
"queryAllPublicConstructors": true,
1662+
"queryAllDeclaredMethods": true,
1663+
"allPublicMethods": true,
1664+
"allDeclaredClasses": true,
1665+
"allPublicClasses": true
1666+
},
16311667
{
16321668
"name": "com.google.spanner.admin.instance.v1.AutoscalingConfig$AutoscalingLimits",
16331669
"queryAllDeclaredConstructors": true,
@@ -2249,6 +2285,24 @@
22492285
"allDeclaredClasses": true,
22502286
"allPublicClasses": true
22512287
},
2288+
{
2289+
"name": "com.google.spanner.admin.instance.v1.ReplicaComputeCapacity",
2290+
"queryAllDeclaredConstructors": true,
2291+
"queryAllPublicConstructors": true,
2292+
"queryAllDeclaredMethods": true,
2293+
"allPublicMethods": true,
2294+
"allDeclaredClasses": true,
2295+
"allPublicClasses": true
2296+
},
2297+
{
2298+
"name": "com.google.spanner.admin.instance.v1.ReplicaComputeCapacity$Builder",
2299+
"queryAllDeclaredConstructors": true,
2300+
"queryAllPublicConstructors": true,
2301+
"queryAllDeclaredMethods": true,
2302+
"allPublicMethods": true,
2303+
"allDeclaredClasses": true,
2304+
"allPublicClasses": true
2305+
},
22522306
{
22532307
"name": "com.google.spanner.admin.instance.v1.ReplicaInfo",
22542308
"queryAllDeclaredConstructors": true,
@@ -2276,6 +2330,24 @@
22762330
"allDeclaredClasses": true,
22772331
"allPublicClasses": true
22782332
},
2333+
{
2334+
"name": "com.google.spanner.admin.instance.v1.ReplicaSelection",
2335+
"queryAllDeclaredConstructors": true,
2336+
"queryAllPublicConstructors": true,
2337+
"queryAllDeclaredMethods": true,
2338+
"allPublicMethods": true,
2339+
"allDeclaredClasses": true,
2340+
"allPublicClasses": true
2341+
},
2342+
{
2343+
"name": "com.google.spanner.admin.instance.v1.ReplicaSelection$Builder",
2344+
"queryAllDeclaredConstructors": true,
2345+
"queryAllPublicConstructors": true,
2346+
"queryAllDeclaredMethods": true,
2347+
"allPublicMethods": true,
2348+
"allDeclaredClasses": true,
2349+
"allPublicClasses": true
2350+
},
22792351
{
22802352
"name": "com.google.spanner.admin.instance.v1.UpdateInstanceConfigMetadata",
22812353
"queryAllDeclaredConstructors": true,
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/*
2+
* Copyright 2024 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 static org.junit.Assert.assertEquals;
20+
import static org.junit.Assert.assertTrue;
21+
22+
import org.junit.Test;
23+
import org.junit.runner.RunWith;
24+
import org.junit.runners.JUnit4;
25+
26+
@RunWith(JUnit4.class)
27+
public class BuiltInOpenTelemetryMetricsProviderTest {
28+
29+
@Test
30+
public void testGenerateClientHashWithSimpleUid() {
31+
String clientUid = "testClient";
32+
verifyHash(BuiltInOpenTelemetryMetricsProvider.generateClientHash(clientUid));
33+
}
34+
35+
@Test
36+
public void testGenerateClientHashWithEmptyUid() {
37+
String clientUid = "";
38+
verifyHash(BuiltInOpenTelemetryMetricsProvider.generateClientHash(clientUid));
39+
}
40+
41+
@Test
42+
public void testGenerateClientHashWithNullUid() {
43+
String clientUid = null;
44+
verifyHash(BuiltInOpenTelemetryMetricsProvider.generateClientHash(clientUid));
45+
}
46+
47+
@Test
48+
public void testGenerateClientHashWithLongUid() {
49+
String clientUid = "aVeryLongUniqueClientIdentifierThatIsUnusuallyLong";
50+
verifyHash(BuiltInOpenTelemetryMetricsProvider.generateClientHash(clientUid));
51+
}
52+
53+
@Test
54+
public void testGenerateClientHashWithSpecialCharacters() {
55+
String clientUid = "273d60f2-5604-42f1-b687-f5f1b975fd07@2316645@test#";
56+
verifyHash(BuiltInOpenTelemetryMetricsProvider.generateClientHash(clientUid));
57+
}
58+
59+
private void verifyHash(String hash) {
60+
// Check if the hash length is 6
61+
assertEquals(hash.length(), 6);
62+
// Check if the hash is in the range [000000, 0003ff]
63+
long hashValue = Long.parseLong(hash, 16); // Convert hash from hex to decimal
64+
assertTrue(hashValue >= 0 && hashValue <= 0x3FF);
65+
}
66+
}

google-cloud-spanner/src/test/java/com/google/cloud/spanner/OpenTelemetryBuiltInMetricsTracerTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ public static void setup() {
9999
BuiltInOpenTelemetryMetricsProvider.detectClientLocation())
100100
.put(BuiltInMetricsConstant.CLIENT_NAME_KEY, client_name)
101101
.put(BuiltInMetricsConstant.CLIENT_UID_KEY, attributes.get("client_uid"))
102-
.put(BuiltInMetricsConstant.CLIENT_HASH_KEY, "cloud_spanner_client_raw_metrics")
102+
.put(BuiltInMetricsConstant.CLIENT_HASH_KEY, attributes.get("client_hash"))
103103
.build();
104104
}
105105

google-cloud-spanner/src/test/java/com/google/cloud/spanner/admin/instance/v1/InstanceAdminClientHttpJsonTest.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@
5959
import com.google.spanner.admin.instance.v1.MoveInstanceRequest;
6060
import com.google.spanner.admin.instance.v1.MoveInstanceResponse;
6161
import com.google.spanner.admin.instance.v1.ProjectName;
62+
import com.google.spanner.admin.instance.v1.ReplicaComputeCapacity;
6263
import com.google.spanner.admin.instance.v1.ReplicaInfo;
6364
import java.io.IOException;
6465
import java.util.ArrayList;
@@ -910,6 +911,7 @@ public void getInstanceTest() throws Exception {
910911
.setDisplayName("displayName1714148973")
911912
.setNodeCount(1539922066)
912913
.setProcessingUnits(-329117885)
914+
.addAllReplicaComputeCapacity(new ArrayList<ReplicaComputeCapacity>())
913915
.setAutoscalingConfig(AutoscalingConfig.newBuilder().build())
914916
.putAllLabels(new HashMap<String, String>())
915917
.addAllEndpointUris(new ArrayList<String>())
@@ -963,6 +965,7 @@ public void getInstanceTest2() throws Exception {
963965
.setDisplayName("displayName1714148973")
964966
.setNodeCount(1539922066)
965967
.setProcessingUnits(-329117885)
968+
.addAllReplicaComputeCapacity(new ArrayList<ReplicaComputeCapacity>())
966969
.setAutoscalingConfig(AutoscalingConfig.newBuilder().build())
967970
.putAllLabels(new HashMap<String, String>())
968971
.addAllEndpointUris(new ArrayList<String>())
@@ -1016,6 +1019,7 @@ public void createInstanceTest() throws Exception {
10161019
.setDisplayName("displayName1714148973")
10171020
.setNodeCount(1539922066)
10181021
.setProcessingUnits(-329117885)
1022+
.addAllReplicaComputeCapacity(new ArrayList<ReplicaComputeCapacity>())
10191023
.setAutoscalingConfig(AutoscalingConfig.newBuilder().build())
10201024
.putAllLabels(new HashMap<String, String>())
10211025
.addAllEndpointUris(new ArrayList<String>())
@@ -1078,6 +1082,7 @@ public void createInstanceTest2() throws Exception {
10781082
.setDisplayName("displayName1714148973")
10791083
.setNodeCount(1539922066)
10801084
.setProcessingUnits(-329117885)
1085+
.addAllReplicaComputeCapacity(new ArrayList<ReplicaComputeCapacity>())
10811086
.setAutoscalingConfig(AutoscalingConfig.newBuilder().build())
10821087
.putAllLabels(new HashMap<String, String>())
10831088
.addAllEndpointUris(new ArrayList<String>())
@@ -1140,6 +1145,7 @@ public void updateInstanceTest() throws Exception {
11401145
.setDisplayName("displayName1714148973")
11411146
.setNodeCount(1539922066)
11421147
.setProcessingUnits(-329117885)
1148+
.addAllReplicaComputeCapacity(new ArrayList<ReplicaComputeCapacity>())
11431149
.setAutoscalingConfig(AutoscalingConfig.newBuilder().build())
11441150
.putAllLabels(new HashMap<String, String>())
11451151
.addAllEndpointUris(new ArrayList<String>())
@@ -1161,6 +1167,7 @@ public void updateInstanceTest() throws Exception {
11611167
.setDisplayName("displayName1714148973")
11621168
.setNodeCount(1539922066)
11631169
.setProcessingUnits(-329117885)
1170+
.addAllReplicaComputeCapacity(new ArrayList<ReplicaComputeCapacity>())
11641171
.setAutoscalingConfig(AutoscalingConfig.newBuilder().build())
11651172
.putAllLabels(new HashMap<String, String>())
11661173
.addAllEndpointUris(new ArrayList<String>())
@@ -1202,6 +1209,7 @@ public void updateInstanceExceptionTest() throws Exception {
12021209
.setDisplayName("displayName1714148973")
12031210
.setNodeCount(1539922066)
12041211
.setProcessingUnits(-329117885)
1212+
.addAllReplicaComputeCapacity(new ArrayList<ReplicaComputeCapacity>())
12051213
.setAutoscalingConfig(AutoscalingConfig.newBuilder().build())
12061214
.putAllLabels(new HashMap<String, String>())
12071215
.addAllEndpointUris(new ArrayList<String>())

0 commit comments

Comments
 (0)