Search in sources :

Example 1 with MetricsCollector

use of com.twitter.heron.common.utils.metrics.MetricsCollector 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.");
    }
    SlaveLooper sinkExecutorLoop = new SlaveLooper();
    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, heronMetricsExportIntervalSec);
    // Set up the SinkContext
    SinkContext sinkContext = new SinkContextImpl(topologyName, metricsmgrId, sinkId, internalCounters);
    SinkExecutor sinkExecutor = new SinkExecutor(sinkId, sink, sinkExecutorLoop, executorInMetricsQueue, sinkContext);
    sinkExecutor.setPropertyMap(config.getConfigForSink(sinkId));
    return sinkExecutor;
}
Also used : IMetricsSink(com.twitter.heron.spi.metricsmgr.sink.IMetricsSink) MetricsCollector(com.twitter.heron.common.utils.metrics.MetricsCollector) Communicator(com.twitter.heron.common.basics.Communicator) MetricsRecord(com.twitter.heron.spi.metricsmgr.metrics.MetricsRecord) SinkContext(com.twitter.heron.spi.metricsmgr.sink.SinkContext) SinkExecutor(com.twitter.heron.metricsmgr.executor.SinkExecutor) MultiCountMetric(com.twitter.heron.api.metric.MultiCountMetric) SinkContextImpl(com.twitter.heron.metricsmgr.sink.SinkContextImpl) SlaveLooper(com.twitter.heron.common.basics.SlaveLooper)

Example 2 with MetricsCollector

use of com.twitter.heron.common.utils.metrics.MetricsCollector in project heron by twitter.

the class GlobalMetricsTest method testGlobalMetrics.

@Test
public void testGlobalMetrics() {
    MetricsCollector fakeCollector = new MetricsCollector(new FakeWakeableLooper(), null);
    TopologyContext fakeContext = new TopologyContextImpl(new HashMap<String, Object>(), TopologyAPI.Topology.getDefaultInstance(), new HashMap<Integer, String>(), 0, fakeCollector);
    GlobalMetrics.init(fakeContext, 5);
    GlobalMetrics.incr("mycounter");
    Map<String, Long> metricsContent = GlobalMetrics.getUnderlyingCounter().getValueAndReset();
    assertTrue(metricsContent.containsKey("mycounter"));
    assertEquals(1, metricsContent.size());
    assertEquals(new Long(1), metricsContent.get("mycounter"));
    // Increment two different counters
    GlobalMetrics.incr("mycounter1");
    GlobalMetrics.incr("mycounter2");
    GlobalMetrics.incr("mycounter1");
    metricsContent = GlobalMetrics.getUnderlyingCounter().getValueAndReset();
    assertTrue(metricsContent.containsKey("mycounter"));
    assertTrue(metricsContent.containsKey("mycounter1"));
    assertTrue(metricsContent.containsKey("mycounter2"));
    assertEquals(3L, metricsContent.size());
    assertEquals(new Long(0), metricsContent.get("mycounter"));
    assertEquals(new Long(1), metricsContent.get("mycounter2"));
    assertEquals(new Long(2), metricsContent.get("mycounter1"));
}
Also used : MetricsCollector(com.twitter.heron.common.utils.metrics.MetricsCollector) TopologyContextImpl(com.twitter.heron.common.utils.topology.TopologyContextImpl) TopologyContext(com.twitter.heron.api.topology.TopologyContext) Test(org.junit.Test)

Example 3 with MetricsCollector

use of com.twitter.heron.common.utils.metrics.MetricsCollector in project heron by twitter.

the class InstanceExecutorTest method testCreatePhysicalPlanHelper.

/**
   * Method: createPhysicalPlanHelper(PhysicalPlans.PhysicalPlan physicalPlan, String instanceId, MetricsCollector metricsCollector)
   */
@Test
public void testCreatePhysicalPlanHelper() throws Exception {
    PhysicalPlanHelper physicalPlanHelper = instanceExecutor.createPhysicalPlanHelper(plan, instanceId, Mockito.mock(MetricsCollector.class));
    Assert.assertNotNull(physicalPlanHelper.getTopologyContext());
}
Also used : MetricsCollector(com.twitter.heron.common.utils.metrics.MetricsCollector) PhysicalPlanHelper(com.twitter.heron.common.utils.misc.PhysicalPlanHelper) Test(org.junit.Test) PhysicalPlanUtilTest(com.twitter.heron.simulator.utils.PhysicalPlanUtilTest)

Example 4 with MetricsCollector

use of com.twitter.heron.common.utils.metrics.MetricsCollector in project incubator-heron by apache.

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.");
    }
    SlaveLooper sinkExecutorLoop = new SlaveLooper();
    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(com.twitter.heron.spi.metricsmgr.sink.IMetricsSink) MetricsCollector(com.twitter.heron.common.utils.metrics.MetricsCollector) Communicator(com.twitter.heron.common.basics.Communicator) MetricsRecord(com.twitter.heron.spi.metricsmgr.metrics.MetricsRecord) SinkContext(com.twitter.heron.spi.metricsmgr.sink.SinkContext) SinkExecutor(com.twitter.heron.metricsmgr.executor.SinkExecutor) MultiCountMetric(com.twitter.heron.api.metric.MultiCountMetric) SinkContextImpl(com.twitter.heron.metricsmgr.sink.SinkContextImpl) SlaveLooper(com.twitter.heron.common.basics.SlaveLooper)

Example 5 with MetricsCollector

use of com.twitter.heron.common.utils.metrics.MetricsCollector in project incubator-heron by apache.

the class InstanceExecutorTest method testCreatePhysicalPlanHelper.

/**
 * Method: createPhysicalPlanHelper(PhysicalPlans.PhysicalPlan physicalPlan, String instanceId, MetricsCollector metricsCollector)
 */
@Test
public void testCreatePhysicalPlanHelper() throws Exception {
    PhysicalPlanHelper physicalPlanHelper = instanceExecutor.createPhysicalPlanHelper(plan, instanceId, Mockito.mock(MetricsCollector.class));
    Assert.assertNotNull(physicalPlanHelper.getTopologyContext());
}
Also used : MetricsCollector(com.twitter.heron.common.utils.metrics.MetricsCollector) PhysicalPlanHelper(com.twitter.heron.common.utils.misc.PhysicalPlanHelper) Test(org.junit.Test) TopologyManagerTest(com.twitter.heron.simulator.utils.TopologyManagerTest)

Aggregations

MetricsCollector (com.twitter.heron.common.utils.metrics.MetricsCollector)7 Test (org.junit.Test)4 MultiCountMetric (com.twitter.heron.api.metric.MultiCountMetric)2 TopologyContext (com.twitter.heron.api.topology.TopologyContext)2 Communicator (com.twitter.heron.common.basics.Communicator)2 SlaveLooper (com.twitter.heron.common.basics.SlaveLooper)2 PhysicalPlanHelper (com.twitter.heron.common.utils.misc.PhysicalPlanHelper)2 TopologyContextImpl (com.twitter.heron.common.utils.topology.TopologyContextImpl)2 SinkExecutor (com.twitter.heron.metricsmgr.executor.SinkExecutor)2 SinkContextImpl (com.twitter.heron.metricsmgr.sink.SinkContextImpl)2 MetricsRecord (com.twitter.heron.spi.metricsmgr.metrics.MetricsRecord)2 IMetricsSink (com.twitter.heron.spi.metricsmgr.sink.IMetricsSink)2 SinkContext (com.twitter.heron.spi.metricsmgr.sink.SinkContext)2 PhysicalPlanUtilTest (com.twitter.heron.simulator.utils.PhysicalPlanUtilTest)1 TopologyManagerTest (com.twitter.heron.simulator.utils.TopologyManagerTest)1