-
Notifications
You must be signed in to change notification settings - Fork 123
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: Add client_hash metric attribute (#3357)
* chore: Add client_hash metric attribute * review comments
- Loading branch information
1 parent
f910f70
commit 438f837
Showing
3 changed files
with
100 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
...anner/src/test/java/com/google/cloud/spanner/BuiltInOpenTelemetryMetricsProviderTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/* | ||
* Copyright 2024 Google LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.google.cloud.spanner; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertTrue; | ||
|
||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.junit.runners.JUnit4; | ||
|
||
@RunWith(JUnit4.class) | ||
public class BuiltInOpenTelemetryMetricsProviderTest { | ||
|
||
@Test | ||
public void testGenerateClientHashWithSimpleUid() { | ||
String clientUid = "testClient"; | ||
verifyHash(BuiltInOpenTelemetryMetricsProvider.generateClientHash(clientUid)); | ||
} | ||
|
||
@Test | ||
public void testGenerateClientHashWithEmptyUid() { | ||
String clientUid = ""; | ||
verifyHash(BuiltInOpenTelemetryMetricsProvider.generateClientHash(clientUid)); | ||
} | ||
|
||
@Test | ||
public void testGenerateClientHashWithNullUid() { | ||
String clientUid = null; | ||
verifyHash(BuiltInOpenTelemetryMetricsProvider.generateClientHash(clientUid)); | ||
} | ||
|
||
@Test | ||
public void testGenerateClientHashWithLongUid() { | ||
String clientUid = "aVeryLongUniqueClientIdentifierThatIsUnusuallyLong"; | ||
verifyHash(BuiltInOpenTelemetryMetricsProvider.generateClientHash(clientUid)); | ||
} | ||
|
||
@Test | ||
public void testGenerateClientHashWithSpecialCharacters() { | ||
String clientUid = "273d60f2-5604-42f1-b687-f5f1b975fd07@2316645@test#"; | ||
verifyHash(BuiltInOpenTelemetryMetricsProvider.generateClientHash(clientUid)); | ||
} | ||
|
||
private void verifyHash(String hash) { | ||
// Check if the hash length is 6 | ||
assertEquals(hash.length(), 6); | ||
// Check if the hash is in the range [000000, 0003ff] | ||
long hashValue = Long.parseLong(hash, 16); // Convert hash from hex to decimal | ||
assertTrue(hashValue >= 0 && hashValue <= 0x3FF); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters