-
Notifications
You must be signed in to change notification settings - Fork 828
Expand file tree
/
Copy pathOpenMetrics2Properties.java
More file actions
118 lines (98 loc) · 4.19 KB
/
OpenMetrics2Properties.java
File metadata and controls
118 lines (98 loc) · 4.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
package io.prometheus.metrics.config;
import javax.annotation.Nullable;
/**
* Properties starting with io.prometheus.openmetrics2. These properties are experimental and
* subject to change.
*/
public class OpenMetrics2Properties {
private static final String PREFIX = "io.prometheus.openmetrics2";
private static final String CONTENT_NEGOTIATION = "content_negotiation";
private static final String COMPOSITE_VALUES = "composite_values";
private static final String EXEMPLAR_COMPLIANCE = "exemplar_compliance";
private static final String NATIVE_HISTOGRAMS = "native_histograms";
@Nullable private final Boolean contentNegotiation;
@Nullable private final Boolean compositeValues;
@Nullable private final Boolean exemplarCompliance;
@Nullable private final Boolean nativeHistograms;
private OpenMetrics2Properties(
@Nullable Boolean contentNegotiation,
@Nullable Boolean compositeValues,
@Nullable Boolean exemplarCompliance,
@Nullable Boolean nativeHistograms) {
this.contentNegotiation = contentNegotiation;
this.compositeValues = compositeValues;
this.exemplarCompliance = exemplarCompliance;
this.nativeHistograms = nativeHistograms;
}
/** Gate OM2 features behind content negotiation. Default is {@code false}. */
public boolean getContentNegotiation() {
return contentNegotiation != null && contentNegotiation;
}
/** Single-line histogram/summary with {@code st@}. Default is {@code false}. */
public boolean getCompositeValues() {
return compositeValues != null && compositeValues;
}
/** Mandatory timestamps, no 128-char limit for exemplars. Default is {@code false}. */
public boolean getExemplarCompliance() {
return exemplarCompliance != null && exemplarCompliance;
}
/** Exponential buckets support for native histograms. Default is {@code false}. */
public boolean getNativeHistograms() {
return nativeHistograms != null && nativeHistograms;
}
/**
* Note that this will remove entries from {@code propertySource}. This is because we want to know
* if there are unused properties remaining after all properties have been loaded.
*/
static OpenMetrics2Properties load(PropertySource propertySource)
throws PrometheusPropertiesException {
Boolean contentNegotiation = Util.loadBoolean(PREFIX, CONTENT_NEGOTIATION, propertySource);
Boolean compositeValues = Util.loadBoolean(PREFIX, COMPOSITE_VALUES, propertySource);
Boolean exemplarCompliance = Util.loadBoolean(PREFIX, EXEMPLAR_COMPLIANCE, propertySource);
Boolean nativeHistograms = Util.loadBoolean(PREFIX, NATIVE_HISTOGRAMS, propertySource);
return new OpenMetrics2Properties(
contentNegotiation, compositeValues, exemplarCompliance, nativeHistograms);
}
public static Builder builder() {
return new Builder();
}
public static class Builder {
@Nullable private Boolean contentNegotiation;
@Nullable private Boolean compositeValues;
@Nullable private Boolean exemplarCompliance;
@Nullable private Boolean nativeHistograms;
private Builder() {}
/** See {@link #getContentNegotiation()} */
public Builder contentNegotiation(boolean contentNegotiation) {
this.contentNegotiation = contentNegotiation;
return this;
}
/** See {@link #getCompositeValues()} */
public Builder compositeValues(boolean compositeValues) {
this.compositeValues = compositeValues;
return this;
}
/** See {@link #getExemplarCompliance()} */
public Builder exemplarCompliance(boolean exemplarCompliance) {
this.exemplarCompliance = exemplarCompliance;
return this;
}
/** See {@link #getNativeHistograms()} */
public Builder nativeHistograms(boolean nativeHistograms) {
this.nativeHistograms = nativeHistograms;
return this;
}
/** Enable all OpenMetrics 2.0 features */
public Builder enableAll() {
this.contentNegotiation = true;
this.compositeValues = true;
this.exemplarCompliance = true;
this.nativeHistograms = true;
return this;
}
public OpenMetrics2Properties build() {
return new OpenMetrics2Properties(
contentNegotiation, compositeValues, exemplarCompliance, nativeHistograms);
}
}
}