Skip to content

Commit 9397121

Browse files
jonatan-ivanovwilkinsona
authored andcommitted
Expose Stackdriver's useSemanticMetricTypes property
See gh-28403
1 parent 4903ce1 commit 9397121

File tree

4 files changed

+32
-1
lines changed

4 files changed

+32
-1
lines changed

spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/stackdriver/StackdriverProperties.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,14 @@ public class StackdriverProperties extends StepRegistryProperties {
4747
*/
4848
private Map<String, String> resourceLabels;
4949

50+
/**
51+
* Whether to use semantically correct metric types. When this is false, counter
52+
* metrics are published as the GAUGE MetricKind. When this is true, counter metrics
53+
* are published as the CUMULATIVE MetricKind. This is false by default for the sake
54+
* of backwards compatibility.
55+
*/
56+
private boolean useSemanticMetricTypes = false;
57+
5058
public String getProjectId() {
5159
return this.projectId;
5260
}
@@ -71,4 +79,12 @@ public void setResourceLabels(Map<String, String> resourceLabels) {
7179
this.resourceLabels = resourceLabels;
7280
}
7381

82+
boolean isUseSemanticMetricTypes() {
83+
return this.useSemanticMetricTypes;
84+
}
85+
86+
void setUseSemanticMetricTypes(boolean useSemanticMetricTypes) {
87+
this.useSemanticMetricTypes = useSemanticMetricTypes;
88+
}
89+
7490
}

spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/metrics/export/stackdriver/StackdriverPropertiesConfigAdapter.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,9 @@ public Map<String, String> resourceLabels() {
5555
return get(StackdriverProperties::getResourceLabels, StackdriverConfig.super::resourceLabels);
5656
}
5757

58+
@Override
59+
public boolean useSemanticMetricTypes() {
60+
return get(StackdriverProperties::isUseSemanticMetricTypes, StackdriverConfig.super::useSemanticMetricTypes);
61+
}
62+
5863
}

spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/stackdriver/StackdriverPropertiesConfigAdapterTests.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,13 @@ void whenPropertiesResourceLabelsAreSetAdapterResourceLabelsReturnsThem() {
5555
.containsExactlyInAnyOrderEntriesOf(labels);
5656
}
5757

58+
@Test
59+
void whenPropertiesUseSemanticMetricTypesIsSetAdapterResourceTypeReturnsIt() {
60+
StackdriverProperties properties = new StackdriverProperties();
61+
properties.setUseSemanticMetricTypes(true);
62+
assertThat(new StackdriverPropertiesConfigAdapter(properties).useSemanticMetricTypes()).isTrue();
63+
properties.setUseSemanticMetricTypes(false);
64+
assertThat(new StackdriverPropertiesConfigAdapter(properties).useSemanticMetricTypes()).isFalse();
65+
}
66+
5867
}

spring-boot-project/spring-boot-actuator-autoconfigure/src/test/java/org/springframework/boot/actuate/autoconfigure/metrics/export/stackdriver/StackdriverPropertiesTests.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2020 the original author or authors.
2+
* Copyright 2012-2021 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -36,6 +36,7 @@ void defaultValuesAreConsistent() {
3636
StackdriverConfig config = (key) -> null;
3737
assertStepRegistryDefaultValues(properties, config);
3838
assertThat(properties.getResourceType()).isEqualTo(config.resourceType());
39+
assertThat(properties.isUseSemanticMetricTypes()).isEqualTo(config.useSemanticMetricTypes());
3940
}
4041

4142
}

0 commit comments

Comments
 (0)