Search in sources :

Example 6 with Stat

use of com.nextdoor.bender.monitoring.Stat in project bender by Nextdoor.

the class SerializerProcessorTest method testSerializeNull.

@Test
public void testSerializeNull() {
    DummySerializer serializer = mock(DummySerializer.class);
    SerializerProcessor processor = new SerializerProcessor(serializer);
    doThrow(new RuntimeException()).when(serializer).serialize(null);
    /*
     * Mock the Stat object
     */
    Stat runtimeStat = mock(Stat.class);
    Stat successStat = mock(Stat.class);
    Stat errorStat = mock(Stat.class);
    processor.setRuntimeStat(runtimeStat);
    processor.setSuccessCountStat(successStat);
    processor.setErrorCountStat(errorStat);
    try {
        processor.serialize(null);
    } catch (Exception e) {
    // expected
    }
    /*
     * Verify start, stop are called, increment error count and never increment success count.
     */
    verify(runtimeStat, times(1)).start();
    verify(runtimeStat, times(1)).stop();
    verify(successStat, never()).increment();
    verify(errorStat, times(1)).increment();
}
Also used : DummySerializer(com.nextdoor.bender.testutils.DummySerializerHelper.DummySerializer) Stat(com.nextdoor.bender.monitoring.Stat) Test(org.junit.Test)

Example 7 with Stat

use of com.nextdoor.bender.monitoring.Stat in project bender by Nextdoor.

the class CloudwatchReporter method write.

@Override
public void write(ArrayList<Stat> stats, long invokeTimeMs, Set<Tag> tags) {
    Date dt = new Date();
    dt.setTime(invokeTimeMs);
    Collection<Dimension> parentDims = tagsToDimensions(tags);
    List<MetricDatum> metrics = new ArrayList<MetricDatum>();
    /*
     * Create CW metric objects from bender internal Stat objects
     */
    for (Stat stat : stats) {
        /*
       * Dimension are CW's version of metric tags. A conversion must be done.
       */
        Collection<Dimension> metricDims = tagsToDimensions(stat.getTags());
        metricDims.addAll(parentDims);
        MetricDatum metric = new MetricDatum();
        metric.setMetricName(stat.getName());
        // TODO: add units to Stat object SYSTEMS-870
        metric.setUnit(StandardUnit.None);
        metric.setTimestamp(dt);
        metric.setDimensions(metricDims);
        metric.setValue((double) stat.getValue());
        metrics.add(metric);
    }
    /*
     * Not very well documented in java docs but CW only allows 20 metrics at a time.
     */
    List<List<MetricDatum>> chunks = ListUtils.partition(metrics, 20);
    for (List<MetricDatum> chunk : chunks) {
        PutMetricDataRequest req = new PutMetricDataRequest();
        req.withMetricData(chunk);
        req.setNamespace(namespace);
        this.client.putMetricData(req);
    }
}
Also used : Stat(com.nextdoor.bender.monitoring.Stat) PutMetricDataRequest(com.amazonaws.services.cloudwatch.model.PutMetricDataRequest) ArrayList(java.util.ArrayList) MetricDatum(com.amazonaws.services.cloudwatch.model.MetricDatum) ArrayList(java.util.ArrayList) List(java.util.List) Dimension(com.amazonaws.services.cloudwatch.model.Dimension) Date(java.util.Date)

Example 8 with Stat

use of com.nextdoor.bender.monitoring.Stat in project bender by Nextdoor.

the class BaseHandler method writeStats.

private void writeStats(long evtCount, long oldestArrivalTime, long oldestOccurrenceTime, String source, Stat runtime) {
    /*
     * Add some stats about this invocation
     */
    Stat eventCount = new Stat("event.count", evtCount, Stat.MetricType.count);
    Stat spoutLag = new Stat("spout.lag.ms", (System.currentTimeMillis() - oldestArrivalTime), Stat.MetricType.gauge);
    Stat sourceLag = new Stat("source.lag.ms", (System.currentTimeMillis() - oldestOccurrenceTime), Stat.MetricType.gauge);
    eventCount.addTag("source", source);
    spoutLag.addTag("source", source);
    sourceLag.addTag("source", source);
    runtime.addTag("source", source);
    this.monitor.addInvocationStat(eventCount);
    this.monitor.addInvocationStat(spoutLag);
    this.monitor.addInvocationStat(sourceLag);
    this.monitor.addInvocationStat(runtime);
    /*
     * Report stats
     */
    this.monitor.writeStats();
}
Also used : Stat(com.nextdoor.bender.monitoring.Stat)

Example 9 with Stat

use of com.nextdoor.bender.monitoring.Stat in project bender by Nextdoor.

the class IpcSenderServiceTest method testStatsLogging.

@Test
public void testStatsLogging() throws InstantiationException, IllegalAccessException, InterruptedException, TransportException {
    DummyTransporterFactory tfactory = new DummyTransporterFactory();
    tfactory.transporter = new DummyTransporter();
    IpcSenderService ipc = new IpcSenderService(tfactory);
    /*
     * Mock the Stat object
     */
    Stat runtimeStat = mock(Stat.class);
    Stat forkedRuntimeStat = mock(Stat.class);
    when(runtimeStat.fork()).thenReturn(forkedRuntimeStat);
    Stat successStat = mock(Stat.class);
    Stat errorStat = mock(Stat.class);
    ipc.setRuntimeStat(runtimeStat);
    ipc.setSuccessCountStat(successStat);
    ipc.setErrorCountStat(errorStat);
    /*
     * Every 5 adds a send should happen.
     */
    for (int i = 0; i < 12; i++) {
        ipc.add(mock(InternalEvent.class));
    }
    ipc.shutdown();
    /*
     * Service should create three runnables and each will fork the stats object and call start,
     * stop, and increment success. On service shutdown the join method should only be called once.
     */
    verify(runtimeStat, times(3)).fork();
    verify(forkedRuntimeStat, times(3)).start();
    verify(forkedRuntimeStat, times(3)).stop();
    verify(runtimeStat, times(1)).join();
    verify(successStat, times(3)).increment();
    verify(errorStat, never()).increment();
}
Also used : Stat(com.nextdoor.bender.monitoring.Stat) InternalEvent(com.nextdoor.bender.InternalEvent) Test(org.junit.Test)

Example 10 with Stat

use of com.nextdoor.bender.monitoring.Stat in project bender by Nextdoor.

the class DeserializerProcessorTest method testStatsLoggingOnError.

@Test
public void testStatsLoggingOnError() {
    DummyDeserializer mockDeser = mock(DummyDeserializer.class);
    when(mockDeser.deserialize("foo")).thenThrow(new DeserializationException(new RuntimeException("expected")));
    DeserializerProcessor deser = new DeserializerProcessor(mockDeser);
    /*
     * Mock the Stat object
     */
    Stat runtimeStat = mock(Stat.class);
    Stat successStat = mock(Stat.class);
    Stat errorStat = mock(Stat.class);
    deser.setRuntimeStat(runtimeStat);
    deser.setSuccessCountStat(successStat);
    deser.setErrorCountStat(errorStat);
    try {
        deser.deserialize("foo");
    } catch (DeserializationException e) {
    // expected
    }
    /*
     * Verify start, stop are called, increment error count and never increment success count.
     */
    verify(runtimeStat, times(1)).start();
    verify(runtimeStat, times(1)).stop();
    verify(successStat, never()).increment();
    verify(errorStat, times(1)).increment();
}
Also used : DummyDeserializer(com.nextdoor.bender.testutils.DummyDeserializerHelper.DummyDeserializer) Stat(com.nextdoor.bender.monitoring.Stat) Test(org.junit.Test)

Aggregations

Stat (com.nextdoor.bender.monitoring.Stat)14 Test (org.junit.Test)10 InternalEvent (com.nextdoor.bender.InternalEvent)5 DummyDeserializer (com.nextdoor.bender.testutils.DummyDeserializerHelper.DummyDeserializer)3 DummySerializer (com.nextdoor.bender.testutils.DummySerializerHelper.DummySerializer)3 ArrayList (java.util.ArrayList)3 List (java.util.List)3 DummyOperationFactory (com.nextdoor.bender.testutils.DummyOperationHelper.DummyOperationFactory)2 Dimension (com.amazonaws.services.cloudwatch.model.Dimension)1 MetricDatum (com.amazonaws.services.cloudwatch.model.MetricDatum)1 PutMetricDataRequest (com.amazonaws.services.cloudwatch.model.PutMetricDataRequest)1 Context (com.amazonaws.services.lambda.runtime.Context)1 AmazonS3URI (com.amazonaws.services.s3.AmazonS3URI)1 AmazonS3ClientFactory (com.nextdoor.bender.aws.AmazonS3ClientFactory)1 BenderConfig (com.nextdoor.bender.config.BenderConfig)1 ConfigurationException (com.nextdoor.bender.config.ConfigurationException)1 HandlerResources (com.nextdoor.bender.config.HandlerResources)1 Source (com.nextdoor.bender.config.Source)1 DeserializedEvent (com.nextdoor.bender.deserializer.DeserializedEvent)1 DeserializerProcessor (com.nextdoor.bender.deserializer.DeserializerProcessor)1