Skip to content

Commit 2da9dd5

Browse files
committed
use openmetrics2 and remove unneeded config
Signed-off-by: Jay DeLuca <[email protected]>
1 parent ec60b58 commit 2da9dd5

3 files changed

Lines changed: 27 additions & 76 deletions

File tree

prometheus-metrics-config/src/main/java/io/prometheus/metrics/config/OpenMetrics2Properties.java

Lines changed: 7 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -2,30 +2,29 @@
22

33
import javax.annotation.Nullable;
44

5-
/** Properties starting with io.prometheus.open_metrics2 */
5+
/**
6+
* Properties starting with io.prometheus.openmetrics2. These properties are experimental and
7+
* subject to change.
8+
*/
69
public class OpenMetrics2Properties {
710

8-
private static final String PREFIX = "io.prometheus.open_metrics2";
11+
private static final String PREFIX = "io.prometheus.openmetrics2";
912
private static final String CONTENT_NEGOTIATION = "content_negotiation";
10-
private static final String DISABLE_SUFFIX_APPENDING = "disable_suffix_appending";
1113
private static final String COMPOSITE_VALUES = "composite_values";
1214
private static final String EXEMPLAR_COMPLIANCE = "exemplar_compliance";
1315
private static final String NATIVE_HISTOGRAMS = "native_histograms";
1416

1517
@Nullable private final Boolean contentNegotiation;
16-
@Nullable private final Boolean disableSuffixAppending;
1718
@Nullable private final Boolean compositeValues;
1819
@Nullable private final Boolean exemplarCompliance;
1920
@Nullable private final Boolean nativeHistograms;
2021

2122
private OpenMetrics2Properties(
2223
@Nullable Boolean contentNegotiation,
23-
@Nullable Boolean disableSuffixAppending,
2424
@Nullable Boolean compositeValues,
2525
@Nullable Boolean exemplarCompliance,
2626
@Nullable Boolean nativeHistograms) {
2727
this.contentNegotiation = contentNegotiation;
28-
this.disableSuffixAppending = disableSuffixAppending;
2928
this.compositeValues = compositeValues;
3029
this.exemplarCompliance = exemplarCompliance;
3130
this.nativeHistograms = nativeHistograms;
@@ -36,11 +35,6 @@ public boolean getContentNegotiation() {
3635
return contentNegotiation != null && contentNegotiation;
3736
}
3837

39-
/** Suppress {@code _total} and unit suffixes. Default is {@code false}. */
40-
public boolean getDisableSuffixAppending() {
41-
return disableSuffixAppending != null && disableSuffixAppending;
42-
}
43-
4438
/** Single-line histogram/summary with {@code st@}. Default is {@code false}. */
4539
public boolean getCompositeValues() {
4640
return compositeValues != null && compositeValues;
@@ -63,17 +57,11 @@ public boolean getNativeHistograms() {
6357
static OpenMetrics2Properties load(PropertySource propertySource)
6458
throws PrometheusPropertiesException {
6559
Boolean contentNegotiation = Util.loadBoolean(PREFIX, CONTENT_NEGOTIATION, propertySource);
66-
Boolean disableSuffixAppending =
67-
Util.loadBoolean(PREFIX, DISABLE_SUFFIX_APPENDING, propertySource);
6860
Boolean compositeValues = Util.loadBoolean(PREFIX, COMPOSITE_VALUES, propertySource);
6961
Boolean exemplarCompliance = Util.loadBoolean(PREFIX, EXEMPLAR_COMPLIANCE, propertySource);
7062
Boolean nativeHistograms = Util.loadBoolean(PREFIX, NATIVE_HISTOGRAMS, propertySource);
7163
return new OpenMetrics2Properties(
72-
contentNegotiation,
73-
disableSuffixAppending,
74-
compositeValues,
75-
exemplarCompliance,
76-
nativeHistograms);
64+
contentNegotiation, compositeValues, exemplarCompliance, nativeHistograms);
7765
}
7866

7967
public static Builder builder() {
@@ -83,7 +71,6 @@ public static Builder builder() {
8371
public static class Builder {
8472

8573
@Nullable private Boolean contentNegotiation;
86-
@Nullable private Boolean disableSuffixAppending;
8774
@Nullable private Boolean compositeValues;
8875
@Nullable private Boolean exemplarCompliance;
8976
@Nullable private Boolean nativeHistograms;
@@ -96,12 +83,6 @@ public Builder contentNegotiation(boolean contentNegotiation) {
9683
return this;
9784
}
9885

99-
/** See {@link #getDisableSuffixAppending()} */
100-
public Builder disableSuffixAppending(boolean disableSuffixAppending) {
101-
this.disableSuffixAppending = disableSuffixAppending;
102-
return this;
103-
}
104-
10586
/** See {@link #getCompositeValues()} */
10687
public Builder compositeValues(boolean compositeValues) {
10788
this.compositeValues = compositeValues;
@@ -123,7 +104,6 @@ public Builder nativeHistograms(boolean nativeHistograms) {
123104
/** Enable all OpenMetrics 2.0 features */
124105
public Builder enableAll() {
125106
this.contentNegotiation = true;
126-
this.disableSuffixAppending = true;
127107
this.compositeValues = true;
128108
this.exemplarCompliance = true;
129109
this.nativeHistograms = true;
@@ -132,11 +112,7 @@ public Builder enableAll() {
132112

133113
public OpenMetrics2Properties build() {
134114
return new OpenMetrics2Properties(
135-
contentNegotiation,
136-
disableSuffixAppending,
137-
compositeValues,
138-
exemplarCompliance,
139-
nativeHistograms);
115+
contentNegotiation, compositeValues, exemplarCompliance, nativeHistograms);
140116
}
141117
}
142118
}

prometheus-metrics-config/src/test/java/io/prometheus/metrics/config/OpenMetrics2PropertiesTest.java

Lines changed: 12 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,15 @@ void load() {
1515
load(
1616
new HashMap<>(
1717
Map.of(
18-
"io.prometheus.open_metrics2.content_negotiation",
18+
"io.prometheus.openmetrics2.content_negotiation",
1919
"true",
20-
"io.prometheus.open_metrics2.disable_suffix_appending",
20+
"io.prometheus.openmetrics2.composite_values",
2121
"true",
22-
"io.prometheus.open_metrics2.composite_values",
22+
"io.prometheus.openmetrics2.exemplar_compliance",
2323
"true",
24-
"io.prometheus.open_metrics2.exemplar_compliance",
25-
"true",
26-
"io.prometheus.open_metrics2.native_histograms",
24+
"io.prometheus.openmetrics2.native_histograms",
2725
"true")));
2826
assertThat(properties.getContentNegotiation()).isTrue();
29-
assertThat(properties.getDisableSuffixAppending()).isTrue();
3027
assertThat(properties.getCompositeValues()).isTrue();
3128
assertThat(properties.getExemplarCompliance()).isTrue();
3229
assertThat(properties.getNativeHistograms()).isTrue();
@@ -39,45 +36,36 @@ void loadInvalidValue() {
3936
() ->
4037
load(
4138
new HashMap<>(
42-
Map.of("io.prometheus.open_metrics2.content_negotiation", "invalid"))))
39+
Map.of("io.prometheus.openmetrics2.content_negotiation", "invalid"))))
4340
.withMessage(
44-
"io.prometheus.open_metrics2.content_negotiation: Expecting 'true' or 'false'. Found:"
41+
"io.prometheus.openmetrics2.content_negotiation: Expecting 'true' or 'false'. Found:"
4542
+ " invalid");
4643
assertThatExceptionOfType(PrometheusPropertiesException.class)
4744
.isThrownBy(
4845
() ->
4946
load(
5047
new HashMap<>(
51-
Map.of("io.prometheus.open_metrics2.disable_suffix_appending", "invalid"))))
52-
.withMessage(
53-
"io.prometheus.open_metrics2.disable_suffix_appending: Expecting 'true' or 'false'."
54-
+ " Found: invalid");
55-
assertThatExceptionOfType(PrometheusPropertiesException.class)
56-
.isThrownBy(
57-
() ->
58-
load(
59-
new HashMap<>(
60-
Map.of("io.prometheus.open_metrics2.composite_values", "invalid"))))
48+
Map.of("io.prometheus.openmetrics2.composite_values", "invalid"))))
6149
.withMessage(
62-
"io.prometheus.open_metrics2.composite_values: Expecting 'true' or 'false'. Found:"
50+
"io.prometheus.openmetrics2.composite_values: Expecting 'true' or 'false'. Found:"
6351
+ " invalid");
6452
assertThatExceptionOfType(PrometheusPropertiesException.class)
6553
.isThrownBy(
6654
() ->
6755
load(
6856
new HashMap<>(
69-
Map.of("io.prometheus.open_metrics2.exemplar_compliance", "invalid"))))
57+
Map.of("io.prometheus.openmetrics2.exemplar_compliance", "invalid"))))
7058
.withMessage(
71-
"io.prometheus.open_metrics2.exemplar_compliance: Expecting 'true' or 'false'. Found:"
59+
"io.prometheus.openmetrics2.exemplar_compliance: Expecting 'true' or 'false'. Found:"
7260
+ " invalid");
7361
assertThatExceptionOfType(PrometheusPropertiesException.class)
7462
.isThrownBy(
7563
() ->
7664
load(
7765
new HashMap<>(
78-
Map.of("io.prometheus.open_metrics2.native_histograms", "invalid"))))
66+
Map.of("io.prometheus.openmetrics2.native_histograms", "invalid"))))
7967
.withMessage(
80-
"io.prometheus.open_metrics2.native_histograms: Expecting 'true' or 'false'. Found:"
68+
"io.prometheus.openmetrics2.native_histograms: Expecting 'true' or 'false'. Found:"
8169
+ " invalid");
8270
}
8371

@@ -92,13 +80,11 @@ void builder() {
9280
OpenMetrics2Properties properties =
9381
OpenMetrics2Properties.builder()
9482
.contentNegotiation(true)
95-
.disableSuffixAppending(true)
9683
.compositeValues(false)
9784
.exemplarCompliance(true)
9885
.nativeHistograms(false)
9986
.build();
10087
assertThat(properties.getContentNegotiation()).isTrue();
101-
assertThat(properties.getDisableSuffixAppending()).isTrue();
10288
assertThat(properties.getCompositeValues()).isFalse();
10389
assertThat(properties.getExemplarCompliance()).isTrue();
10490
assertThat(properties.getNativeHistograms()).isFalse();
@@ -108,7 +94,6 @@ void builder() {
10894
void builderEnableAll() {
10995
OpenMetrics2Properties properties = OpenMetrics2Properties.builder().enableAll().build();
11096
assertThat(properties.getContentNegotiation()).isTrue();
111-
assertThat(properties.getDisableSuffixAppending()).isTrue();
11297
assertThat(properties.getCompositeValues()).isTrue();
11398
assertThat(properties.getExemplarCompliance()).isTrue();
11499
assertThat(properties.getNativeHistograms()).isTrue();
@@ -118,7 +103,6 @@ void builderEnableAll() {
118103
void defaultValues() {
119104
OpenMetrics2Properties properties = OpenMetrics2Properties.builder().build();
120105
assertThat(properties.getContentNegotiation()).isFalse();
121-
assertThat(properties.getDisableSuffixAppending()).isFalse();
122106
assertThat(properties.getCompositeValues()).isFalse();
123107
assertThat(properties.getExemplarCompliance()).isFalse();
124108
assertThat(properties.getNativeHistograms()).isFalse();
@@ -129,7 +113,6 @@ void partialConfiguration() {
129113
OpenMetrics2Properties properties =
130114
OpenMetrics2Properties.builder().contentNegotiation(true).compositeValues(true).build();
131115
assertThat(properties.getContentNegotiation()).isTrue();
132-
assertThat(properties.getDisableSuffixAppending()).isFalse();
133116
assertThat(properties.getCompositeValues()).isTrue();
134117
assertThat(properties.getExemplarCompliance()).isFalse();
135118
assertThat(properties.getNativeHistograms()).isFalse();

prometheus-metrics-config/src/test/java/io/prometheus/metrics/config/PrometheusPropertiesTest.java

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -133,14 +133,9 @@ void testMetricNameStartingWithNumber() {
133133
void testOpenMetrics2ConsumerPattern() {
134134
PrometheusProperties config =
135135
PrometheusProperties.builder()
136-
.enableOpenMetrics2(
137-
om2 ->
138-
om2.contentNegotiation(true)
139-
.disableSuffixAppending(true)
140-
.compositeValues(false))
136+
.enableOpenMetrics2(om2 -> om2.contentNegotiation(true).compositeValues(false))
141137
.build();
142138
assertThat(config.getOpenMetrics2Properties().getContentNegotiation()).isTrue();
143-
assertThat(config.getOpenMetrics2Properties().getDisableSuffixAppending()).isTrue();
144139
assertThat(config.getOpenMetrics2Properties().getCompositeValues()).isFalse();
145140
assertThat(config.getOpenMetrics2Properties().getExemplarCompliance()).isFalse();
146141
assertThat(config.getOpenMetrics2Properties().getNativeHistograms()).isFalse();
@@ -149,9 +144,10 @@ void testOpenMetrics2ConsumerPattern() {
149144
@Test
150145
void testOpenMetrics2EnableAll() {
151146
PrometheusProperties config =
152-
PrometheusProperties.builder().enableOpenMetrics2(om2 -> om2.enableAll()).build();
147+
PrometheusProperties.builder()
148+
.enableOpenMetrics2(OpenMetrics2Properties.Builder::enableAll)
149+
.build();
153150
assertThat(config.getOpenMetrics2Properties().getContentNegotiation()).isTrue();
154-
assertThat(config.getOpenMetrics2Properties().getDisableSuffixAppending()).isTrue();
155151
assertThat(config.getOpenMetrics2Properties().getCompositeValues()).isTrue();
156152
assertThat(config.getOpenMetrics2Properties().getExemplarCompliance()).isTrue();
157153
assertThat(config.getOpenMetrics2Properties().getNativeHistograms()).isTrue();
@@ -164,7 +160,6 @@ void testOpenMetrics2DirectAssignment() {
164160
PrometheusProperties config =
165161
PrometheusProperties.builder().openMetrics2Properties(om2Props).build();
166162
assertThat(config.getOpenMetrics2Properties().getContentNegotiation()).isTrue();
167-
assertThat(config.getOpenMetrics2Properties().getDisableSuffixAppending()).isFalse();
168163
assertThat(config.getOpenMetrics2Properties().getCompositeValues()).isFalse();
169164
assertThat(config.getOpenMetrics2Properties().getExemplarCompliance()).isFalse();
170165
assertThat(config.getOpenMetrics2Properties().getNativeHistograms()).isTrue();
@@ -174,7 +169,6 @@ void testOpenMetrics2DirectAssignment() {
174169
void testOpenMetrics2Defaults() {
175170
PrometheusProperties config = PrometheusProperties.builder().build();
176171
assertThat(config.getOpenMetrics2Properties().getContentNegotiation()).isFalse();
177-
assertThat(config.getOpenMetrics2Properties().getDisableSuffixAppending()).isFalse();
178172
assertThat(config.getOpenMetrics2Properties().getCompositeValues()).isFalse();
179173
assertThat(config.getOpenMetrics2Properties().getExemplarCompliance()).isFalse();
180174
assertThat(config.getOpenMetrics2Properties().getNativeHistograms()).isFalse();
@@ -183,14 +177,12 @@ void testOpenMetrics2Defaults() {
183177
@Test
184178
void testOpenMetrics2PropertiesLoading() {
185179
Map<Object, Object> properties = new HashMap<>();
186-
properties.put("io.prometheus.open_metrics2.content_negotiation", "true");
187-
properties.put("io.prometheus.open_metrics2.disable_suffix_appending", "true");
188-
properties.put("io.prometheus.open_metrics2.composite_values", "false");
189-
properties.put("io.prometheus.open_metrics2.exemplar_compliance", "true");
190-
properties.put("io.prometheus.open_metrics2.native_histograms", "false");
180+
properties.put("io.prometheus.openmetrics2.content_negotiation", "true");
181+
properties.put("io.prometheus.openmetrics2.composite_values", "false");
182+
properties.put("io.prometheus.openmetrics2.exemplar_compliance", "true");
183+
properties.put("io.prometheus.openmetrics2.native_histograms", "false");
191184
PrometheusProperties config = PrometheusPropertiesLoader.load(properties);
192185
assertThat(config.getOpenMetrics2Properties().getContentNegotiation()).isTrue();
193-
assertThat(config.getOpenMetrics2Properties().getDisableSuffixAppending()).isTrue();
194186
assertThat(config.getOpenMetrics2Properties().getCompositeValues()).isFalse();
195187
assertThat(config.getOpenMetrics2Properties().getExemplarCompliance()).isTrue();
196188
assertThat(config.getOpenMetrics2Properties().getNativeHistograms()).isFalse();

0 commit comments

Comments
 (0)