use of io.prometheus.client.Collector.MetricFamilySamples.Sample in project promregator by promregator.
the class TextFormat004ParserTest method testGaugeWithSingleLabelEscaping.
@Test
public void testGaugeWithSingleLabelEscaping() {
String textToParse = "# TYPE metric_with_label gauge\n" + "metric_with_label{name=\"containing \\\" and \\\\ and \\n\"} 12.47\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<>();
List<String> labelNames = new LinkedList<>();
labelNames.add("name");
List<String> labelValues = new LinkedList<>();
labelValues.add("containing \" and \\ and \n");
Sample sample = new Sample("metric_with_label", labelNames, labelValues, 12.47);
samples.add(sample);
Collector.MetricFamilySamples expectedMFS = new Collector.MetricFamilySamples("metric_with_label", Type.GAUGE, 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 testHelpEscaping.
@Test
public void testHelpEscaping() {
String textToParse = "# Simple metric without labels:\n" + "# TYPE metric_without_labels counter\n" + "# HELP metric_without_labels this is my help text with \\\\ backslashes escaped \\\\ and escaped newline \\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.COUNTER, "this is my help text with \\ backslashes escaped \\ and escaped newline \n", 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 testGaugeWithMultipleLabels.
@Test
public void testGaugeWithMultipleLabels() {
String textToParse = "# TYPE metric_with_label gauge\n" + "metric_with_label{name=\"value\",second=\"somevalue\",third=\"next value\",} 12.47\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<>();
List<String> labelNames = new LinkedList<>();
labelNames.add("name");
labelNames.add("second");
labelNames.add("third");
List<String> labelValues = new LinkedList<>();
labelValues.add("value");
labelValues.add("somevalue");
labelValues.add("next value");
Sample sample = new Sample("metric_with_label", labelNames, labelValues, 12.47);
samples.add(sample);
Collector.MetricFamilySamples expectedMFS = new Collector.MetricFamilySamples("metric_with_label", Type.GAUGE, 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 testSummaryWithLabel.
@Test
public void testSummaryWithLabel() {
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{name=\"value\",quantile=\"0.01\",} 3102\n" + "rpc_duration_seconds{name=\"value\",quantile=\"0.05\"} 3272\n" + "rpc_duration_seconds{quantile=\"0.5\",name=\"value\",} 4773\n" + "rpc_duration_seconds{quantile=\"0.9\",name=\"value\"} 9001\n" + "rpc_duration_seconds{name=\"value\",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 = createSampleForSummaryWithDummyLabel("rpc_duration_seconds", "0.01", 3102, true);
samples.add(sample);
sample = createSampleForSummaryWithDummyLabel("rpc_duration_seconds", "0.05", 3272, true);
samples.add(sample);
sample = createSampleForSummaryWithDummyLabel("rpc_duration_seconds", "0.5", 4773, false);
samples.add(sample);
sample = createSampleForSummaryWithDummyLabel("rpc_duration_seconds", "0.9", 9001, false);
samples.add(sample);
sample = createSampleForSummaryWithDummyLabel("rpc_duration_seconds", "0.99", 76656, true);
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 GenericMetricFamilySamplesPrefixRewriterTest method testDoesNotPrefixIfNotNeeded.
@Test
public void testDoesNotPrefixIfNotNeeded() {
GenericMetricFamilySamplesPrefixRewriter subject = new GenericMetricFamilySamplesPrefixRewriter("prefix");
List<Sample> samples = new LinkedList<>();
Sample s = new Sample("prefix_dummyname", Arrays.asList(new String[] { "labelName" }), Arrays.asList(new String[] { "labelValue" }), 1.0);
samples.add(s);
MetricFamilySamples mfs = new MetricFamilySamples("prefix_dummyname", Type.GAUGE, "dummyHelp", samples);
HashMap<String, MetricFamilySamples> map = new HashMap<>();
map.put("prefix_metricName", mfs);
HashMap<String, MetricFamilySamples> result = subject.determineEnumerationOfMetricFamilySamples(map);
MetricFamilySamples mfsResult = result.get("prefix_metricName");
Assert.assertNotNull(mfsResult);
Assert.assertEquals("prefix_dummyname", mfsResult.name);
Assert.assertEquals(1, mfsResult.samples.size());
Sample sampleResult = mfsResult.samples.get(0);
;
Assert.assertEquals("prefix_dummyname", sampleResult.name);
}
Aggregations