Search in sources :

Example 1 with CheckpointManager

use of io.cdap.cdap.logging.meta.CheckpointManager in project cdap by caskdata.

the class LogBufferService method loadLogPipelines.

/**
 * Load log buffer pipelines.
 */
@SuppressWarnings("unchecked")
private List<LogBufferProcessorPipeline> loadLogPipelines() {
    Map<String, LogPipelineSpecification<AppenderContext>> specs = new LogPipelineLoader(cConf).load(contextProvider);
    int pipelineCount = specs.size();
    List<LogBufferProcessorPipeline> bufferPipelines = new ArrayList<>();
    // Create one LogBufferProcessorPipeline per spec
    for (LogPipelineSpecification<AppenderContext> pipelineSpec : specs.values()) {
        CConfiguration cConf = pipelineSpec.getConf();
        AppenderContext context = pipelineSpec.getContext();
        long bufferSize = getBufferSize(pipelineCount, cConf);
        LogBufferPipelineConfig config = new LogBufferPipelineConfig(bufferSize, cConf.getLong(Constants.Logging.PIPELINE_EVENT_DELAY_MS), cConf.getLong(Constants.Logging.PIPELINE_CHECKPOINT_INTERVAL_MS), cConf.getLong(Constants.LogBuffer.LOG_BUFFER_PIPELINE_BATCH_SIZE, 1000));
        CheckpointManager checkpointManager = checkpointManagerFactory.create(pipelineSpec.getCheckpointPrefix(), CheckpointManagerFactory.Type.LOG_BUFFER);
        LogBufferProcessorPipeline pipeline = new LogBufferProcessorPipeline(new LogProcessorPipelineContext(cConf, context.getName(), context, context.getMetricsContext(), context.getInstanceId()), config, checkpointManager, 0);
        RetryStrategy retryStrategy = RetryStrategies.fromConfiguration(cConf, "system.log.process.");
        pipelines.add(new RetryOnStartFailureService(() -> pipeline, retryStrategy));
        bufferPipelines.add(pipeline);
        checkpointManagers.add(checkpointManager);
    }
    return bufferPipelines;
}
Also used : LogPipelineSpecification(io.cdap.cdap.logging.framework.LogPipelineSpecification) CheckpointManager(io.cdap.cdap.logging.meta.CheckpointManager) ArrayList(java.util.ArrayList) LogPipelineLoader(io.cdap.cdap.logging.framework.LogPipelineLoader) LogProcessorPipelineContext(io.cdap.cdap.logging.pipeline.LogProcessorPipelineContext) CConfiguration(io.cdap.cdap.common.conf.CConfiguration) LogBufferProcessorPipeline(io.cdap.cdap.logging.pipeline.logbuffer.LogBufferProcessorPipeline) LogBufferPipelineConfig(io.cdap.cdap.logging.pipeline.logbuffer.LogBufferPipelineConfig) AppenderContext(io.cdap.cdap.api.logging.AppenderContext) RetryOnStartFailureService(io.cdap.cdap.common.service.RetryOnStartFailureService) RetryStrategy(io.cdap.cdap.common.service.RetryStrategy)

Example 2 with CheckpointManager

use of io.cdap.cdap.logging.meta.CheckpointManager in project cdap by caskdata.

the class LogBufferProcessorPipelineTest method testSingleAppender.

@Test
public void testSingleAppender() throws Exception {
    LoggerContext loggerContext = LogPipelineTestUtil.createLoggerContext("WARN", ImmutableMap.of("test.logger", "INFO"), MockAppender.class.getName());
    final MockAppender appender = LogPipelineTestUtil.getAppender(loggerContext.getLogger(Logger.ROOT_LOGGER_NAME), "Test", MockAppender.class);
    MockCheckpointManager checkpointManager = new MockCheckpointManager();
    LogBufferPipelineConfig config = new LogBufferPipelineConfig(1024L, 300L, 500L, 4);
    loggerContext.start();
    LogBufferProcessorPipeline pipeline = new LogBufferProcessorPipeline(new LogProcessorPipelineContext(CConfiguration.create(), "test", loggerContext, NO_OP_METRICS_CONTEXT, 0), config, checkpointManager, 0);
    // start the pipeline
    pipeline.startAndWait();
    // start thread to write to incomingEventQueue
    List<ILoggingEvent> events = getLoggingEvents();
    AtomicInteger i = new AtomicInteger(0);
    List<LogBufferEvent> bufferEvents = events.stream().map(event -> {
        LogBufferEvent lbe = new LogBufferEvent(event, serializer.toBytes(event).length, new LogBufferFileOffset(0, i.get()));
        i.incrementAndGet();
        return lbe;
    }).collect(Collectors.toList());
    // start a thread to send log buffer events to pipeline
    ExecutorService executorService = Executors.newSingleThreadExecutor();
    executorService.execute(() -> {
        for (int count = 0; count < 40; count++) {
            pipeline.processLogEvents(bufferEvents.iterator());
            try {
                Thread.sleep(100);
            } catch (InterruptedException e) {
            // should not happen
            }
        }
    });
    // wait for pipeline to append all the logs to appender. The DEBUG message should get filtered out.
    Tasks.waitFor(200, () -> appender.getEvents().size(), 60, TimeUnit.SECONDS, 100, TimeUnit.MILLISECONDS);
    executorService.shutdown();
    pipeline.stopAndWait();
    loggerContext.stop();
}
Also used : ILoggingEvent(ch.qos.logback.classic.spi.ILoggingEvent) LogBufferFileOffset(io.cdap.cdap.logging.logbuffer.LogBufferFileOffset) LoggerContext(ch.qos.logback.classic.LoggerContext) CheckpointManager(io.cdap.cdap.logging.meta.CheckpointManager) MockAppender(io.cdap.cdap.logging.pipeline.MockAppender) LoggingEventSerializer(io.cdap.cdap.logging.serialize.LoggingEventSerializer) ImmutableList(com.google.common.collect.ImmutableList) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) LogProcessorPipelineContext(io.cdap.cdap.logging.pipeline.LogProcessorPipelineContext) Map(java.util.Map) ExecutorService(java.util.concurrent.ExecutorService) NoopMetricsContext(io.cdap.cdap.api.metrics.NoopMetricsContext) Tasks(io.cdap.cdap.common.utils.Tasks) ImmutableMap(com.google.common.collect.ImmutableMap) Checkpoint(io.cdap.cdap.logging.meta.Checkpoint) Set(java.util.Set) Test(org.junit.Test) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) Executors(java.util.concurrent.Executors) TimeUnit(java.util.concurrent.TimeUnit) Level(ch.qos.logback.classic.Level) MetricsContext(io.cdap.cdap.api.metrics.MetricsContext) List(java.util.List) CConfiguration(io.cdap.cdap.common.conf.CConfiguration) Logger(ch.qos.logback.classic.Logger) LogBufferEvent(io.cdap.cdap.logging.logbuffer.LogBufferEvent) Collections(java.util.Collections) LogPipelineTestUtil(io.cdap.cdap.logging.pipeline.LogPipelineTestUtil) LogProcessorPipelineContext(io.cdap.cdap.logging.pipeline.LogProcessorPipelineContext) ILoggingEvent(ch.qos.logback.classic.spi.ILoggingEvent) LoggerContext(ch.qos.logback.classic.LoggerContext) Checkpoint(io.cdap.cdap.logging.meta.Checkpoint) MockAppender(io.cdap.cdap.logging.pipeline.MockAppender) LogBufferEvent(io.cdap.cdap.logging.logbuffer.LogBufferEvent) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ExecutorService(java.util.concurrent.ExecutorService) LogBufferFileOffset(io.cdap.cdap.logging.logbuffer.LogBufferFileOffset) Test(org.junit.Test)

Aggregations

CConfiguration (io.cdap.cdap.common.conf.CConfiguration)2 CheckpointManager (io.cdap.cdap.logging.meta.CheckpointManager)2 LogProcessorPipelineContext (io.cdap.cdap.logging.pipeline.LogProcessorPipelineContext)2 Level (ch.qos.logback.classic.Level)1 Logger (ch.qos.logback.classic.Logger)1 LoggerContext (ch.qos.logback.classic.LoggerContext)1 ILoggingEvent (ch.qos.logback.classic.spi.ILoggingEvent)1 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 AppenderContext (io.cdap.cdap.api.logging.AppenderContext)1 MetricsContext (io.cdap.cdap.api.metrics.MetricsContext)1 NoopMetricsContext (io.cdap.cdap.api.metrics.NoopMetricsContext)1 RetryOnStartFailureService (io.cdap.cdap.common.service.RetryOnStartFailureService)1 RetryStrategy (io.cdap.cdap.common.service.RetryStrategy)1 Tasks (io.cdap.cdap.common.utils.Tasks)1 LogPipelineLoader (io.cdap.cdap.logging.framework.LogPipelineLoader)1 LogPipelineSpecification (io.cdap.cdap.logging.framework.LogPipelineSpecification)1 LogBufferEvent (io.cdap.cdap.logging.logbuffer.LogBufferEvent)1 LogBufferFileOffset (io.cdap.cdap.logging.logbuffer.LogBufferFileOffset)1 Checkpoint (io.cdap.cdap.logging.meta.Checkpoint)1