Search in sources :

Example 1 with MetricsRecord

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

the class MetricsManager method initSinkExecutor.

private SinkExecutor initSinkExecutor(String sinkId) {
    IMetricsSink sink;
    String classname = (String) config.getConfigForSink(sinkId).get(MetricsSinksConfig.CONFIG_KEY_CLASSNAME);
    try {
        sink = (IMetricsSink) Class.forName(classname).newInstance();
    } catch (InstantiationException e) {
        throw new RuntimeException(e + " IMetricsSink class must have a no-arg constructor.");
    } catch (IllegalAccessException e) {
        throw new RuntimeException(e + " IMetricsSink class must be concrete.");
    } catch (ClassNotFoundException e) {
        throw new RuntimeException(e + " IMetricsSink class must be a class path.");
    }
    ExecutorLooper sinkExecutorLoop = new ExecutorLooper();
    Communicator<MetricsRecord> executorInMetricsQueue = new Communicator<MetricsRecord>(null, sinkExecutorLoop);
    // Since MetricsCollector is not thread-safe,
    // we need to specify individual MetricsCollector and MultiCountMetric
    // for different SinkExecutor
    MetricsCollector sinkMetricsCollector = new MetricsCollector(sinkExecutorLoop, metricsQueue);
    MultiCountMetric internalCounters = new MultiCountMetric();
    sinkMetricsCollector.registerMetric(sinkId, internalCounters, (int) heronMetricsExportInterval.getSeconds());
    // Set up the SinkContext
    SinkContext sinkContext = new SinkContextImpl(topologyName, cluster, role, environment, metricsmgrId, sinkId, internalCounters);
    SinkExecutor sinkExecutor = new SinkExecutor(sinkId, sink, sinkExecutorLoop, executorInMetricsQueue, sinkContext);
    sinkExecutor.setPropertyMap(config.getConfigForSink(sinkId));
    return sinkExecutor;
}
Also used : IMetricsSink(org.apache.heron.spi.metricsmgr.sink.IMetricsSink) MetricsCollector(org.apache.heron.common.utils.metrics.MetricsCollector) Communicator(org.apache.heron.common.basics.Communicator) MetricsRecord(org.apache.heron.spi.metricsmgr.metrics.MetricsRecord) SinkContext(org.apache.heron.spi.metricsmgr.sink.SinkContext) SinkExecutor(org.apache.heron.metricsmgr.executor.SinkExecutor) MultiCountMetric(org.apache.heron.api.metric.MultiCountMetric) ExecutorLooper(org.apache.heron.common.basics.ExecutorLooper) SinkContextImpl(org.apache.heron.metricsmgr.sink.SinkContextImpl)

Example 2 with MetricsRecord

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

the class MetricsUtilTests method testSplitRecordSource.

@Test
public void testSplitRecordSource() {
    final String source = MetricsUtil.createSource(host, port, component, instance);
    MetricsRecord record = Mockito.mock(MetricsRecord.class);
    Mockito.when(record.getSource()).thenReturn(source);
    final String[] sourceComponents = MetricsUtil.splitRecordSource(record);
    assertEquals(3, sourceComponents.length);
    assertEquals(String.format("%s:%d", host, port), sourceComponents[0]);
    assertEquals(component, sourceComponents[1]);
    assertEquals(instance, sourceComponents[2]);
}
Also used : MetricsRecord(org.apache.heron.spi.metricsmgr.metrics.MetricsRecord) Test(org.junit.Test)

Example 3 with MetricsRecord

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

the class WebSinkTest method testGroupedMetrics.

/**
 * Testing grouped map with metrics
 */
@Test
public void testGroupedMetrics() {
    Map<String, Object> conf = new HashMap<>(defaultConf);
    conf.put("flat-metrics", "false");
    WebTestSink sink = new WebTestSink();
    sink.init(conf, context);
    for (MetricsRecord r : records) {
        sink.processRecord(r);
    }
    // Update and override MetricsRecord 1
    Iterable<MetricsInfo> infos2 = Arrays.asList(new MetricsInfo("metric_1", "3.0"), new MetricsInfo("metric_3", "1.0"));
    sink.processRecord(new MetricsRecord(records.get(0).getSource(), infos2, Collections.<ExceptionInfo>emptyList()));
    Map<String, Object> results = sink.getMetrics();
    Assert.assertEquals(2, results.size());
    @SuppressWarnings("unchecked") Map<String, Object> record1 = (Map<String, Object>) results.get("/stuff/record_1");
    @SuppressWarnings("unchecked") Map<String, Object> record2 = (Map<String, Object>) results.get("/record_2");
    Assert.assertEquals(record1.get("metric_1"), 3.0d);
    Assert.assertEquals(record1.get("metric_2"), 2.0d);
    Assert.assertEquals(record1.get("metric_3"), 1.0d);
    Assert.assertEquals(record2.get("metric_1"), 1.0d);
    Assert.assertEquals(record2.get("metric_2"), 2.0d);
}
Also used : MetricsInfo(org.apache.heron.spi.metricsmgr.metrics.MetricsInfo) HashMap(java.util.HashMap) MetricsRecord(org.apache.heron.spi.metricsmgr.metrics.MetricsRecord) HashMap(java.util.HashMap) Map(java.util.Map) ExceptionInfo(org.apache.heron.spi.metricsmgr.metrics.ExceptionInfo) Test(org.junit.Test)

Example 4 with MetricsRecord

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

the class WebSinkTest method testIncludeTopologyName.

/**
 * Testing flat map with metrics, prefixed with topology name
 */
@Test
public void testIncludeTopologyName() {
    Map<String, Object> conf = new HashMap<>(defaultConf);
    conf.put("include-topology-name", "true");
    WebTestSink sink = new WebTestSink();
    sink.init(conf, context);
    for (MetricsRecord r : records) {
        sink.processRecord(r);
    }
    Map<String, Object> results = sink.getMetrics();
    Assert.assertEquals(4, results.size());
    Assert.assertEquals(results.get("testTopology/stuff/record_1/metric_1"), 1.0d);
    Assert.assertEquals(results.get("testTopology/stuff/record_1/metric_2"), 2.0d);
    Assert.assertEquals(results.get("testTopology/record_2/metric_1"), 1.0d);
    Assert.assertEquals(results.get("testTopology/record_2/metric_2"), 2.0d);
}
Also used : HashMap(java.util.HashMap) MetricsRecord(org.apache.heron.spi.metricsmgr.metrics.MetricsRecord) Test(org.junit.Test)

Example 5 with MetricsRecord

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

the class WebSinkTest method testMaxMetrics.

/**
 * Testing max metrics size, and oldest keys get expired
 */
@Test
public void testMaxMetrics() {
    Map<String, Object> conf = new HashMap<>(defaultConf);
    conf.put("metrics-cache-max-size", "2");
    WebTestSink sink = new WebTestSink();
    sink.init(conf, context);
    for (MetricsRecord r : records) {
        sink.processRecord(r);
    }
    Map<String, Object> results = sink.getMetrics();
    Assert.assertEquals(2, results.size());
    Assert.assertEquals(results.get("/record_2/metric_1"), 1.0d);
    Assert.assertEquals(results.get("/record_2/metric_2"), 2.0d);
}
Also used : HashMap(java.util.HashMap) MetricsRecord(org.apache.heron.spi.metricsmgr.metrics.MetricsRecord) 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