Search in sources :

Example 1 with RemoteLogAppender

use of io.cdap.cdap.logging.appender.remote.RemoteLogAppender in project cdap by caskdata.

the class LogBufferHandlerTest method testHandler.

@Test
public void testHandler() throws Exception {
    CConfiguration cConf = CConfiguration.create();
    String absolutePath = TMP_FOLDER.newFolder().getAbsolutePath();
    cConf.set(Constants.LogBuffer.LOG_BUFFER_BASE_DIR, absolutePath);
    cConf.setLong(Constants.LogBuffer.LOG_BUFFER_MAX_FILE_SIZE_BYTES, 100000);
    LoggerContext loggerContext = LogPipelineTestUtil.createLoggerContext("WARN", ImmutableMap.of("test.logger", "INFO"), MockAppender.class.getName());
    final MockAppender appender = LogPipelineTestUtil.getAppender(loggerContext.getLogger(ch.qos.logback.classic.Logger.ROOT_LOGGER_NAME), "Test", MockAppender.class);
    LogBufferProcessorPipeline pipeline = getLogPipeline(loggerContext);
    pipeline.startAndWait();
    ConcurrentLogBufferWriter writer = new ConcurrentLogBufferWriter(cConf, ImmutableList.of(pipeline), () -> {
    });
    NettyHttpService httpService = NettyHttpService.builder("RemoteAppenderTest").setHttpHandlers(new LogBufferHandler(writer)).setExceptionHandler(new HttpExceptionHandler()).build();
    httpService.start();
    RemoteLogAppender remoteLogAppender = getRemoteAppender(cConf, httpService);
    remoteLogAppender.start();
    List<ILoggingEvent> events = getLoggingEvents();
    WorkerLoggingContext loggingContext = new WorkerLoggingContext("default", "app1", "worker1", "run1", "instance1");
    for (int i = 0; i < 1000; i++) {
        remoteLogAppender.append(new LogMessage(events.get(i % events.size()), loggingContext));
    }
    Tasks.waitFor(1000, () -> appender.getEvents().size(), 120, TimeUnit.SECONDS, 100, TimeUnit.MILLISECONDS);
    remoteLogAppender.stop();
    httpService.stop();
    pipeline.stopAndWait();
    loggerContext.stop();
}
Also used : WorkerLoggingContext(io.cdap.cdap.logging.context.WorkerLoggingContext) RemoteLogAppender(io.cdap.cdap.logging.appender.remote.RemoteLogAppender) HttpExceptionHandler(io.cdap.cdap.common.HttpExceptionHandler) ILoggingEvent(ch.qos.logback.classic.spi.ILoggingEvent) CConfiguration(io.cdap.cdap.common.conf.CConfiguration) LoggerContext(ch.qos.logback.classic.LoggerContext) MockAppender(io.cdap.cdap.logging.pipeline.MockAppender) LogMessage(io.cdap.cdap.logging.appender.LogMessage) LogBufferProcessorPipeline(io.cdap.cdap.logging.pipeline.logbuffer.LogBufferProcessorPipeline) NettyHttpService(io.cdap.http.NettyHttpService) ConcurrentLogBufferWriter(io.cdap.cdap.logging.logbuffer.ConcurrentLogBufferWriter) Test(org.junit.Test)

Example 2 with RemoteLogAppender

use of io.cdap.cdap.logging.appender.remote.RemoteLogAppender in project cdap by caskdata.

the class LogBufferHandlerTest method getRemoteAppender.

private RemoteLogAppender getRemoteAppender(CConfiguration cConf, NettyHttpService httpService) {
    InMemoryDiscoveryService discoveryService = new InMemoryDiscoveryService();
    discoveryService.register(new Discoverable(Constants.Service.LOG_BUFFER_SERVICE, httpService.getBindAddress()));
    RemoteClientFactory remoteClientFactory = new RemoteClientFactory(discoveryService, new DefaultInternalAuthenticator(new AuthenticationTestContext()));
    return new RemoteLogAppender(cConf, remoteClientFactory);
}
Also used : RemoteClientFactory(io.cdap.cdap.common.internal.remote.RemoteClientFactory) Discoverable(org.apache.twill.discovery.Discoverable) DefaultInternalAuthenticator(io.cdap.cdap.common.internal.remote.DefaultInternalAuthenticator) AuthenticationTestContext(io.cdap.cdap.security.auth.context.AuthenticationTestContext) RemoteLogAppender(io.cdap.cdap.logging.appender.remote.RemoteLogAppender) InMemoryDiscoveryService(org.apache.twill.discovery.InMemoryDiscoveryService)

Aggregations

RemoteLogAppender (io.cdap.cdap.logging.appender.remote.RemoteLogAppender)2 LoggerContext (ch.qos.logback.classic.LoggerContext)1 ILoggingEvent (ch.qos.logback.classic.spi.ILoggingEvent)1 HttpExceptionHandler (io.cdap.cdap.common.HttpExceptionHandler)1 CConfiguration (io.cdap.cdap.common.conf.CConfiguration)1 DefaultInternalAuthenticator (io.cdap.cdap.common.internal.remote.DefaultInternalAuthenticator)1 RemoteClientFactory (io.cdap.cdap.common.internal.remote.RemoteClientFactory)1 LogMessage (io.cdap.cdap.logging.appender.LogMessage)1 WorkerLoggingContext (io.cdap.cdap.logging.context.WorkerLoggingContext)1 ConcurrentLogBufferWriter (io.cdap.cdap.logging.logbuffer.ConcurrentLogBufferWriter)1 MockAppender (io.cdap.cdap.logging.pipeline.MockAppender)1 LogBufferProcessorPipeline (io.cdap.cdap.logging.pipeline.logbuffer.LogBufferProcessorPipeline)1 AuthenticationTestContext (io.cdap.cdap.security.auth.context.AuthenticationTestContext)1 NettyHttpService (io.cdap.http.NettyHttpService)1 Discoverable (org.apache.twill.discovery.Discoverable)1 InMemoryDiscoveryService (org.apache.twill.discovery.InMemoryDiscoveryService)1 Test (org.junit.Test)1