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();
}
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());
}
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();
}
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));
}
}
Aggregations