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;
}
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();
}
Aggregations