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