Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: built-in metrics attributes #3346

Merged
merged 1 commit into from
Sep 27, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,16 @@ public class BuiltInMetricsConstant {
public static final AttributeKey<String> LOCATION_ID_KEY = AttributeKey.stringKey("location");
public static final AttributeKey<String> INSTANCE_CONFIG_ID_KEY =
AttributeKey.stringKey("instance_config");
public static final AttributeKey<String> CLIENT_HASH_KEY = AttributeKey.stringKey("client_hash");

// These metric labels will be promoted to the spanner monitored resource fields
public static final Set<AttributeKey<String>> SPANNER_PROMOTED_RESOURCE_LABELS =
ImmutableSet.of(PROJECT_ID_KEY, INSTANCE_ID_KEY, INSTANCE_CONFIG_ID_KEY, LOCATION_ID_KEY);
ImmutableSet.of(
PROJECT_ID_KEY,
INSTANCE_ID_KEY,
INSTANCE_CONFIG_ID_KEY,
LOCATION_ID_KEY,
CLIENT_HASH_KEY);

public static final AttributeKey<String> DATABASE_KEY = AttributeKey.stringKey("database");
public static final AttributeKey<String> CLIENT_UID_KEY = AttributeKey.stringKey("client_uid");
Expand All @@ -87,6 +93,7 @@ public class BuiltInMetricsConstant {
LOCATION_ID_KEY,
INSTANCE_CONFIG_ID_KEY,
CLIENT_UID_KEY,
CLIENT_HASH_KEY,
METHOD_KEY,
STATUS_KEY,
DATABASE_KEY,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
package com.google.cloud.spanner;

import static com.google.cloud.opentelemetry.detection.GCPPlatformDetector.SupportedPlatform.GOOGLE_KUBERNETES_ENGINE;
import static com.google.cloud.spanner.BuiltInMetricsConstant.CLIENT_HASH_KEY;
import static com.google.cloud.spanner.BuiltInMetricsConstant.CLIENT_NAME_KEY;
import static com.google.cloud.spanner.BuiltInMetricsConstant.CLIENT_UID_KEY;
import static com.google.cloud.spanner.BuiltInMetricsConstant.INSTANCE_CONFIG_ID_KEY;
Expand Down Expand Up @@ -83,6 +84,7 @@ Map<String, String> createClientAttributes(String projectId, String client_name)
clientAttributes.put(INSTANCE_CONFIG_ID_KEY.getKey(), "unknown");
clientAttributes.put(CLIENT_NAME_KEY.getKey(), client_name);
clientAttributes.put(CLIENT_UID_KEY.getKey(), getDefaultTaskValue());
clientAttributes.put(CLIENT_HASH_KEY.getKey(), "cloud_spanner_client_raw_metrics");
return clientAttributes;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ public static void setup() {
BuiltInOpenTelemetryMetricsProvider.detectClientLocation())
.put(BuiltInMetricsConstant.CLIENT_NAME_KEY, client_name)
.put(BuiltInMetricsConstant.CLIENT_UID_KEY, attributes.get("client_uid"))
.put(BuiltInMetricsConstant.CLIENT_HASH_KEY, "cloud_spanner_client_raw_metrics")
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package com.google.cloud.spanner;

import static com.google.cloud.spanner.BuiltInMetricsConstant.CLIENT_HASH_KEY;
import static com.google.cloud.spanner.BuiltInMetricsConstant.CLIENT_NAME_KEY;
import static com.google.cloud.spanner.BuiltInMetricsConstant.CLIENT_UID_KEY;
import static com.google.cloud.spanner.BuiltInMetricsConstant.DATABASE_KEY;
Expand Down Expand Up @@ -76,6 +77,8 @@ public class SpannerCloudMonitoringExporterTest {
private static final String locationId = "global";
private static final String databaseId = "fake-database";
private static final String clientName = "spanner-java";

private static final String clientHash = "spanner-test";
private static final String instanceConfigId = "fake-instance-config-id";

@Rule public final MockitoRule mockitoRule = MockitoJUnit.rule();
Expand All @@ -101,6 +104,7 @@ public void setUp() {
.put(INSTANCE_CONFIG_ID_KEY, instanceConfigId)
.put(DATABASE_KEY, databaseId)
.put(CLIENT_NAME_KEY, clientName)
.put(CLIENT_HASH_KEY, clientHash)
.put(String.valueOf(DIRECT_PATH_ENABLED_KEY), true)
.put(String.valueOf(DIRECT_PATH_USED_KEY), true)
.build();
Expand Down Expand Up @@ -153,9 +157,10 @@ public void testExportingSumData() {
PROJECT_ID_KEY.getKey(), projectId,
INSTANCE_ID_KEY.getKey(), instanceId,
LOCATION_ID_KEY.getKey(), locationId,
INSTANCE_CONFIG_ID_KEY.getKey(), instanceConfigId);
INSTANCE_CONFIG_ID_KEY.getKey(), instanceConfigId,
CLIENT_HASH_KEY.getKey(), clientHash);

assertThat(timeSeries.getResource().getLabelsMap()).hasSize(4);
assertThat(timeSeries.getResource().getLabelsMap()).hasSize(5);

assertThat(timeSeries.getMetric().getLabelsMap())
.containsExactly(
Expand Down Expand Up @@ -218,13 +223,14 @@ public void testExportingHistogramData() {

TimeSeries timeSeries = request.getTimeSeriesList().get(0);

assertThat(timeSeries.getResource().getLabelsMap()).hasSize(4);
assertThat(timeSeries.getResource().getLabelsMap()).hasSize(5);
assertThat(timeSeries.getResource().getLabelsMap())
.containsExactly(
PROJECT_ID_KEY.getKey(), projectId,
INSTANCE_ID_KEY.getKey(), instanceId,
LOCATION_ID_KEY.getKey(), locationId,
INSTANCE_CONFIG_ID_KEY.getKey(), instanceConfigId);
INSTANCE_CONFIG_ID_KEY.getKey(), instanceConfigId,
CLIENT_HASH_KEY.getKey(), clientHash);

assertThat(timeSeries.getMetric().getLabelsMap()).hasSize(4);
assertThat(timeSeries.getMetric().getLabelsMap())
Expand Down Expand Up @@ -296,13 +302,14 @@ public void testExportingSumDataInBatches() {
timeSeries = secondRequest.getTimeSeriesList().get(i - 200);
}

assertThat(timeSeries.getResource().getLabelsMap()).hasSize(4);
assertThat(timeSeries.getResource().getLabelsMap()).hasSize(5);
assertThat(timeSeries.getResource().getLabelsMap())
.containsExactly(
PROJECT_ID_KEY.getKey(), projectId,
INSTANCE_ID_KEY.getKey(), instanceId,
LOCATION_ID_KEY.getKey(), locationId,
INSTANCE_CONFIG_ID_KEY.getKey(), instanceConfigId);
INSTANCE_CONFIG_ID_KEY.getKey(), instanceConfigId,
CLIENT_HASH_KEY.getKey(), clientHash);

assertThat(timeSeries.getMetric().getLabelsMap()).hasSize(5);
assertThat(timeSeries.getMetric().getLabelsMap())
Expand Down
Loading