Skip to content

Commit 346ebbc

Browse files
committed
Merge branch '3.1.x'
Closes spring-projectsgh-36554
2 parents 53da866 + 5d1b234 commit 346ebbc

File tree

4 files changed

+77
-3
lines changed

4 files changed

+77
-3
lines changed

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

+33-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2022 the original author or authors.
2+
* Copyright 2012-2023 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.
@@ -54,6 +54,11 @@ public class SignalFxProperties extends StepRegistryProperties {
5454
*/
5555
private String source;
5656

57+
/**
58+
* Type of histogram to publish.
59+
*/
60+
private HistogramType publishedHistogramType = HistogramType.DEFAULT;
61+
5762
@Override
5863
public Duration getStep() {
5964
return this.step;
@@ -88,4 +93,31 @@ public void setSource(String source) {
8893
this.source = source;
8994
}
9095

96+
public HistogramType getPublishedHistogramType() {
97+
return this.publishedHistogramType;
98+
}
99+
100+
public void setPublishedHistogramType(HistogramType publishedHistogramType) {
101+
this.publishedHistogramType = publishedHistogramType;
102+
}
103+
104+
public enum HistogramType {
105+
106+
/**
107+
* Default, time-based histogram.
108+
*/
109+
DEFAULT,
110+
111+
/**
112+
* Cumulative histogram.
113+
*/
114+
CUMULATIVE,
115+
116+
/**
117+
* Delta histogram.
118+
*/
119+
DELTA;
120+
121+
}
122+
91123
}

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

+20-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2022 the original author or authors.
2+
* Copyright 2012-2023 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.
@@ -19,6 +19,7 @@
1919
import io.micrometer.signalfx.SignalFxConfig;
2020

2121
import org.springframework.boot.actuate.autoconfigure.metrics.export.properties.StepRegistryPropertiesConfigAdapter;
22+
import org.springframework.boot.actuate.autoconfigure.metrics.export.signalfx.SignalFxProperties.HistogramType;
2223

2324
/**
2425
* Adapter to convert {@link SignalFxProperties} to a {@link SignalFxConfig}.
@@ -54,4 +55,22 @@ public String source() {
5455
return get(SignalFxProperties::getSource, SignalFxConfig.super::source);
5556
}
5657

58+
@Override
59+
public boolean publishCumulativeHistogram() {
60+
return get(this::isPublishCumulativeHistogram, SignalFxConfig.super::publishCumulativeHistogram);
61+
}
62+
63+
private boolean isPublishCumulativeHistogram(SignalFxProperties properties) {
64+
return HistogramType.CUMULATIVE == properties.getPublishedHistogramType();
65+
}
66+
67+
@Override
68+
public boolean publishDeltaHistogram() {
69+
return get(this::isPublishDeltaHistogram, SignalFxConfig.super::publishDeltaHistogram);
70+
}
71+
72+
private boolean isPublishDeltaHistogram(SignalFxProperties properties) {
73+
return HistogramType.DELTA == properties.getPublishedHistogramType();
74+
}
75+
5776
}

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

+17
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import org.junit.jupiter.api.Test;
2020

2121
import org.springframework.boot.actuate.autoconfigure.metrics.export.properties.StepRegistryPropertiesConfigAdapterTests;
22+
import org.springframework.boot.actuate.autoconfigure.metrics.export.signalfx.SignalFxProperties.HistogramType;
2223

2324
import static org.assertj.core.api.Assertions.assertThat;
2425

@@ -62,4 +63,20 @@ void whenPropertiesSourceIsSetAdapterSourceReturnsIt() {
6263
assertThat(createConfigAdapter(properties).source()).isEqualTo("DESKTOP-GA5");
6364
}
6465

66+
@Test
67+
void whenPropertiesPublishHistogramTypeIsCumulativePublishCumulativeHistogramReturnsIt() {
68+
SignalFxProperties properties = createProperties();
69+
properties.setPublishedHistogramType(HistogramType.CUMULATIVE);
70+
assertThat(createConfigAdapter(properties).publishCumulativeHistogram()).isTrue();
71+
assertThat(createConfigAdapter(properties).publishDeltaHistogram()).isFalse();
72+
}
73+
74+
@Test
75+
void whenPropertiesPublishHistogramTypeIsDeltaPublishDeltaHistogramReturnsIt() {
76+
SignalFxProperties properties = createProperties();
77+
properties.setPublishedHistogramType(HistogramType.DELTA);
78+
assertThat(createConfigAdapter(properties).publishDeltaHistogram()).isTrue();
79+
assertThat(createConfigAdapter(properties).publishCumulativeHistogram()).isFalse();
80+
}
81+
6582
}

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

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2019 the original author or authors.
2+
* Copyright 2012-2023 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.
@@ -20,6 +20,7 @@
2020
import org.junit.jupiter.api.Test;
2121

2222
import org.springframework.boot.actuate.autoconfigure.metrics.export.properties.StepRegistryPropertiesTests;
23+
import org.springframework.boot.actuate.autoconfigure.metrics.export.signalfx.SignalFxProperties.HistogramType;
2324

2425
import static org.assertj.core.api.Assertions.assertThat;
2526

@@ -38,6 +39,11 @@ void defaultValuesAreConsistent() {
3839
// access token is mandatory
3940
assertThat(properties.getUri()).isEqualTo(config.uri());
4041
// source has no static default value
42+
// Not publishing cumulative or delta histograms implies that the default
43+
// histogram type should be published.
44+
assertThat(config.publishCumulativeHistogram()).isFalse();
45+
assertThat(config.publishDeltaHistogram()).isFalse();
46+
assertThat(properties.getPublishedHistogramType()).isEqualTo(HistogramType.DEFAULT);
4147
}
4248

4349
}

0 commit comments

Comments
 (0)