Skip to content

Commit b4e4bfc

Browse files
committed
Merge pull request #28403 from jonatan-ivanov
* gh-28403: Polish "Expose Stackdriver's useSemanticMetricTypes property" Expose Stackdriver's useSemanticMetricTypes property Closes gh-28403
2 parents 4903ce1 + 284725f commit b4e4bfc

File tree

4 files changed

+29
-1
lines changed

4 files changed

+29
-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: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,13 @@ public class StackdriverProperties extends StepRegistryProperties {
4747
*/
4848
private Map<String, String> resourceLabels;
4949

50+
/**
51+
* Whether to use semantically correct metric types. When false, counter metrics are
52+
* published as the GAUGE MetricKind. When true, counter metrics are published as the
53+
* CUMULATIVE MetricKind.
54+
*/
55+
private boolean useSemanticMetricTypes = false;
56+
5057
public String getProjectId() {
5158
return this.projectId;
5259
}
@@ -71,4 +78,12 @@ public void setResourceLabels(Map<String, String> resourceLabels) {
7178
this.resourceLabels = resourceLabels;
7279
}
7380

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

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: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,11 @@ 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+
}
64+
5865
}

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)