use of co.cask.cdap.common.logging.LoggingContext in project cdap by caskdata.
the class LoggingContextMDCTest method testMDC.
@Test
public void testMDC() {
LoggingContext context = new TestLoggingContext("namespace", "app", "run", "instance");
// Put an entry in the user mdc. It shouldn't override what's in the system tags.
Map<String, String> userMDC = new HashMap<>();
userMDC.put(Constants.Logging.TAG_APPLICATION_ID, "userApp");
Map<String, String> mdc = new LoggingContextMDC(context.getSystemTagsAsString(), userMDC);
Assert.assertEquals(4, mdc.size());
Map<String, String> copiedMDC = new HashMap<>();
for (Map.Entry<String, String> entry : mdc.entrySet()) {
copiedMDC.put(entry.getKey(), entry.getValue());
}
Assert.assertEquals(4, copiedMDC.size());
Assert.assertEquals("namespace", copiedMDC.get(Constants.Logging.TAG_NAMESPACE_ID));
Assert.assertEquals("app", copiedMDC.get(Constants.Logging.TAG_APPLICATION_ID));
Assert.assertEquals("run", copiedMDC.get(Constants.Logging.TAG_RUN_ID));
Assert.assertEquals("instance", copiedMDC.get(Constants.Logging.TAG_INSTANCE_ID));
// Should be able to set user property
mdc.put("user", "test");
Assert.assertEquals(5, mdc.size());
Assert.assertEquals(5, mdc.entrySet().size());
// This should fail with exception
try {
mdc.put(Constants.Logging.TAG_APPLICATION_ID, "newApp");
Assert.fail();
} catch (IllegalArgumentException e) {
// expected
}
}
use of co.cask.cdap.common.logging.LoggingContext in project cdap by caskdata.
the class TestFileLogging method testGetLogPrev.
@Test
public void testGetLogPrev() throws Exception {
LoggingContext loggingContext = new FlowletLoggingContext("TFL_NS_1", "APP_1", "FLOW_1", "", "RUN1", "INSTANCE1");
FileLogReader logReader = injector.getInstance(FileLogReader.class);
LoggingTester tester = new LoggingTester();
tester.testGetPrev(logReader, loggingContext);
}
use of co.cask.cdap.common.logging.LoggingContext in project cdap by caskdata.
the class TestFileLogging method testGetLogNext.
@Test
public void testGetLogNext() throws Exception {
LoggingContext loggingContext = new FlowletLoggingContext("TFL_NS_1", "APP_1", "FLOW_1", "", "RUN1", "INSTANCE1");
FileLogReader logReader = injector.getInstance(FileLogReader.class);
LoggingTester tester = new LoggingTester();
tester.testGetNext(logReader, loggingContext);
}
use of co.cask.cdap.common.logging.LoggingContext in project cdap by caskdata.
the class PreviewHttpHandler method getPreviewLogs.
@GET
@Path("/previews/{preview-id}/logs")
public void getPreviewLogs(HttpRequest request, HttpResponder responder, @PathParam("namespace-id") String namespaceId, @PathParam("preview-id") String previewId, @QueryParam("start") @DefaultValue("-1") long fromTimeSecsParam, @QueryParam("stop") @DefaultValue("-1") long toTimeSecsParam, @QueryParam("escape") @DefaultValue("true") boolean escape, @QueryParam("filter") @DefaultValue("") String filterStr, @QueryParam("format") @DefaultValue("text") String format, @QueryParam("suppress") List<String> suppress) throws Exception {
ProgramRunId runId = getProgramRunId(namespaceId, previewId);
RunRecordMeta runRecord = getRunRecord(namespaceId, previewId);
LoggingContext loggingContext = LoggingContextHelper.getLoggingContextWithRunId(namespaceId, previewId, runId.getProgram(), runId.getType(), runId.getRun(), runRecord.getSystemArgs());
doGetLogs(responder, loggingContext, fromTimeSecsParam, toTimeSecsParam, escape, filterStr, runRecord, format, suppress);
}
use of co.cask.cdap.common.logging.LoggingContext in project cdap by caskdata.
the class PreviewHttpHandler method getPreviewLogsNext.
@GET
@Path("/previews/{preview-id}/logs/next")
public void getPreviewLogsNext(HttpRequest request, HttpResponder responder, @PathParam("namespace-id") String namespaceId, @PathParam("preview-id") String previewId, @QueryParam("max") @DefaultValue("50") int maxEvents, @QueryParam("fromOffset") @DefaultValue("") String fromOffsetStr, @QueryParam("escape") @DefaultValue("true") boolean escape, @QueryParam("filter") @DefaultValue("") String filterStr, @QueryParam("format") @DefaultValue("text") String format, @QueryParam("suppress") List<String> suppress) throws Exception {
ProgramRunId runId = getProgramRunId(namespaceId, previewId);
RunRecordMeta runRecord = getRunRecord(namespaceId, previewId);
LoggingContext loggingContext = LoggingContextHelper.getLoggingContextWithRunId(namespaceId, previewId, runId.getProgram(), runId.getType(), runId.getRun(), runRecord.getSystemArgs());
doNext(responder, loggingContext, maxEvents, fromOffsetStr, escape, filterStr, runRecord, format, suppress);
}
Aggregations