Search in sources :

Example 1 with MetricsOptions

use of org.apache.beam.sdk.metrics.MetricsOptions in project beam by apache.

the class MetricsHttpSinkTest method testWriteMetricsWithCommittedSupported.

@Test
public void testWriteMetricsWithCommittedSupported() throws Exception {
    MetricQueryResults metricQueryResults = new CustomMetricQueryResults(true);
    MetricsOptions pipelineOptions = PipelineOptionsFactory.create().as(MetricsOptions.class);
    pipelineOptions.setMetricsHttpSinkUrl(String.format("http://localhost:%s", port));
    MetricsHttpSink metricsHttpSink = new MetricsHttpSink(pipelineOptions);
    countDownLatch = new CountDownLatch(1);
    metricsHttpSink.writeMetrics(metricQueryResults);
    countDownLatch.await();
    String expected = "{\"counters\":[{\"attempted\":20,\"committed\":10,\"name\":{\"name\":\"n1\"," + "\"namespace\":\"ns1\"},\"step\":\"s1\"}],\"distributions\":[{\"attempted\":" + "{\"count\":4,\"max\":9,\"mean\":6.25,\"min\":3,\"sum\":25},\"committed\":" + "{\"count\":2,\"max\":8,\"mean\":5.0,\"min\":5,\"sum\":10},\"name\":{\"name\":\"n2\"," + "\"namespace\":\"ns1\"},\"step\":\"s2\"}],\"gauges\":[{\"attempted\":{\"timestamp\":" + "\"1970-01-05T00:04:22.800Z\",\"value\":120},\"committed\":{\"timestamp\":" + "\"1970-01-05T00:04:22.800Z\",\"value\":100},\"name\":{\"name\":\"n3\",\"namespace\":" + "\"ns1\"},\"step\":\"s3\"}]}";
    assertEquals("Wrong number of messages sent to HTTP server", 1, messages.size());
    assertEquals("Wrong messages sent to HTTP server", expected, messages.get(0));
}
Also used : MetricsOptions(org.apache.beam.sdk.metrics.MetricsOptions) MetricQueryResults(org.apache.beam.sdk.metrics.MetricQueryResults) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Example 2 with MetricsOptions

use of org.apache.beam.sdk.metrics.MetricsOptions in project beam by apache.

the class MetricsGraphiteSinkTest method testWriteMetricsWithCommittedUnSupported.

@Test
public void testWriteMetricsWithCommittedUnSupported() throws Exception {
    MetricQueryResults metricQueryResults = new CustomMetricQueryResults(false);
    MetricsOptions pipelineOptions = PipelineOptionsFactory.create().as(MetricsOptions.class);
    pipelineOptions.setMetricsGraphitePort(port);
    pipelineOptions.setMetricsGraphiteHost("127.0.0.1");
    MetricsGraphiteSink metricsGraphiteSink = new MetricsGraphiteSink(pipelineOptions);
    CountDownLatch countDownLatch = new CountDownLatch(1);
    graphiteServer.setCountDownLatch(countDownLatch);
    metricsGraphiteSink.writeMetrics(metricQueryResults);
    countDownLatch.await();
    String join = String.join("\n", graphiteServer.getMessages());
    String regexpr = "beam.counter.ns1.n1.s1.attempted.value 20 [0-9]+\\n" + "beam.gauge.ns1.n3.s3.attempted.value 120 [0-9]+\\n" + "beam.distribution.ns1.n2.s2.attempted.min 3 [0-9]+\\n" + "beam.distribution.ns1.n2.s2.attempted.max 9 [0-9]+\\n" + "beam.distribution.ns1.n2.s2.attempted.count 4 [0-9]+\\n" + "beam.distribution.ns1.n2.s2.attempted.sum 25 [0-9]+\\n" + "beam.distribution.ns1.n2.s2.attempted.mean 6.25 [0-9]+";
    assertTrue(join.matches(regexpr));
}
Also used : MetricsOptions(org.apache.beam.sdk.metrics.MetricsOptions) MetricQueryResults(org.apache.beam.sdk.metrics.MetricQueryResults) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Example 3 with MetricsOptions

use of org.apache.beam.sdk.metrics.MetricsOptions in project beam by apache.

the class MetricsPusherTest method init.

@Before
public void init() {
    MetricsOptions options = pipeline.getOptions().as(MetricsOptions.class);
    options.setMetricsSink(TestMetricsSink.class);
}
Also used : MetricsOptions(org.apache.beam.sdk.metrics.MetricsOptions) Before(org.junit.Before)

Example 4 with MetricsOptions

use of org.apache.beam.sdk.metrics.MetricsOptions in project beam by apache.

the class MetricsHttpSinkTest method testWriteMetricsWithCommittedUnSupported.

@Test
public void testWriteMetricsWithCommittedUnSupported() throws Exception {
    MetricQueryResults metricQueryResults = new CustomMetricQueryResults(false);
    MetricsOptions pipelineOptions = PipelineOptionsFactory.create().as(MetricsOptions.class);
    pipelineOptions.setMetricsHttpSinkUrl(String.format("http://localhost:%s", port));
    MetricsHttpSink metricsHttpSink = new MetricsHttpSink(pipelineOptions);
    countDownLatch = new CountDownLatch(1);
    metricsHttpSink.writeMetrics(metricQueryResults);
    countDownLatch.await();
    String expected = "{\"counters\":[{\"attempted\":20,\"name\":{\"name\":\"n1\"," + "\"namespace\":\"ns1\"},\"step\":\"s1\"}],\"distributions\":[{\"attempted\":" + "{\"count\":4,\"max\":9,\"mean\":6.25,\"min\":3,\"sum\":25},\"name\":{\"name\":\"n2\"" + ",\"namespace\":\"ns1\"},\"step\":\"s2\"}],\"gauges\":[{\"attempted\":{\"timestamp\":" + "\"1970-01-05T00:04:22.800Z\",\"value\":120},\"name\":{\"name\":\"n3\",\"namespace\":" + "\"ns1\"},\"step\":\"s3\"}]}";
    assertEquals("Wrong number of messages sent to HTTP server", 1, messages.size());
    assertEquals("Wrong messages sent to HTTP server", expected, messages.get(0));
}
Also used : MetricsOptions(org.apache.beam.sdk.metrics.MetricsOptions) MetricQueryResults(org.apache.beam.sdk.metrics.MetricQueryResults) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Example 5 with MetricsOptions

use of org.apache.beam.sdk.metrics.MetricsOptions in project beam by apache.

the class MetricsGraphiteSinkTest method testWriteMetricsWithCommittedSupported.

@Test
public void testWriteMetricsWithCommittedSupported() throws Exception {
    MetricQueryResults metricQueryResults = new CustomMetricQueryResults(true);
    MetricsOptions pipelineOptions = PipelineOptionsFactory.create().as(MetricsOptions.class);
    pipelineOptions.setMetricsGraphitePort(port);
    pipelineOptions.setMetricsGraphiteHost("127.0.0.1");
    MetricsGraphiteSink metricsGraphiteSink = new MetricsGraphiteSink(pipelineOptions);
    CountDownLatch countDownLatch = new CountDownLatch(1);
    graphiteServer.setCountDownLatch(countDownLatch);
    metricsGraphiteSink.writeMetrics(metricQueryResults);
    countDownLatch.await();
    String join = String.join("\n", graphiteServer.getMessages());
    String regexpr = "beam.counter.ns1.n1.s1.committed.value 10 [0-9]+\\n" + "beam.counter.ns1.n1.s1.attempted.value 20 [0-9]+\\n" + "beam.gauge.ns1.n3.s3.committed.value 100 [0-9]+\\n" + "beam.gauge.ns1.n3.s3.attempted.value 120 [0-9]+\\n" + "beam.distribution.ns1.n2.s2.committed.min 5 [0-9]+\\n" + "beam.distribution.ns1.n2.s2.attempted.min 3 [0-9]+\\n" + "beam.distribution.ns1.n2.s2.committed.max 8 [0-9]+\\n" + "beam.distribution.ns1.n2.s2.attempted.max 9 [0-9]+\\n" + "beam.distribution.ns1.n2.s2.committed.count 2 [0-9]+\\n" + "beam.distribution.ns1.n2.s2.attempted.count 4 [0-9]+\\n" + "beam.distribution.ns1.n2.s2.committed.sum 10 [0-9]+\\n" + "beam.distribution.ns1.n2.s2.attempted.sum 25 [0-9]+\\n" + "beam.distribution.ns1.n2.s2.committed.mean 5.0 [0-9]+\\n" + "beam.distribution.ns1.n2.s2.attempted.mean 6.25 [0-9]+";
    assertTrue(join.matches(regexpr));
}
Also used : MetricsOptions(org.apache.beam.sdk.metrics.MetricsOptions) MetricQueryResults(org.apache.beam.sdk.metrics.MetricQueryResults) CountDownLatch(java.util.concurrent.CountDownLatch) Test(org.junit.Test)

Aggregations

MetricsOptions (org.apache.beam.sdk.metrics.MetricsOptions)6 CountDownLatch (java.util.concurrent.CountDownLatch)4 MetricQueryResults (org.apache.beam.sdk.metrics.MetricQueryResults)4 Test (org.junit.Test)4 Before (org.junit.Before)2