use of org.apache.druid.java.util.emitter.service.AlertBuilder in project druid by druid-io.
the class EmittingLogger method makeAlert.
public AlertBuilder makeAlert(@Nullable Throwable t, String message, Object... objects) {
if (emitter == null) {
final String errorMessage = StringUtils.format("Emitter not initialized! Cannot alert. Please make sure to call %s.registerEmitter()\n" + "Message: %s", this.getClass(), StringUtils.nonStrictFormat(message, objects));
ISE e = new ISE(errorMessage);
if (t != null) {
e.addSuppressed(t);
}
error(e, errorMessage);
throw e;
}
final AlertBuilder retVal = new EmittingAlertBuilder(t, StringUtils.format(message, objects), emitter).addData("class", className);
if (t != null) {
final StringWriter trace = new StringWriter();
final PrintWriter pw = new PrintWriter(trace);
t.printStackTrace(pw);
retVal.addData("exceptionType", t.getClass());
retVal.addData("exceptionMessage", t.getMessage());
retVal.addData("exceptionStackTrace", trace.toString());
}
return retVal;
}
use of org.apache.druid.java.util.emitter.service.AlertBuilder in project druid by druid-io.
the class StorageLocationTest method testMaybeReserve.
@Test
public void testMaybeReserve() throws IOException {
ServiceEmitter emitter = Mockito.mock(ServiceEmitter.class);
ArgumentCaptor<ServiceEventBuilder> argumentCaptor = ArgumentCaptor.forClass(ServiceEventBuilder.class);
EmittingLogger.registerEmitter(emitter);
File dir = temporaryFolder.newFolder();
long expectedAvail = 1000L;
StorageLocation loc = new StorageLocation(dir, expectedAvail, null);
verifyLoc(expectedAvail, loc);
final DataSegment secondSegment = makeSegment("2012-01-02/2012-01-03", 23);
loc.maybeReserve("test1", makeSegment("2012-01-01/2012-01-02", 10));
expectedAvail -= 10;
verifyLoc(expectedAvail, loc);
loc.maybeReserve("test1", makeSegment("2012-01-01/2012-01-02", 10));
verifyLoc(expectedAvail, loc);
loc.maybeReserve("test2", secondSegment);
expectedAvail -= 23;
verifyLoc(expectedAvail, loc);
loc.removeSegmentDir(new File(dir, "test1"), makeSegment("2012-01-01/2012-01-02", 10));
expectedAvail += 10;
verifyLoc(expectedAvail, loc);
loc.maybeReserve("test3", makeSegment("2012-01-01/2012-01-02", 999));
expectedAvail -= 999;
verifyLoc(expectedAvail, loc);
Mockito.verify(emitter).emit(argumentCaptor.capture());
AlertBuilder alertBuilder = (AlertBuilder) argumentCaptor.getValue();
String description = alertBuilder.build(ImmutableMap.of()).getDescription();
Assert.assertNotNull(description);
Assert.assertTrue(description, description.contains("Please increase druid.segmentCache.locations maxSize param"));
}
Aggregations