Search in sources :

Example 6 with MetricsRecord

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

the class SinkExecutorTest method constructMetricsRecord.

private MetricsRecord constructMetricsRecord() {
    List<MetricsInfo> metricsInfos = new ArrayList<>();
    // We add N MetricsInfo into a MetricsRecord
    for (int i = 0; i < N; i++) {
        MetricsInfo metricsInfo = new MetricsInfo(METRICS_NAME + i, METRICS_VALUE + i);
        metricsInfos.add(metricsInfo);
    }
    // We add N ExceptionInfo into a MetricsRecord
    List<ExceptionInfo> exceptionInfos = new ArrayList<>();
    for (int i = 0; i < N; i++) {
        String stackTrace = EXCEPTION_STACK_TRACE + i;
        String lastTime = EXCEPTION_LAST_TIME + i;
        String firstTime = EXCEPTION_FIRST_TIME + i;
        String logging = EXCEPTION_LOGGING + i;
        ExceptionInfo info = new ExceptionInfo(stackTrace, lastTime, firstTime, i, logging);
        exceptionInfos.add(info);
    }
    return new MetricsRecord(RECORD_SOURCE, metricsInfos, exceptionInfos, RECORD_CONTEXT);
}
Also used : MetricsInfo(com.twitter.heron.spi.metricsmgr.metrics.MetricsInfo) MetricsRecord(com.twitter.heron.spi.metricsmgr.metrics.MetricsRecord) ArrayList(java.util.ArrayList) ExceptionInfo(com.twitter.heron.spi.metricsmgr.metrics.ExceptionInfo)

Example 7 with MetricsRecord

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

Example 8 with MetricsRecord

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

the class WebSinkTest method testMaxMetrics.

/**
   * Testinging max metics 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);
}
Also used : HashMap(java.util.HashMap) MetricsRecord(com.twitter.heron.spi.metricsmgr.metrics.MetricsRecord) Test(org.junit.Test)

Example 9 with MetricsRecord

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

the class WebSinkTest method testFlatMetrics.

/**
   * Testing flat map with metrics
   */
@Test
public void testFlatMetrics() {
    Map<String, Object> conf = new HashMap<>(defaultConf);
    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("/stuff/record_1/metric_1"), 1.0d);
    Assert.assertEquals(results.get("/stuff/record_1/metric_2"), 2.0d);
    Assert.assertEquals(results.get("/record_2/metric_1"), 1.0d);
    Assert.assertEquals(results.get("/record_2/metric_2"), 2.0d);
}
Also used : HashMap(java.util.HashMap) MetricsRecord(com.twitter.heron.spi.metricsmgr.metrics.MetricsRecord) Test(org.junit.Test)

Example 10 with MetricsRecord

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

the class MetricsManagerServer method handlePublisherPublishMessage.

private void handlePublisherPublishMessage(Metrics.MetricPublisher request, Metrics.MetricPublisherPublishMessage message) {
    if (message.getMetricsCount() <= 0 && message.getExceptionsCount() <= 0) {
        LOG.log(Level.SEVERE, "Publish message has no metrics nor exceptions for message from hostname: {0}," + " component_name: {1}, port: {2}, instance_id: {3}, instance_index: {4}", new Object[] { request.getHostname(), request.getComponentName(), request.getPort(), request.getInstanceId(), request.getInstanceIndex() });
        return;
    }
    // Convert the message to MetricsRecord
    String source = String.format("%s:%d/%s/%s", request.getHostname(), request.getPort(), request.getComponentName(), request.getInstanceId());
    List<MetricsInfo> metricsInfos = new ArrayList<MetricsInfo>(message.getMetricsCount());
    for (Metrics.MetricDatum metricDatum : message.getMetricsList()) {
        MetricsInfo info = new MetricsInfo(metricDatum.getName(), metricDatum.getValue());
        metricsInfos.add(info);
    }
    List<ExceptionInfo> exceptionInfos = new ArrayList<ExceptionInfo>(message.getExceptionsCount());
    for (Metrics.ExceptionData exceptionData : message.getExceptionsList()) {
        ExceptionInfo exceptionInfo = new ExceptionInfo(exceptionData.getStacktrace(), exceptionData.getLasttime(), exceptionData.getFirsttime(), exceptionData.getCount(), exceptionData.getLogging());
        exceptionInfos.add(exceptionInfo);
    }
    LOG.info(String.format("%d MetricsInfo and %d ExceptionInfo to push", metricsInfos.size(), exceptionInfos.size()));
    // Update the metrics
    serverMetricsCounters.scope(SERVER_METRICS_RECEIVED).incrBy(metricsInfos.size());
    serverMetricsCounters.scope(SERVER_EXCEPTIONS_RECEIVED).incrBy(exceptionInfos.size());
    MetricsRecord record = new MetricsRecord(source, metricsInfos, exceptionInfos);
    // Push MetricsRecord to Communicator, which would wake up SlaveLooper bind with IMetricsSink
    for (Communicator<MetricsRecord> c : metricsSinkCommunicators) {
        c.offer(record);
    }
}
Also used : MetricsInfo(com.twitter.heron.spi.metricsmgr.metrics.MetricsInfo) Metrics(com.twitter.heron.proto.system.Metrics) MetricsRecord(com.twitter.heron.spi.metricsmgr.metrics.MetricsRecord) ArrayList(java.util.ArrayList) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) ExceptionInfo(com.twitter.heron.spi.metricsmgr.metrics.ExceptionInfo)

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