use of org.apache.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.");
}
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;
}
use of org.apache.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, Duration.ofSeconds(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"));
}
use of org.apache.heron.common.utils.metrics.MetricsCollector in project heron by twitter.
the class Executor method registerTasksWithExecutor.
private void registerTasksWithExecutor() {
// Create a new MetricsCollector with the clean executorLooper and register its task
metricsCollector = new MetricsCollector(executorLooper, metricsOutCommunicator);
// registering the handling of control msg
handleControlMessage();
// instance task will be registered when instance.start() is called
}
use of org.apache.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());
}
Aggregations