use of org.apache.heron.api.metric.MultiCountMetric 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.api.metric.MultiCountMetric in project heron by twitter.
the class MetricsCacheSinkTest method testHandleMetricsCacheLocation.
/**
* Test whether MetricsCacheSink would handle MetricsCacheLocation in SingletonRegistry automatically
*/
@Test
public void testHandleMetricsCacheLocation() throws Exception {
// create a new MetricsCacheClientService
MetricsCacheSink metricsCacheSink = new MetricsCacheSink();
Map<String, Object> sinkConfig = new HashMap<String, Object>();
// Fill with necessary config
sinkConfig.put("metricscache-location-check-interval-sec", METRICSCACHE_LOCATION_CHECK_INTERVAL.getSeconds());
sinkConfig.put("metricscache-client", buildServiceConfig());
// It is null since we have not set it
Assert.assertNull(metricsCacheSink.getCurrentMetricsCacheLocation());
MultiCountMetric multiCountMetric = new MultiCountMetric();
SinkContext sinkContext = new SinkContextImpl("topology-name", "cluster", "role", "environment", "metricsmgr-id", "sink-id", multiCountMetric);
// Start the MetricsCacheSink
metricsCacheSink.init(sinkConfig, sinkContext);
// Put the MetricsCacheLocation into SingletonRegistry
TopologyManager.MetricsCacheLocation oldLoc = getMetricsCacheLocation(0);
SingletonRegistry.INSTANCE.registerSingleton(METRICSCACHE_LOCATION_BEAN_NAME, oldLoc);
SysUtils.sleep(RESTART_WAIT_INTERVAL);
// The MetricsCacheService should start
assertTrue(metricsCacheSink.getMetricsCacheStartedAttempts() > 0);
assertEquals(oldLoc, metricsCacheSink.getCurrentMetricsCacheLocation());
assertEquals(oldLoc, metricsCacheSink.getCurrentMetricsCacheLocationInService());
// Update it, the MetricsCacheSink should pick up the new one.
TopologyManager.MetricsCacheLocation newLoc = getMetricsCacheLocation(1);
SingletonRegistry.INSTANCE.updateSingleton(METRICSCACHE_LOCATION_BEAN_NAME, newLoc);
int lastMetricsCacheStartedAttempts = metricsCacheSink.getMetricsCacheStartedAttempts();
SysUtils.sleep(RESTART_WAIT_INTERVAL);
// The MetricsCacheService should use the new MetricsCacheLocation
assertTrue(metricsCacheSink.getMetricsCacheStartedAttempts() > lastMetricsCacheStartedAttempts);
assertNotSame(oldLoc, metricsCacheSink.getCurrentMetricsCacheLocation());
assertNotSame(oldLoc, metricsCacheSink.getCurrentMetricsCacheLocationInService());
assertEquals(newLoc, metricsCacheSink.getCurrentMetricsCacheLocation());
assertEquals(newLoc, metricsCacheSink.getCurrentMetricsCacheLocationInService());
metricsCacheSink.close();
}
use of org.apache.heron.api.metric.MultiCountMetric in project heron by twitter.
the class TManagerSinkTest method testHandleTManagerLocation.
/**
* Test whether TManagerSink would handle TManagerLocation in SingletonRegistry automatically
*/
@Test
public void testHandleTManagerLocation() throws InterruptedException {
// create a new TManagerClientService
TManagerSink tManagerSink = new TManagerSink();
Map<String, Object> sinkConfig = new HashMap<>();
// Fill with necessary config
sinkConfig.put("tmanager-location-check-interval-sec", TMANAGER_LOCATION_CHECK_INTERVAL.getSeconds());
sinkConfig.put("tmanager-client", buildServiceConfig());
// It is null since we have not set it
Assert.assertNull(tManagerSink.getCurrentTManagerLocation());
MultiCountMetric multiCountMetric = new MultiCountMetric();
SinkContext sinkContext = new SinkContextImpl("topology-name", "cluster", "role", "environment", "metricsmgr-id", "sink-id", multiCountMetric);
// Start the TManagerSink
tManagerSink.init(sinkConfig, sinkContext);
// Put the TManagerLocation into SingletonRegistry
TopologyManager.TManagerLocation oldLoc = getTManagerLocation(0);
SingletonRegistry.INSTANCE.registerSingleton(TMANAGER_LOCATION_BEAN_NAME, oldLoc);
SysUtils.sleep(RESTART_WAIT_INTERVAL);
// The TManagerService should start
assertTrue(tManagerSink.getTManagerStartedAttempts() > 0);
assertEquals(oldLoc, tManagerSink.getCurrentTManagerLocation());
assertEquals(oldLoc, tManagerSink.getCurrentTManagerLocationInService());
// Update it, the TManagerSink should pick up the new one.
TopologyManager.TManagerLocation newLoc = getTManagerLocation(1);
SingletonRegistry.INSTANCE.updateSingleton(TMANAGER_LOCATION_BEAN_NAME, newLoc);
int lastTManagerStartedAttempts = tManagerSink.getTManagerStartedAttempts();
SysUtils.sleep(RESTART_WAIT_INTERVAL);
// The TManagerService should use the new TManagerLocation
assertTrue(tManagerSink.getTManagerStartedAttempts() > lastTManagerStartedAttempts);
assertNotSame(oldLoc, tManagerSink.getCurrentTManagerLocation());
assertNotSame(oldLoc, tManagerSink.getCurrentTManagerLocationInService());
assertEquals(newLoc, tManagerSink.getCurrentTManagerLocation());
assertEquals(newLoc, tManagerSink.getCurrentTManagerLocationInService());
tManagerSink.close();
}
use of org.apache.heron.api.metric.MultiCountMetric in project heron by twitter.
the class MetricsManagerServerTest method before.
@Before
public void before() throws IOException {
metricsManagerServer = new MetricsManagerServer(new NIOLooper(), HeronServerTester.SERVER_HOST, SysUtils.getFreePort(), HeronServerTester.TEST_SOCKET_OPTIONS, new MultiCountMetric());
serverTester = new HeronServerTester(metricsManagerServer, new MetricsManagerClientRequestHandler(), new HeronServerTester.SuccessResponseHandler(Metrics.MetricPublisherRegisterResponse.class, new MetricsManagerClientResponseHandler(MESSAGE_SIZE)), RESPONSE_RECEIVED_TIMEOUT);
}
use of org.apache.heron.api.metric.MultiCountMetric in project heron by twitter.
the class SinkExecutorTest method before.
@Before
public void before() throws Exception {
metricsSink = new DummyMetricsSink(EXPECTED_RECORDS, EXPECTED_FLUSHES);
executorLooper = new ExecutorLooper();
communicator = new Communicator<>(null, executorLooper);
SinkContext sinkContext = new SinkContextImpl("topology-name", "cluster", "role", "environment", "metricsmgr-id", "sink-id", new MultiCountMetric());
sinkExecutor = new SinkExecutor("testSinkId", metricsSink, executorLooper, communicator, sinkContext);
}
Aggregations