Skip to content

Commit d4d2267

Browse files
checkettsbrian-brazil
authored andcommitted
Add build() method that has required fields. (prometheus#187)
1 parent 996e402 commit d4d2267

4 files changed

Lines changed: 40 additions & 0 deletions

File tree

simpleclient/src/main/java/io/prometheus/client/Counter.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,16 @@ public Counter create() {
7777
}
7878
}
7979

80+
/**
81+
* Return a Builder to allow configuration of a new Counter. Ensures required fields are provided.
82+
*
83+
* @param name The name of the metric
84+
* @param help The help string of the metric
85+
*/
86+
public static Builder build(String name, String help) {
87+
return new Builder().name(name).help(help);
88+
}
89+
8090
/**
8191
* Return a Builder to allow configuration of a new Counter.
8292
*/

simpleclient/src/main/java/io/prometheus/client/Gauge.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,16 @@ public Gauge create() {
7575
}
7676
}
7777

78+
/**
79+
* Return a Builder to allow configuration of a new Gauge. Ensures required fields are provided.
80+
*
81+
* @param name The name of the metric
82+
* @param help The help string of the metric
83+
*/
84+
public static Builder build(String name, String help) {
85+
return new Builder().name(name).help(help);
86+
}
87+
7888
/**
7989
* Return a Builder to allow configuration of a new Gauge.
8090
*/

simpleclient/src/main/java/io/prometheus/client/Histogram.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,16 @@ public Builder exponentialBuckets(double start, double factor, int count) {
130130

131131
}
132132

133+
/**
134+
* Return a Builder to allow configuration of a new Histogram. Ensures required fields are provided.
135+
*
136+
* @param name The name of the metric
137+
* @param help The help string of the metric
138+
*/
139+
public static Builder build(String name, String help) {
140+
return new Builder().name(name).help(help);
141+
}
142+
133143
/**
134144
* Return a Builder to allow configuration of a new Histogram.
135145
*/

simpleclient/src/main/java/io/prometheus/client/Summary.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,16 @@ public Summary create() {
137137
}
138138
}
139139

140+
/**
141+
* Return a Builder to allow configuration of a new Summary. Ensures required fields are provided.
142+
*
143+
* @param name The name of the metric
144+
* @param help The help string of the metric
145+
*/
146+
public static Builder build(String name, String help) {
147+
return new Builder().name(name).help(help);
148+
}
149+
140150
/**
141151
* Return a Builder to allow configuration of a new Summary.
142152
*/

0 commit comments

Comments
 (0)