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));
}
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));
}
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);
}
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));
}
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));
}
Aggregations