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