Search in sources :

Example 11 with Stat

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

the class DeserializerProcessorTest method testStatsLogging.

@Test
public void testStatsLogging() throws InstantiationException, IllegalAccessException {
    DeserializerProcessor deser = new DeserializerProcessor(new DummyDeserializer());
    /*
     * 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);
    deser.deserialize("foo");
    /*
     * Verify start, stop, increment success count, and never increment error count.
     */
    verify(runtimeStat, times(1)).start();
    verify(runtimeStat, times(1)).stop();
    verify(successStat, times(1)).increment();
    verify(errorStat, never()).increment();
}
Also used : DummyDeserializer(com.nextdoor.bender.testutils.DummyDeserializerHelper.DummyDeserializer) Stat(com.nextdoor.bender.monitoring.Stat) Test(org.junit.Test)

Example 12 with Stat

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

the class OperationProcessorTest method testStatsLogging.

@Test
public void testStatsLogging() throws JsonSyntaxException, UnsupportedEncodingException, IOException, OperationException {
    DummyOperationFactory mutatorFactory = new DummyOperationFactory();
    OperationProcessor processor = new OperationProcessor(mutatorFactory);
    /*
     * 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);
    InternalEvent ievent = new InternalEvent("foo", null, 1);
    ievent.setEventObj(new DummyDeserializerHelper.DummyDeserializedEvent("test"));
    Stream<InternalEvent> stream = processor.perform(Stream.of(ievent));
    List<InternalEvent> output = stream.collect(Collectors.toList());
    /*
     * Verify start, stop, increment success count, and never increment error count.
     */
    verify(runtimeStat, times(1)).start();
    verify(runtimeStat, times(1)).stop();
    verify(successStat, times(1)).increment();
    verify(errorStat, never()).increment();
    /*
     * Verify contents of output stream
     */
    assertEquals(1, output.size());
}
Also used : Stat(com.nextdoor.bender.monitoring.Stat) DummyDeserializerHelper(com.nextdoor.bender.testutils.DummyDeserializerHelper) DummyOperationFactory(com.nextdoor.bender.testutils.DummyOperationHelper.DummyOperationFactory) InternalEvent(com.nextdoor.bender.InternalEvent) Test(org.junit.Test)

Example 13 with Stat

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

the class SerializerProcessorTest method testStatsLogging.

@Test
public void testStatsLogging() throws SerializationException {
    DummySerializer serializer = new DummySerializer();
    SerializerProcessor processor = new SerializerProcessor(serializer);
    /*
     * 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);
    processor.serialize("foo");
    /*
     * Verify start, stop, increment success count, and never increment error count.
     */
    verify(runtimeStat, times(1)).start();
    verify(runtimeStat, times(1)).stop();
    verify(successStat, times(1)).increment();
    verify(errorStat, never()).increment();
}
Also used : DummySerializer(com.nextdoor.bender.testutils.DummySerializerHelper.DummySerializer) Stat(com.nextdoor.bender.monitoring.Stat) Test(org.junit.Test)

Example 14 with Stat

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

the class DataDogReporter method write.

@Override
public void write(ArrayList<Stat> stats, long invokeTimeMs, Set<Tag> tags) {
    Set<Tag> allTags = new HashSet<Tag>();
    /*
     * DataDog only tracks to second precision
     */
    long ts = invokeTimeMs / 1000;
    for (Stat stat : stats) {
        allTags.addAll(tags);
        allTags.addAll(stat.getTags());
        String tagsString = allTags.stream().map(e -> formatEntry(e.getKey(), e.getValue())).collect(Collectors.joining(","));
        /*
       * MONITORING|unix_epoch_timestamp|value|metric_type|my.metric.name|#tag1:value,tag2
       */
        String[] logParts = { "MONITORING", "" + ts, "" + stat.getValue(), stat.getType().name(), prefix + "." + stat.getName(), "#" + tagsString };
        allTags.clear();
        System.out.println(String.join("|", logParts));
    }
}
Also used : HashSet(java.util.HashSet) Reporter(com.nextdoor.bender.monitoring.Reporter) List(java.util.List) Set(java.util.Set) Stat(com.nextdoor.bender.monitoring.Stat) Tag(com.nextdoor.bender.monitoring.Tag) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) StatFilter(com.nextdoor.bender.monitoring.StatFilter) Stat(com.nextdoor.bender.monitoring.Stat) Tag(com.nextdoor.bender.monitoring.Tag) HashSet(java.util.HashSet)

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