From 9397121a98cbb91a74fc04bca6619e6bf7c216e3 Mon Sep 17 00:00:00 2001 From: Jonatan Ivanov Date: Wed, 20 Oct 2021 13:12:53 -0700 Subject: [PATCH 1/2] Expose Stackdriver's useSemanticMetricTypes property See gh-28403 --- .../stackdriver/StackdriverProperties.java | 16 ++++++++++++++++ .../StackdriverPropertiesConfigAdapter.java | 5 +++++ .../StackdriverPropertiesConfigAdapterTests.java | 9 +++++++++ .../stackdriver/StackdriverPropertiesTests.java | 3 ++- 4 files changed, 32 insertions(+), 1 deletion(-) 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 1ff7f48d77dd..298e65cf19c8 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 @@ -47,6 +47,14 @@ public class StackdriverProperties extends StepRegistryProperties { */ private Map resourceLabels; + /** + * Whether to use semantically correct metric types. When this is false, counter + * metrics are published as the GAUGE MetricKind. When this is true, counter metrics + * are published as the CUMULATIVE MetricKind. This is false by default for the sake + * of backwards compatibility. + */ + private boolean useSemanticMetricTypes = false; + public String getProjectId() { return this.projectId; } @@ -71,4 +79,12 @@ public void setResourceLabels(Map resourceLabels) { this.resourceLabels = resourceLabels; } + boolean isUseSemanticMetricTypes() { + return this.useSemanticMetricTypes; + } + + void setUseSemanticMetricTypes(boolean useSemanticMetricTypes) { + this.useSemanticMetricTypes = useSemanticMetricTypes; + } + } 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 7011dd1f1f68..de1ce993cf45 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 @@ -55,4 +55,9 @@ public Map resourceLabels() { return get(StackdriverProperties::getResourceLabels, StackdriverConfig.super::resourceLabels); } + @Override + public boolean useSemanticMetricTypes() { + return get(StackdriverProperties::isUseSemanticMetricTypes, StackdriverConfig.super::useSemanticMetricTypes); + } + } 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 7c7980f05c7d..4f89e9d3dba4 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 @@ -55,4 +55,13 @@ void whenPropertiesResourceLabelsAreSetAdapterResourceLabelsReturnsThem() { .containsExactlyInAnyOrderEntriesOf(labels); } + @Test + void whenPropertiesUseSemanticMetricTypesIsSetAdapterResourceTypeReturnsIt() { + StackdriverProperties properties = new StackdriverProperties(); + properties.setUseSemanticMetricTypes(true); + assertThat(new StackdriverPropertiesConfigAdapter(properties).useSemanticMetricTypes()).isTrue(); + properties.setUseSemanticMetricTypes(false); + assertThat(new StackdriverPropertiesConfigAdapter(properties).useSemanticMetricTypes()).isFalse(); + } + } 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 e612fa2a7c3f..103344d4617c 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-2020 the original author or authors. + * Copyright 2012-2021 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. @@ -36,6 +36,7 @@ void defaultValuesAreConsistent() { StackdriverConfig config = (key) -> null; assertStepRegistryDefaultValues(properties, config); assertThat(properties.getResourceType()).isEqualTo(config.resourceType()); + assertThat(properties.isUseSemanticMetricTypes()).isEqualTo(config.useSemanticMetricTypes()); } } From 284725f5becb38866eddcd7128cab59c7cb17583 Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Thu, 21 Oct 2021 17:57:23 +0100 Subject: [PATCH 2/2] Polish "Expose Stackdriver's useSemanticMetricTypes property" See gh-28403 --- .../metrics/export/stackdriver/StackdriverProperties.java | 7 +++---- .../StackdriverPropertiesConfigAdapterTests.java | 2 -- 2 files changed, 3 insertions(+), 6 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 298e65cf19c8..e1121e9289a4 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 @@ -48,10 +48,9 @@ public class StackdriverProperties extends StepRegistryProperties { private Map resourceLabels; /** - * Whether to use semantically correct metric types. When this is false, counter - * metrics are published as the GAUGE MetricKind. When this is true, counter metrics - * are published as the CUMULATIVE MetricKind. This is false by default for the sake - * of backwards compatibility. + * Whether to use semantically correct metric types. When false, counter metrics are + * published as the GAUGE MetricKind. When true, counter metrics are published as the + * CUMULATIVE MetricKind. */ private boolean useSemanticMetricTypes = false; 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 4f89e9d3dba4..d04b5410af15 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 @@ -60,8 +60,6 @@ void whenPropertiesUseSemanticMetricTypesIsSetAdapterResourceTypeReturnsIt() { StackdriverProperties properties = new StackdriverProperties(); properties.setUseSemanticMetricTypes(true); assertThat(new StackdriverPropertiesConfigAdapter(properties).useSemanticMetricTypes()).isTrue(); - properties.setUseSemanticMetricTypes(false); - assertThat(new StackdriverPropertiesConfigAdapter(properties).useSemanticMetricTypes()).isFalse(); } }