From d290d05f63712bafe273e0c510bb0c9976f7f25f Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Mon, 24 Jul 2023 11:57:21 +0100 Subject: [PATCH] Add missing Stackdriver metric-type-prefix property Closes gh-36499 --- .../stackdriver/StackdriverProperties.java | 16 +++++++++++++++- .../StackdriverPropertiesConfigAdapter.java | 7 ++++++- .../StackdriverPropertiesConfigAdapterTests.java | 8 ++++++++ .../stackdriver/StackdriverPropertiesTests.java | 3 ++- 4 files changed, 31 insertions(+), 3 deletions(-) diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/stackdriver/StackdriverProperties.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/stackdriver/StackdriverProperties.java index b16b83f81a..4557f3f539 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/stackdriver/StackdriverProperties.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/stackdriver/StackdriverProperties.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2022 the original author or authors. + * Copyright 2012-2023 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -54,6 +54,12 @@ public class StackdriverProperties extends StepRegistryProperties { */ private boolean useSemanticMetricTypes = false; + /** + * Prefix for metric type. Valid prefixes are described in the Google Cloud + * documentation (https://cloud.google.com/monitoring/custom-metrics#identifier). + */ + private String metricTypePrefix = "custom.googleapis.com/"; + public String getProjectId() { return this.projectId; } @@ -86,4 +92,12 @@ public class StackdriverProperties extends StepRegistryProperties { this.useSemanticMetricTypes = useSemanticMetricTypes; } + public String getMetricTypePrefix() { + return this.metricTypePrefix; + } + + public void setMetricTypePrefix(String metricTypePrefix) { + this.metricTypePrefix = metricTypePrefix; + } + } diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/stackdriver/StackdriverPropertiesConfigAdapter.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/stackdriver/StackdriverPropertiesConfigAdapter.java index e762b6da87..b4334c7414 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/stackdriver/StackdriverPropertiesConfigAdapter.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/stackdriver/StackdriverPropertiesConfigAdapter.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2022 the original author or authors. + * Copyright 2012-2023 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -60,4 +60,9 @@ public class StackdriverPropertiesConfigAdapter extends StepRegistryPropertiesCo return get(StackdriverProperties::isUseSemanticMetricTypes, StackdriverConfig.super::useSemanticMetricTypes); } + @Override + public String metricTypePrefix() { + return get(StackdriverProperties::getMetricTypePrefix, StackdriverConfig.super::metricTypePrefix); + } + } diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/stackdriver/StackdriverPropertiesConfigAdapterTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/stackdriver/StackdriverPropertiesConfigAdapterTests.java index 9b2f2fe964..5fa7d7093f 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/stackdriver/StackdriverPropertiesConfigAdapterTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/stackdriver/StackdriverPropertiesConfigAdapterTests.java @@ -62,4 +62,12 @@ class StackdriverPropertiesConfigAdapterTests { assertThat(new StackdriverPropertiesConfigAdapter(properties).useSemanticMetricTypes()).isTrue(); } + @Test + void whenPropertiesMetricTypePrefixIsSetAdapterMetricTypePrefixReturnsIt() { + StackdriverProperties properties = new StackdriverProperties(); + properties.setMetricTypePrefix("external.googleapis.com/prometheus"); + assertThat(new StackdriverPropertiesConfigAdapter(properties).metricTypePrefix()) + .isEqualTo("external.googleapis.com/prometheus"); + } + } diff --git a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/stackdriver/StackdriverPropertiesTests.java b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/stackdriver/StackdriverPropertiesTests.java index 103344d461..20031fce87 100644 --- a/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/stackdriver/StackdriverPropertiesTests.java +++ b/spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/stackdriver/StackdriverPropertiesTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2021 the original author or authors. + * Copyright 2012-2023 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -37,6 +37,7 @@ class StackdriverPropertiesTests extends StepRegistryPropertiesTests { assertStepRegistryDefaultValues(properties, config); assertThat(properties.getResourceType()).isEqualTo(config.resourceType()); assertThat(properties.isUseSemanticMetricTypes()).isEqualTo(config.useSemanticMetricTypes()); + assertThat(properties.getMetricTypePrefix()).isEqualTo(config.metricTypePrefix()); } }