Search in sources :

Example 1 with MultiCountMetric

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;
}
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 MultiCountMetric

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();
}
Also used : TopologyManager(org.apache.heron.proto.tmanager.TopologyManager) HashMap(java.util.HashMap) SinkContext(org.apache.heron.spi.metricsmgr.sink.SinkContext) SinkContextImpl(org.apache.heron.metricsmgr.sink.SinkContextImpl) MultiCountMetric(org.apache.heron.api.metric.MultiCountMetric) Test(org.junit.Test)

Example 3 with MultiCountMetric

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();
}
Also used : TopologyManager(org.apache.heron.proto.tmanager.TopologyManager) HashMap(java.util.HashMap) SinkContext(org.apache.heron.spi.metricsmgr.sink.SinkContext) SinkContextImpl(org.apache.heron.metricsmgr.sink.SinkContextImpl) MultiCountMetric(org.apache.heron.api.metric.MultiCountMetric) Test(org.junit.Test)

Example 4 with MultiCountMetric

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);
}
Also used : Metrics(org.apache.heron.proto.system.Metrics) NIOLooper(org.apache.heron.common.basics.NIOLooper) MultiCountMetric(org.apache.heron.api.metric.MultiCountMetric) HeronServerTester(org.apache.heron.common.testhelpers.HeronServerTester) Before(org.junit.Before)

Example 5 with MultiCountMetric

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);
}
Also used : ExecutorLooper(org.apache.heron.common.basics.ExecutorLooper) SinkContext(org.apache.heron.spi.metricsmgr.sink.SinkContext) SinkContextImpl(org.apache.heron.metricsmgr.sink.SinkContextImpl) MultiCountMetric(org.apache.heron.api.metric.MultiCountMetric) Before(org.junit.Before)

Aggregations

MultiCountMetric (org.apache.heron.api.metric.MultiCountMetric)5 SinkContextImpl (org.apache.heron.metricsmgr.sink.SinkContextImpl)4 SinkContext (org.apache.heron.spi.metricsmgr.sink.SinkContext)4 HashMap (java.util.HashMap)2 ExecutorLooper (org.apache.heron.common.basics.ExecutorLooper)2 TopologyManager (org.apache.heron.proto.tmanager.TopologyManager)2 Before (org.junit.Before)2 Test (org.junit.Test)2 Communicator (org.apache.heron.common.basics.Communicator)1 NIOLooper (org.apache.heron.common.basics.NIOLooper)1 HeronServerTester (org.apache.heron.common.testhelpers.HeronServerTester)1 MetricsCollector (org.apache.heron.common.utils.metrics.MetricsCollector)1 SinkExecutor (org.apache.heron.metricsmgr.executor.SinkExecutor)1 Metrics (org.apache.heron.proto.system.Metrics)1 MetricsRecord (org.apache.heron.spi.metricsmgr.metrics.MetricsRecord)1 IMetricsSink (org.apache.heron.spi.metricsmgr.sink.IMetricsSink)1