Search in sources :

Example 31 with Sample

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);
}
Also used : Sample(io.prometheus.client.Collector.MetricFamilySamples.Sample) Collector(io.prometheus.client.Collector) MetricFamilySamples(io.prometheus.client.Collector.MetricFamilySamples) LinkedList(java.util.LinkedList) MetricFamilySamples(io.prometheus.client.Collector.MetricFamilySamples) Test(org.junit.Test)

Example 32 with Sample

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);
}
Also used : Sample(io.prometheus.client.Collector.MetricFamilySamples.Sample) Collector(io.prometheus.client.Collector) MetricFamilySamples(io.prometheus.client.Collector.MetricFamilySamples) LinkedList(java.util.LinkedList) MetricFamilySamples(io.prometheus.client.Collector.MetricFamilySamples) Test(org.junit.Test)

Example 33 with Sample

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);
}
Also used : Sample(io.prometheus.client.Collector.MetricFamilySamples.Sample) Collector(io.prometheus.client.Collector) MetricFamilySamples(io.prometheus.client.Collector.MetricFamilySamples) LinkedList(java.util.LinkedList) MetricFamilySamples(io.prometheus.client.Collector.MetricFamilySamples) Test(org.junit.Test)

Example 34 with Sample

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);
}
Also used : Sample(io.prometheus.client.Collector.MetricFamilySamples.Sample) Collector(io.prometheus.client.Collector) MetricFamilySamples(io.prometheus.client.Collector.MetricFamilySamples) LinkedList(java.util.LinkedList) MetricFamilySamples(io.prometheus.client.Collector.MetricFamilySamples) Test(org.junit.Test)

Example 35 with Sample

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);
}
Also used : HashMap(java.util.HashMap) Sample(io.prometheus.client.Collector.MetricFamilySamples.Sample) MetricFamilySamples(io.prometheus.client.Collector.MetricFamilySamples) LinkedList(java.util.LinkedList) Test(org.junit.Test)

Aggregations

Sample (io.prometheus.client.Collector.MetricFamilySamples.Sample)44 MetricFamilySamples (io.prometheus.client.Collector.MetricFamilySamples)34 Test (org.junit.Test)32 LinkedList (java.util.LinkedList)27 Collector (io.prometheus.client.Collector)18 ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)4 Type (io.prometheus.client.Collector.Type)2 Collector.doubleToGoString (io.prometheus.client.Collector.doubleToGoString)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 Meter (com.netflix.spectator.api.Meter)1 Registry (com.netflix.spectator.api.Registry)1 Tag (com.netflix.spectator.api.Tag)1 LabelValue (io.opencensus.metrics.LabelValue)1 Distribution (io.opencensus.metrics.export.Distribution)1 BucketOptions (io.opencensus.metrics.export.Distribution.BucketOptions)1 ExplicitOptions (io.opencensus.metrics.export.Distribution.BucketOptions.ExplicitOptions)1 MetricDescriptor (io.opencensus.metrics.export.MetricDescriptor)1 Summary (io.opencensus.metrics.export.Summary)1 ValueAtPercentile (io.opencensus.metrics.export.Summary.Snapshot.ValueAtPercentile)1