Search in sources :

Example 1 with AlertBuilder

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;
}
Also used : AlertBuilder(org.apache.druid.java.util.emitter.service.AlertBuilder) StringWriter(java.io.StringWriter) ISE(org.apache.druid.java.util.common.ISE) PrintWriter(java.io.PrintWriter)

Example 2 with AlertBuilder

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"));
}
Also used : ServiceEmitter(org.apache.druid.java.util.emitter.service.ServiceEmitter) AlertBuilder(org.apache.druid.java.util.emitter.service.AlertBuilder) ServiceEventBuilder(org.apache.druid.java.util.emitter.service.ServiceEventBuilder) File(java.io.File) DataSegment(org.apache.druid.timeline.DataSegment) Test(org.junit.Test)

Aggregations

AlertBuilder (org.apache.druid.java.util.emitter.service.AlertBuilder)2 File (java.io.File)1 PrintWriter (java.io.PrintWriter)1 StringWriter (java.io.StringWriter)1 ISE (org.apache.druid.java.util.common.ISE)1 ServiceEmitter (org.apache.druid.java.util.emitter.service.ServiceEmitter)1 ServiceEventBuilder (org.apache.druid.java.util.emitter.service.ServiceEventBuilder)1 DataSegment (org.apache.druid.timeline.DataSegment)1 Test (org.junit.Test)1