Search in sources :

Example 11 with MetricsRecord

use of org.apache.heron.spi.metricsmgr.metrics.MetricsRecord in project heron by twitter.

the class WebSinkTest method testTTLMetrics.

/**
 * Testing TTL
 */
@Test
public void testTTLMetrics() throws InterruptedException {
    Duration cacheTTL = Duration.ofSeconds(1);
    Map<String, Object> conf = new HashMap<>(defaultConf);
    conf.put("metrics-cache-ttl-sec", cacheTTL.getSeconds());
    FakeTicker ticker = new FakeTicker();
    WebTestSink sink = new WebTestSink(ticker);
    sink.init(conf, context);
    for (MetricsRecord r : records) {
        sink.processRecord(r);
    }
    Assert.assertEquals(records.size() * 2, sink.getMetrics().size());
    ticker.advance(cacheTTL.plusMillis(1));
    sink.syncCache();
    Assert.assertEquals(0, sink.getMetrics().size());
}
Also used : HashMap(java.util.HashMap) MetricsRecord(org.apache.heron.spi.metricsmgr.metrics.MetricsRecord) Duration(java.time.Duration) Test(org.junit.Test)

Example 12 with MetricsRecord

use of org.apache.heron.spi.metricsmgr.metrics.MetricsRecord in project heron by twitter.

the class MetricsManagerServerTest method testMetricsManagerServer.

/**
 * Method: addSinkCommunicator(Communicator&lt;MetricsRecord&gt; communicator)
 */
@Test
public void testMetricsManagerServer() throws InterruptedException {
    String name = "test_communicator";
    CountDownLatch offersLatch = new CountDownLatch(MESSAGE_SIZE);
    Communicator<MetricsRecord> sinkCommunicator = CommunicatorTestHelper.spyCommunicator(new Communicator<MetricsRecord>(), offersLatch);
    metricsManagerServer.addSinkCommunicator(name, sinkCommunicator);
    serverTester.start();
    HeronServerTester.await(offersLatch);
    int messages = 0;
    while (!sinkCommunicator.isEmpty()) {
        int exceptions = 0;
        int metrics = 0;
        MetricsRecord record = sinkCommunicator.poll();
        Assert.assertEquals("hostname:0/component/instance-id", record.getSource());
        Assert.assertEquals("default", record.getContext());
        for (MetricsInfo info : record.getMetrics()) {
            Assert.assertEquals(METRIC_NAME, info.getName());
            Assert.assertEquals(METRIC_VALUE, info.getValue());
            metrics++;
        }
        Assert.assertEquals(METRICS_COUNT, metrics);
        for (ExceptionInfo info : record.getExceptions()) {
            Assert.assertEquals(STACK_TRACE, info.getStackTrace());
            Assert.assertEquals(LAST_TIME, info.getLastTime());
            Assert.assertEquals(FIRST_TIME, info.getFirstTime());
            Assert.assertEquals(LOGGING, info.getLogging());
            Assert.assertEquals(EXCEPTION_COUNT, info.getCount());
            exceptions++;
        }
        Assert.assertEquals(METRICS_COUNT, exceptions);
        messages++;
    }
    Assert.assertEquals(MESSAGE_SIZE, messages);
}
Also used : MetricsInfo(org.apache.heron.spi.metricsmgr.metrics.MetricsInfo) MetricsRecord(org.apache.heron.spi.metricsmgr.metrics.MetricsRecord) CountDownLatch(java.util.concurrent.CountDownLatch) ExceptionInfo(org.apache.heron.spi.metricsmgr.metrics.ExceptionInfo) Test(org.junit.Test)

Example 13 with MetricsRecord

use of org.apache.heron.spi.metricsmgr.metrics.MetricsRecord in project heron by twitter.

the class SinkExecutorTest method constructMetricsRecord.

private MetricsRecord constructMetricsRecord() {
    List<MetricsInfo> metricsInfos = new ArrayList<>();
    // We add EXPECTED_RECORDS MetricsInfo into a MetricsRecord
    for (int i = 0; i < EXPECTED_RECORDS; i++) {
        MetricsInfo metricsInfo = new MetricsInfo(METRICS_NAME + i, METRICS_VALUE + i);
        metricsInfos.add(metricsInfo);
    }
    // We add EXPECTED_RECORDS ExceptionInfo into a MetricsRecord
    List<ExceptionInfo> exceptionInfos = new ArrayList<>();
    for (int i = 0; i < EXPECTED_RECORDS; i++) {
        String stackTrace = EXCEPTION_STACK_TRACE + i;
        String lastTime = EXCEPTION_LAST_TIME + i;
        String firstTime = EXCEPTION_FIRST_TIME + i;
        String logging = EXCEPTION_LOGGING + i;
        ExceptionInfo info = new ExceptionInfo(stackTrace, lastTime, firstTime, i, logging);
        exceptionInfos.add(info);
    }
    return new MetricsRecord(RECORD_SOURCE, metricsInfos, exceptionInfos, RECORD_CONTEXT);
}
Also used : MetricsInfo(org.apache.heron.spi.metricsmgr.metrics.MetricsInfo) MetricsRecord(org.apache.heron.spi.metricsmgr.metrics.MetricsRecord) ArrayList(java.util.ArrayList) ExceptionInfo(org.apache.heron.spi.metricsmgr.metrics.ExceptionInfo)

Example 14 with MetricsRecord

use of org.apache.heron.spi.metricsmgr.metrics.MetricsRecord in project heron by twitter.

the class PrometheusSinkTests method testResponseWhenMetricNamesHaveAnInstanceId.

@Test
public void testResponseWhenMetricNamesHaveAnInstanceId() throws IOException {
    Iterable<MetricsInfo> infos = Arrays.asList(new MetricsInfo("__connection_buffer_by_instanceid/container_1_word_5/packets", "1.0"), new MetricsInfo("__time_spent_back_pressure_by_compid/container_1_exclaim1_1", "1.0"), new MetricsInfo("__client_stmgr-92/__ack_tuples_to_stmgrs", "1.0"), new MetricsInfo("__instance_bytes_received/1", "1.0"));
    records = Arrays.asList(newRecord("machine/__stmgr__/stmgr-1", infos, Collections.emptyList()));
    PrometheusTestSink sink = new PrometheusTestSink();
    sink.init(defaultConf, context);
    for (MetricsRecord r : records) {
        sink.processRecord(r);
    }
    final String topology = "testTopology";
    final List<String> expectedLines = Arrays.asList(createMetric(topology, "__stmgr__", "stmgr-1", "connection_buffer_by_instanceid_packets", "container_1_word_5", "1.0"), createMetric(topology, "__stmgr__", "stmgr-1", "time_spent_back_pressure_by_compid", "container_1_exclaim1_1", "1.0"), createMetric(topology, "__stmgr__", "stmgr-1", "client_stmgr_ack_tuples_to_stmgrs", "stmgr-92", "1.0"), createMetric(topology, "__stmgr__", "stmgr-1", "instance_bytes_received", "1", "1.0"));
    final Set<String> generatedLines = new HashSet<>(Arrays.asList(new String(sink.generateResponse()).split("\n")));
    assertEquals(expectedLines.size(), generatedLines.size());
    expectedLines.forEach((String line) -> {
        assertTrue(generatedLines.contains(line));
    });
}
Also used : MetricsInfo(org.apache.heron.spi.metricsmgr.metrics.MetricsInfo) MetricsRecord(org.apache.heron.spi.metricsmgr.metrics.MetricsRecord) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 15 with MetricsRecord

use of org.apache.heron.spi.metricsmgr.metrics.MetricsRecord in project heron by twitter.

the class PrometheusSinkTests method testMetricsGrouping.

@Test
public void testMetricsGrouping() {
    PrometheusTestSink sink = new PrometheusTestSink();
    sink.init(defaultConf, context);
    for (MetricsRecord r : records) {
        sink.processRecord(r);
    }
    final Map<String, Map<String, Double>> metrics = sink.getMetrics();
    assertTrue(metrics.containsKey("testTopology/component/instance_1"));
    assertTrue(metrics.containsKey("testTopology/component/instance_2"));
}
Also used : MetricsRecord(org.apache.heron.spi.metricsmgr.metrics.MetricsRecord) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Aggregations

MetricsRecord (org.apache.heron.spi.metricsmgr.metrics.MetricsRecord)15 Test (org.junit.Test)11 MetricsInfo (org.apache.heron.spi.metricsmgr.metrics.MetricsInfo)7 HashMap (java.util.HashMap)6 ExceptionInfo (org.apache.heron.spi.metricsmgr.metrics.ExceptionInfo)4 HashSet (java.util.HashSet)3 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 SinkContext (org.apache.heron.spi.metricsmgr.sink.SinkContext)2 Duration (java.time.Duration)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 MultiCountMetric (org.apache.heron.api.metric.MultiCountMetric)1 Communicator (org.apache.heron.common.basics.Communicator)1 ExecutorLooper (org.apache.heron.common.basics.ExecutorLooper)1 MetricsCollector (org.apache.heron.common.utils.metrics.MetricsCollector)1 SinkExecutor (org.apache.heron.metricsmgr.executor.SinkExecutor)1 SinkContextImpl (org.apache.heron.metricsmgr.sink.SinkContextImpl)1 Metrics (org.apache.heron.proto.system.Metrics)1 IMetricsSink (org.apache.heron.spi.metricsmgr.sink.IMetricsSink)1 Before (org.junit.Before)1