Search in sources :

Example 16 with LoggingContext

use of io.cdap.cdap.common.logging.LoggingContext in project cdap by caskdata.

the class LogHttpHandler method getRunIdLogs.

@GET
@Path("/namespaces/{namespace-id}/apps/{app-id}/{program-type}/{program-id}/runs/{run-id}/logs")
public void getRunIdLogs(HttpRequest request, HttpResponder responder, @PathParam("namespace-id") String namespaceId, @PathParam("app-id") String appId, @PathParam("program-type") String programType, @PathParam("program-id") String programId, @PathParam("run-id") String runId, @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 {
    ensureVisibilityOnProgram(namespaceId, appId, programType, programId);
    ProgramType type = ProgramType.valueOfCategoryName(programType);
    ProgramRunId programRunId = new ProgramRunId(namespaceId, appId, type, programId, runId);
    RunRecordDetail runRecord = getRunRecordMeta(programRunId);
    LoggingContext loggingContext = LoggingContextHelper.getLoggingContextWithRunId(programRunId, runRecord.getSystemArgs());
    doGetLogs(logReader, responder, loggingContext, fromTimeSecsParam, toTimeSecsParam, escape, filterStr, runRecord, format, suppress);
}
Also used : LoggingContext(io.cdap.cdap.common.logging.LoggingContext) RunRecordDetail(io.cdap.cdap.internal.app.store.RunRecordDetail) ProgramType(io.cdap.cdap.proto.ProgramType) ProgramRunId(io.cdap.cdap.proto.id.ProgramRunId) Path(javax.ws.rs.Path) GET(javax.ws.rs.GET)

Example 17 with LoggingContext

use of io.cdap.cdap.common.logging.LoggingContext in project cdap by caskdata.

the class TestFileLogging method testGetLogNext.

@Test
public void testGetLogNext() throws Exception {
    LoggingContext loggingContext = new WorkerLoggingContext("TFL_NS_1", "APP_1", "WORKER_1", "RUN1", "INSTANCE1");
    FileLogReader logReader = injector.getInstance(FileLogReader.class);
    LoggingTester tester = new LoggingTester();
    tester.testGetNext(logReader, loggingContext);
}
Also used : LoggingTester(io.cdap.cdap.logging.appender.LoggingTester) WorkerLoggingContext(io.cdap.cdap.logging.context.WorkerLoggingContext) LoggingContext(io.cdap.cdap.common.logging.LoggingContext) WorkerLoggingContext(io.cdap.cdap.logging.context.WorkerLoggingContext) FileLogReader(io.cdap.cdap.logging.read.FileLogReader) Test(org.junit.Test)

Example 18 with LoggingContext

use of io.cdap.cdap.common.logging.LoggingContext in project cdap by caskdata.

the class TestKafkaLogging method testGetNext.

@Test
public void testGetNext() throws Exception {
    // Check with null runId and null instanceId
    LoggingContext loggingContext = new WorkerLoggingContext("TKL_NS_1", "APP_1", "FLOW_1", "RUN1", "INSTANCE1");
    KafkaLogReader logReader = KAFKA_TESTER.getInjector().getInstance(KafkaLogReader.class);
    LoggingTester tester = new LoggingTester();
    tester.testGetNext(logReader, loggingContext);
}
Also used : KafkaLogReader(io.cdap.cdap.logging.read.KafkaLogReader) LoggingTester(io.cdap.cdap.logging.appender.LoggingTester) WorkerLoggingContext(io.cdap.cdap.logging.context.WorkerLoggingContext) LoggingContext(io.cdap.cdap.common.logging.LoggingContext) WorkerLoggingContext(io.cdap.cdap.logging.context.WorkerLoggingContext) Test(org.junit.Test)

Example 19 with LoggingContext

use of io.cdap.cdap.common.logging.LoggingContext in project cdap by cdapio.

the class RemoteExecutionService method shouldRetry.

@Override
protected boolean shouldRetry(Exception ex) {
    LoggingContext loggingContext = LoggingContextHelper.getLoggingContextWithRunId(programRunId, null);
    Cancellable cancellable = LoggingContextAccessor.setLoggingContext(loggingContext);
    try {
        OUTAGE_LOGGER.warn("Exception raised when monitoring program run {}", programRunId, ex);
        try {
            // If the program is not running, abort retry
            if (!processController.isRunning()) {
                LOG.debug("Program {} is not running", programRunId, ex);
                // Always emit an error state. If this is indeed a normal stop, there should be a completion state
                // in the TMS before this one, in which this one will get ignored by the
                programStateWriter.error(programRunId, new IllegalStateException("Program terminated " + programRunId, ex));
                return false;
            }
        } catch (Exception e) {
            OUTAGE_LOGGER.warn("Failed to check if the remote process is still running for program {}", programRunId, e);
        }
        return true;
    } finally {
        cancellable.cancel();
    }
}
Also used : LoggingContext(io.cdap.cdap.common.logging.LoggingContext) Cancellable(org.apache.twill.common.Cancellable)

Example 20 with LoggingContext

use of io.cdap.cdap.common.logging.LoggingContext in project cdap by cdapio.

the class ProvisioningService method callWithProgramLogging.

/**
 * Calls the {@link Callable} with the logging context set to the program run's context.
 * Anything logged within the runnable will be treated as if they were logs in the program run.
 *
 * @param programRunId the program run to log as
 * @param systemArgs system arguments for the run
 * @param callable the {@link Callable} to call
 * @return the value returned by the {@link Callable#call()} method
 * @throws Exception if the {@link Callable#call()} method thrown an exception
 */
private <V> V callWithProgramLogging(ProgramRunId programRunId, Map<String, String> systemArgs, Callable<V> callable) throws Exception {
    LoggingContext loggingContext = LoggingContextHelper.getLoggingContextWithRunId(programRunId, systemArgs);
    Cancellable cancellable = LoggingContextAccessor.setLoggingContext(loggingContext);
    try {
        return callable.call();
    } finally {
        cancellable.cancel();
    }
}
Also used : LoggingContext(io.cdap.cdap.common.logging.LoggingContext) Cancellable(org.apache.twill.common.Cancellable)

Aggregations

LoggingContext (io.cdap.cdap.common.logging.LoggingContext)74 Test (org.junit.Test)20 WorkerLoggingContext (io.cdap.cdap.logging.context.WorkerLoggingContext)18 GET (javax.ws.rs.GET)18 Path (javax.ws.rs.Path)18 CConfiguration (io.cdap.cdap.common.conf.CConfiguration)16 ServiceLoggingContext (io.cdap.cdap.common.logging.ServiceLoggingContext)14 Injector (com.google.inject.Injector)12 LogAppenderInitializer (io.cdap.cdap.logging.appender.LogAppenderInitializer)12 LoggingTester (io.cdap.cdap.logging.appender.LoggingTester)12 File (java.io.File)12 Configuration (org.apache.hadoop.conf.Configuration)12 Cancellable (org.apache.twill.common.Cancellable)10 FileLogReader (io.cdap.cdap.logging.read.FileLogReader)8 LogEvent (io.cdap.cdap.logging.read.LogEvent)8 ProgramRunId (io.cdap.cdap.proto.id.ProgramRunId)8 Logger (org.slf4j.Logger)8 ILoggingEvent (ch.qos.logback.classic.spi.ILoggingEvent)6 MetricsCollectionService (io.cdap.cdap.api.metrics.MetricsCollectionService)6 RunRecordDetail (io.cdap.cdap.internal.app.store.RunRecordDetail)6