use of io.prometheus.client.Collector.MetricFamilySamples.Sample in project promregator by promregator.
the class TextFormat004ParserTest method testSummarySpecificationExample.
@Test
public void testSummarySpecificationExample() {
String textToParse = "# Finally a summary, which has a complex representation, too:\n" + "# HELP rpc_duration_seconds A summary of the RPC duration in seconds.\n" + "# TYPE rpc_duration_seconds summary\n" + "rpc_duration_seconds{quantile=\"0.01\"} 3102\n" + "rpc_duration_seconds{quantile=\"0.05\"} 3272\n" + "rpc_duration_seconds{quantile=\"0.5\"} 4773\n" + "rpc_duration_seconds{quantile=\"0.9\"} 9001\n" + "rpc_duration_seconds{quantile=\"0.99\"} 76656\n" + "rpc_duration_seconds_sum 1.7560473e+07\n" + "rpc_duration_seconds_count 2693";
TextFormat004Parser subject = new TextFormat004Parser(textToParse);
HashMap<String, Collector.MetricFamilySamples> resultMap = subject.parse();
Enumeration<Collector.MetricFamilySamples> result = Collections.enumeration(resultMap.values());
// creating expected result
LinkedList<Collector.MetricFamilySamples> expectedList = new LinkedList<>();
List<Sample> samples = new LinkedList<>();
Sample sample = null;
sample = createSampleForSummary("rpc_duration_seconds", "0.01", 3102);
samples.add(sample);
sample = createSampleForSummary("rpc_duration_seconds", "0.05", 3272);
samples.add(sample);
sample = createSampleForSummary("rpc_duration_seconds", "0.5", 4773);
samples.add(sample);
sample = createSampleForSummary("rpc_duration_seconds", "0.9", 9001);
samples.add(sample);
sample = createSampleForSummary("rpc_duration_seconds", "0.99", 76656);
samples.add(sample);
sample = new Sample("rpc_duration_seconds_sum", new LinkedList<>(), new LinkedList<>(), 1.7560473e+07);
samples.add(sample);
sample = new Sample("rpc_duration_seconds_count", new LinkedList<>(), new LinkedList<>(), 2693);
samples.add(sample);
Collector.MetricFamilySamples expectedMFS = new Collector.MetricFamilySamples("rpc_duration_seconds", Type.SUMMARY, "A summary of the RPC duration in seconds.", samples);
expectedList.add(expectedMFS);
Enumeration<Collector.MetricFamilySamples> expected = Collections.enumeration(expectedList);
// compare
compareEMFS(expected, result);
}
use of io.prometheus.client.Collector.MetricFamilySamples.Sample in project promregator by promregator.
the class TextFormat004ParserTest method createSampleForSummaryWithDummyLabel.
private static Sample createSampleForSummaryWithDummyLabel(String bucketMetricName, String quantileValue, double value, boolean firstPosition) {
List<String> labelNames = new LinkedList<>();
if (firstPosition) {
labelNames.add("name");
}
labelNames.add("quantile");
if (!firstPosition) {
labelNames.add("name");
}
List<String> labelValues = new LinkedList<>();
if (firstPosition) {
labelValues.add("value");
}
labelValues.add(quantileValue);
if (!firstPosition) {
labelValues.add("value");
}
Sample sample = new Sample(bucketMetricName, labelNames, labelValues, value);
return sample;
}
use of io.prometheus.client.Collector.MetricFamilySamples.Sample in project promregator by promregator.
the class TextFormat004ParserTest method createSampleForHistogram.
private static Sample createSampleForHistogram(String bucketMetricName, String leValue, double value) {
List<String> labelNames = new LinkedList<>();
labelNames.add("le");
List<String> labelValues = new LinkedList<>();
labelValues.add(leValue);
Sample sample = new Sample(bucketMetricName, labelNames, labelValues, value);
return sample;
}
use of io.prometheus.client.Collector.MetricFamilySamples.Sample in project promregator by promregator.
the class TextFormat004ParserTest method testSimplePlusInf.
@Test
public void testSimplePlusInf() {
String textToParse = "# Minimalistic line:\n" + "\n" + "metric_without_labels +Inf 123456789012345600\n";
TextFormat004Parser subject = new TextFormat004Parser(textToParse);
HashMap<String, Collector.MetricFamilySamples> resultMap = subject.parse();
Enumeration<Collector.MetricFamilySamples> result = Collections.enumeration(resultMap.values());
// creating expected result
LinkedList<Collector.MetricFamilySamples> expectedList = new LinkedList<>();
List<Sample> samples = new LinkedList<>();
Sample sample = new Sample("metric_without_labels", new LinkedList<String>(), new LinkedList<String>(), Double.POSITIVE_INFINITY);
samples.add(sample);
Collector.MetricFamilySamples expectedMFS = new Collector.MetricFamilySamples("metric_without_labels", Type.UNTYPED, null, samples);
expectedList.add(expectedMFS);
Enumeration<Collector.MetricFamilySamples> expected = Collections.enumeration(expectedList);
// compare
compareEMFS(expected, result);
}
use of io.prometheus.client.Collector.MetricFamilySamples.Sample in project promregator by promregator.
the class TextFormat004ParserTest method testSimpleWithTimestampAndEmptyLine.
@Test
public void testSimpleWithTimestampAndEmptyLine() {
String textToParse = "# Minimalistic line:\n" + "\n" + "metric_without_labels 12.47 123456789012345600\n";
TextFormat004Parser subject = new TextFormat004Parser(textToParse);
HashMap<String, Collector.MetricFamilySamples> resultMap = subject.parse();
Enumeration<Collector.MetricFamilySamples> result = Collections.enumeration(resultMap.values());
// creating expected result
LinkedList<Collector.MetricFamilySamples> expectedList = new LinkedList<>();
List<Sample> samples = new LinkedList<>();
Sample sample = new Sample("metric_without_labels", new LinkedList<String>(), new LinkedList<String>(), 12.47);
samples.add(sample);
Collector.MetricFamilySamples expectedMFS = new Collector.MetricFamilySamples("metric_without_labels", Type.UNTYPED, null, samples);
expectedList.add(expectedMFS);
Enumeration<Collector.MetricFamilySamples> expected = Collections.enumeration(expectedList);
// compare
compareEMFS(expected, result);
}
Aggregations