|
5 | 5 | import java.io.IOException; |
6 | 6 | import java.io.StringWriter; |
7 | 7 | import java.util.ArrayList; |
| 8 | +import java.util.Arrays; |
8 | 9 | import java.util.List; |
9 | 10 |
|
10 | 11 | import org.junit.Before; |
@@ -57,6 +58,17 @@ public void testCounterOutput() throws IOException { |
57 | 58 | + "nolabels_total 1.0\n", writer.toString()); |
58 | 59 | } |
59 | 60 |
|
| 61 | + @Test |
| 62 | + public void testCounterWithTotalOutput() throws IOException { |
| 63 | + Counter noLabels = Counter.build().name("nolabels_total").help("help").register(registry); |
| 64 | + noLabels.inc(); |
| 65 | + TextFormat.write004(writer, registry.metricFamilySamples()); |
| 66 | + assertEquals("# HELP nolabels_total help\n" |
| 67 | + + "# TYPE nolabels_total counter\n" |
| 68 | + + "nolabels_total 1.0\n", writer.toString()); |
| 69 | + } |
| 70 | + |
| 71 | + |
60 | 72 | @Test |
61 | 73 | public void testCounterSamplesMissingTotal() throws IOException { |
62 | 74 |
|
@@ -131,6 +143,39 @@ public void testSummaryOutputWithQuantiles() throws IOException { |
131 | 143 | + "labelsAndQuantiles_sum{l=\"a\",} 2.0\n", writer.toString()); |
132 | 144 | } |
133 | 145 |
|
| 146 | + @Test |
| 147 | + public void testGaugeHistogramOutput() throws IOException { |
| 148 | + class CustomCollector extends Collector { |
| 149 | + public List<MetricFamilySamples> collect() { |
| 150 | + List<MetricFamilySamples> mfs = new ArrayList<MetricFamilySamples>(); |
| 151 | + ArrayList<String> labelNames = new ArrayList<String>(); |
| 152 | + ArrayList<String> labelValues = new ArrayList<String>(); |
| 153 | + ArrayList<MetricFamilySamples.Sample> samples = new ArrayList<Collector.MetricFamilySamples.Sample>(); |
| 154 | + samples.add(new MetricFamilySamples.Sample("nolabels_bucket", Arrays.asList("le"), Arrays.asList("+Inf"), 2.0)); |
| 155 | + samples.add(new MetricFamilySamples.Sample("nolabels_gcount", labelNames, labelValues, 2.0)); |
| 156 | + samples.add(new MetricFamilySamples.Sample("nolabels_gsum", labelNames, labelValues, 7.0)); |
| 157 | + samples.add(new MetricFamilySamples.Sample("nolabels_created", labelNames, labelValues, 1234.0)); |
| 158 | + mfs.add(new MetricFamilySamples("nolabels", Collector.Type.GAUGE_HISTOGRAM, "help", samples)); |
| 159 | + return mfs; |
| 160 | + } |
| 161 | + } |
| 162 | + new CustomCollector().register(registry); |
| 163 | + writer = new StringWriter(); |
| 164 | + TextFormat.write004(writer, registry.metricFamilySamples()); |
| 165 | + assertEquals("# HELP nolabels help\n" |
| 166 | + + "# TYPE nolabels histogram\n" |
| 167 | + + "nolabels_bucket{le=\"+Inf\",} 2.0\n" |
| 168 | + + "# HELP nolabels_created help\n" |
| 169 | + + "# TYPE nolabels_created gauge\n" |
| 170 | + + "nolabels_created 1234.0\n" |
| 171 | + + "# HELP nolabels_gcount help\n" |
| 172 | + + "# TYPE nolabels_gcount gauge\n" |
| 173 | + + "nolabels_gcount 2.0\n" |
| 174 | + + "# HELP nolabels_gsum help\n" |
| 175 | + + "# TYPE nolabels_gsum gauge\n" |
| 176 | + + "nolabels_gsum 7.0\n", writer.toString()); |
| 177 | + } |
| 178 | + |
134 | 179 | @Test |
135 | 180 | public void testLabelsOutput() throws IOException { |
136 | 181 | Gauge labels = Gauge.build().name("labels").help("help").labelNames("l").register(registry); |
|
0 commit comments