Search in sources :

Example 1 with MetricsRecord

use of com.twitter.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);
}
Also used : MetricsInfo(com.twitter.heron.spi.metricsmgr.metrics.MetricsInfo) HashMap(java.util.HashMap) MetricsRecord(com.twitter.heron.spi.metricsmgr.metrics.MetricsRecord) HashMap(java.util.HashMap) Map(java.util.Map) ExceptionInfo(com.twitter.heron.spi.metricsmgr.metrics.ExceptionInfo) Test(org.junit.Test)

Example 2 with MetricsRecord

use of com.twitter.heron.spi.metricsmgr.metrics.MetricsRecord in project heron by twitter.

the class WebSinkTest method testTTLMetrics.

/**
   * Testinging TTL
   */
@Test
public void testTTLMetrics() throws InterruptedException {
    Map<String, Object> conf = new HashMap<>(defaultConf);
    conf.put("metrics-cache-ttl-sec", "1");
    WebTestSink sink = new WebTestSink();
    sink.init(conf, context);
    for (MetricsRecord r : records) {
        sink.processRecord(r);
    }
    Thread.sleep(1100);
    sink.syncCache();
    Map<String, Object> results = sink.getMetrics();
    Assert.assertEquals(0, results.size());
}
Also used : HashMap(java.util.HashMap) MetricsRecord(com.twitter.heron.spi.metricsmgr.metrics.MetricsRecord) Test(org.junit.Test)

Example 3 with MetricsRecord

use of com.twitter.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.");
    }
    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 4 with MetricsRecord

use of com.twitter.heron.spi.metricsmgr.metrics.MetricsRecord in project heron by twitter.

the class MetricsManagerServerTest method testMetricsManagerServer.

/**
   * Method: addSinkCommunicator(Communicator&lt;MetricsRecord&gt; communicator)
   */
@Test
public void testMetricsManagerServer() throws Exception {
    final Communicator<MetricsRecord> sinkCommunicator = new Communicator<MetricsRecord>();
    metricsManagerServer.addSinkCommunicator(sinkCommunicator);
    // First run Server
    runServer();
    // Wait a while for server fully starting
    Thread.sleep(3 * 1000);
    // Then run Client
    runClient();
    // Wait some while to let message fully send out
    Thread.sleep(10 * 1000);
    int messages = 0;
    while (!sinkCommunicator.isEmpty()) {
        int exceptions = 0;
        int metrics = 0;
        MetricsRecord record = sinkCommunicator.poll();
        Assert.assertEquals("hostname:0/component/instance-id", record.getSource());
        Assert.assertEquals("default", record.getContext());
        for (MetricsInfo info : record.getMetrics()) {
            Assert.assertEquals(METRIC_NAME, info.getName());
            Assert.assertEquals(METRIC_VALUE, info.getValue());
            metrics++;
        }
        Assert.assertEquals(N, metrics);
        for (ExceptionInfo info : record.getExceptions()) {
            Assert.assertEquals(STACK_TRACE, info.getStackTrace());
            Assert.assertEquals(LAST_TIME, info.getLastTime());
            Assert.assertEquals(FIRST_TIME, info.getFirstTime());
            Assert.assertEquals(LOGGING, info.getLogging());
            Assert.assertEquals(EXCEPTION_COUNT, info.getCount());
            exceptions++;
        }
        Assert.assertEquals(N, exceptions);
        messages++;
    }
    Assert.assertEquals(MESSAGE_SIZE, messages);
}
Also used : MetricsInfo(com.twitter.heron.spi.metricsmgr.metrics.MetricsInfo) Communicator(com.twitter.heron.common.basics.Communicator) MetricsRecord(com.twitter.heron.spi.metricsmgr.metrics.MetricsRecord) ExceptionInfo(com.twitter.heron.spi.metricsmgr.metrics.ExceptionInfo) Test(org.junit.Test)

Example 5 with MetricsRecord

use of com.twitter.heron.spi.metricsmgr.metrics.MetricsRecord in project heron by twitter.

the class WebSinkTest method before.

@Before
public void before() throws IOException {
    defaultConf = new HashMap<>();
    defaultConf.put("port", "9999");
    defaultConf.put("path", "test");
    defaultConf.put("flat-metrics", "true");
    defaultConf.put("include-topology-name", "false");
    context = Mockito.mock(SinkContext.class);
    Mockito.when(context.getTopologyName()).thenReturn("testTopology");
    Mockito.when(context.getSinkId()).thenReturn("testId");
    Iterable<MetricsInfo> infos = Arrays.asList(new MetricsInfo("metric_1", "1.0"), new MetricsInfo("metric_2", "2.0"));
    records = Arrays.asList(new MetricsRecord("machine/stuff/record_1", infos, Collections.<ExceptionInfo>emptyList()), new MetricsRecord("record_2", infos, Collections.<ExceptionInfo>emptyList()));
}
Also used : MetricsInfo(com.twitter.heron.spi.metricsmgr.metrics.MetricsInfo) SinkContext(com.twitter.heron.spi.metricsmgr.sink.SinkContext) MetricsRecord(com.twitter.heron.spi.metricsmgr.metrics.MetricsRecord) Before(org.junit.Before)

Aggregations

MetricsRecord (com.twitter.heron.spi.metricsmgr.metrics.MetricsRecord)10 Test (org.junit.Test)6 MetricsInfo (com.twitter.heron.spi.metricsmgr.metrics.MetricsInfo)5 HashMap (java.util.HashMap)5 ExceptionInfo (com.twitter.heron.spi.metricsmgr.metrics.ExceptionInfo)4 Communicator (com.twitter.heron.common.basics.Communicator)2 SinkContext (com.twitter.heron.spi.metricsmgr.sink.SinkContext)2 ArrayList (java.util.ArrayList)2 MultiCountMetric (com.twitter.heron.api.metric.MultiCountMetric)1 SlaveLooper (com.twitter.heron.common.basics.SlaveLooper)1 MetricsCollector (com.twitter.heron.common.utils.metrics.MetricsCollector)1 SinkExecutor (com.twitter.heron.metricsmgr.executor.SinkExecutor)1 SinkContextImpl (com.twitter.heron.metricsmgr.sink.SinkContextImpl)1 Metrics (com.twitter.heron.proto.system.Metrics)1 IMetricsSink (com.twitter.heron.spi.metricsmgr.sink.IMetricsSink)1 Map (java.util.Map)1 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)1 Before (org.junit.Before)1