Search in sources :

Example 11 with LoggingContext

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
    }
}
Also used : TestLoggingContext(co.cask.cdap.common.logging.logback.TestLoggingContext) LoggingContext(co.cask.cdap.common.logging.LoggingContext) HashMap(java.util.HashMap) TestLoggingContext(co.cask.cdap.common.logging.logback.TestLoggingContext) Map(java.util.Map) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 12 with LoggingContext

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);
}
Also used : LoggingTester(co.cask.cdap.logging.appender.LoggingTester) LoggingContext(co.cask.cdap.common.logging.LoggingContext) FlowletLoggingContext(co.cask.cdap.logging.context.FlowletLoggingContext) FlowletLoggingContext(co.cask.cdap.logging.context.FlowletLoggingContext) FileLogReader(co.cask.cdap.logging.read.FileLogReader) Test(org.junit.Test)

Example 13 with 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);
}
Also used : LoggingTester(co.cask.cdap.logging.appender.LoggingTester) LoggingContext(co.cask.cdap.common.logging.LoggingContext) FlowletLoggingContext(co.cask.cdap.logging.context.FlowletLoggingContext) FlowletLoggingContext(co.cask.cdap.logging.context.FlowletLoggingContext) FileLogReader(co.cask.cdap.logging.read.FileLogReader) Test(org.junit.Test)

Example 14 with 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);
}
Also used : LoggingContext(co.cask.cdap.common.logging.LoggingContext) RunRecordMeta(co.cask.cdap.internal.app.store.RunRecordMeta) ProgramRunId(co.cask.cdap.proto.id.ProgramRunId) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Example 15 with LoggingContext

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);
}
Also used : LoggingContext(co.cask.cdap.common.logging.LoggingContext) RunRecordMeta(co.cask.cdap.internal.app.store.RunRecordMeta) ProgramRunId(co.cask.cdap.proto.id.ProgramRunId) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Aggregations

LoggingContext (co.cask.cdap.common.logging.LoggingContext)30 GET (javax.ws.rs.GET)12 Path (javax.ws.rs.Path)12 Test (org.junit.Test)11 FlowletLoggingContext (co.cask.cdap.logging.context.FlowletLoggingContext)9 RunRecordMeta (co.cask.cdap.internal.app.store.RunRecordMeta)6 LoggingTester (co.cask.cdap.logging.appender.LoggingTester)5 FileLogReader (co.cask.cdap.logging.read.FileLogReader)4 LogEvent (co.cask.cdap.logging.read.LogEvent)4 CConfiguration (co.cask.cdap.common.conf.CConfiguration)3 ApplicationLoggingContext (co.cask.cdap.common.logging.ApplicationLoggingContext)3 LogPathIdentifier (co.cask.cdap.logging.appender.system.LogPathIdentifier)3 FileMetaDataReader (co.cask.cdap.logging.meta.FileMetaDataReader)3 LogLocation (co.cask.cdap.logging.write.LogLocation)3 ProgramType (co.cask.cdap.proto.ProgramType)3 Transactional (co.cask.cdap.api.Transactional)2 DatasetManager (co.cask.cdap.api.dataset.DatasetManager)2 NamespaceLoggingContext (co.cask.cdap.common.logging.NamespaceLoggingContext)2 ServiceLoggingContext (co.cask.cdap.common.logging.ServiceLoggingContext)2 SystemDatasetInstantiator (co.cask.cdap.data.dataset.SystemDatasetInstantiator)2