Search in sources :

Example 6 with LoggingTester

use of io.cdap.cdap.logging.appender.LoggingTester in project cdap by cdapio.

the class TestKafkaLogging method init.

@BeforeClass
public static void init() throws Exception {
    KafkaLogAppender appender = KAFKA_TESTER.getInjector().getInstance(KafkaLogAppender.class);
    new LogAppenderInitializer(appender).initialize("TestKafkaLogging");
    Logger logger = LoggerFactory.getLogger("TestKafkaLogging");
    LoggingTester loggingTester = new LoggingTester();
    loggingTester.generateLogs(logger, new WorkerLoggingContext("TKL_NS_1", "APP_1", "FLOW_1", "RUN1", "INSTANCE1"));
    appender.stop();
}
Also used : LoggingTester(io.cdap.cdap.logging.appender.LoggingTester) LogAppenderInitializer(io.cdap.cdap.logging.appender.LogAppenderInitializer) WorkerLoggingContext(io.cdap.cdap.logging.context.WorkerLoggingContext) Logger(org.slf4j.Logger) BeforeClass(org.junit.BeforeClass)

Example 7 with LoggingTester

use of io.cdap.cdap.logging.appender.LoggingTester in project cdap by cdapio.

the class TestKafkaLogging method testGetPrev.

@Test
public void testGetPrev() throws Exception {
    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.testGetPrev(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 8 with LoggingTester

use of io.cdap.cdap.logging.appender.LoggingTester in project cdap by caskdata.

the class TestFileLogging method setUpContext.

@BeforeClass
public static void setUpContext() throws Exception {
    Configuration hConf = HBaseConfiguration.create();
    final CConfiguration cConf = CConfiguration.create();
    cConf.set(Constants.CFG_LOCAL_DATA_DIR, TMP_FOLDER.newFolder().getAbsolutePath());
    cConf.setInt(LoggingConfiguration.LOG_MAX_FILE_SIZE_BYTES, 20 * 1024);
    String logBaseDir = cConf.get(LoggingConfiguration.LOG_BASE_DIR) + "/" + TestFileLogging.class.getSimpleName();
    cConf.set(LoggingConfiguration.LOG_BASE_DIR, logBaseDir);
    injector = Guice.createInjector(new ConfigModule(cConf, hConf), new NonCustomLocationUnitTestModule(), new TransactionModules().getInMemoryModules(), new LocalLogAppenderModule(), new DataSetsModules().getInMemoryModules(), new SystemDatasetRuntimeModule().getInMemoryModules(), new AuthorizationTestModule(), new AuthorizationEnforcementModule().getInMemoryModules(), new AuthenticationContextModules().getNoOpModule(), new StorageModule(), new AbstractModule() {

        @Override
        protected void configure() {
            bind(MetricsCollectionService.class).to(NoOpMetricsCollectionService.class);
            bind(OwnerAdmin.class).to(DefaultOwnerAdmin.class);
            bind(UGIProvider.class).to(UnsupportedUGIProvider.class);
            bind(NamespaceQueryAdmin.class).to(SimpleNamespaceQueryAdmin.class);
        }
    });
    txManager = injector.getInstance(TransactionManager.class);
    txManager.startAndWait();
    StoreDefinition.LogFileMetaStore.create(injector.getInstance(StructuredTableAdmin.class));
    LogAppender appender = injector.getInstance(LocalLogAppender.class);
    new LogAppenderInitializer(appender).initialize("TestFileLogging");
    Logger logger = LoggerFactory.getLogger("TestFileLogging");
    LoggingTester loggingTester = new LoggingTester();
    loggingTester.generateLogs(logger, new WorkerLoggingContext("TFL_NS_1", "APP_1", "WORKER_1", "RUN1", "INSTANCE1"));
    appender.stop();
}
Also used : StorageModule(io.cdap.cdap.data.runtime.StorageModule) WorkerLoggingContext(io.cdap.cdap.logging.context.WorkerLoggingContext) Configuration(org.apache.hadoop.conf.Configuration) HBaseConfiguration(org.apache.hadoop.hbase.HBaseConfiguration) LoggingConfiguration(io.cdap.cdap.logging.LoggingConfiguration) CConfiguration(io.cdap.cdap.common.conf.CConfiguration) ConfigModule(io.cdap.cdap.common.guice.ConfigModule) StructuredTableAdmin(io.cdap.cdap.spi.data.StructuredTableAdmin) LogAppender(io.cdap.cdap.logging.appender.LogAppender) LocalLogAppender(io.cdap.cdap.logging.framework.local.LocalLogAppender) UGIProvider(io.cdap.cdap.security.impersonation.UGIProvider) UnsupportedUGIProvider(io.cdap.cdap.security.impersonation.UnsupportedUGIProvider) Logger(org.slf4j.Logger) LoggingTester(io.cdap.cdap.logging.appender.LoggingTester) LogAppenderInitializer(io.cdap.cdap.logging.appender.LogAppenderInitializer) NamespaceQueryAdmin(io.cdap.cdap.common.namespace.NamespaceQueryAdmin) SimpleNamespaceQueryAdmin(io.cdap.cdap.common.namespace.SimpleNamespaceQueryAdmin) SystemDatasetRuntimeModule(io.cdap.cdap.data.runtime.SystemDatasetRuntimeModule) NoOpMetricsCollectionService(io.cdap.cdap.common.metrics.NoOpMetricsCollectionService) MetricsCollectionService(io.cdap.cdap.api.metrics.MetricsCollectionService) AuthenticationContextModules(io.cdap.cdap.security.auth.context.AuthenticationContextModules) DataSetsModules(io.cdap.cdap.data.runtime.DataSetsModules) DefaultOwnerAdmin(io.cdap.cdap.security.impersonation.DefaultOwnerAdmin) OwnerAdmin(io.cdap.cdap.security.impersonation.OwnerAdmin) NonCustomLocationUnitTestModule(io.cdap.cdap.common.guice.NonCustomLocationUnitTestModule) CConfiguration(io.cdap.cdap.common.conf.CConfiguration) AuthorizationTestModule(io.cdap.cdap.security.authorization.AuthorizationTestModule) AbstractModule(com.google.inject.AbstractModule) TransactionModules(org.apache.tephra.runtime.TransactionModules) LocalLogAppenderModule(io.cdap.cdap.logging.guice.LocalLogAppenderModule) TransactionManager(org.apache.tephra.TransactionManager) AuthorizationEnforcementModule(io.cdap.cdap.security.authorization.AuthorizationEnforcementModule) BeforeClass(org.junit.BeforeClass)

Example 9 with LoggingTester

use of io.cdap.cdap.logging.appender.LoggingTester in project cdap by caskdata.

the class TestFileLogging method testGetLogPrev.

@Test
public void testGetLogPrev() 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.testGetPrev(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 10 with LoggingTester

use of io.cdap.cdap.logging.appender.LoggingTester in project cdap by caskdata.

the class TestTMSLogging method testTmsLogAppender.

@Test
public void testTmsLogAppender() throws Exception {
    // setup TMSLogAppender and log messages to it
    LogAppenderInitializer logAppenderInitializer = new LogAppenderInitializer(tmsLogAppender);
    logAppenderInitializer.initialize("TestTMSLogging");
    Logger logger = LoggerFactory.getLogger("TestTMSLogging");
    LoggingTester loggingTester = new LoggingTester();
    LoggingContext loggingContext = new MapReduceLoggingContext("TKL_NS_1", "APP_1", "MR_1", "RUN1");
    loggingTester.generateLogs(logger, loggingContext);
    logAppenderInitializer.close();
    // fetch and deserialize all the logs from TMS
    LoggingEventSerializer loggingEventSerializer = new LoggingEventSerializer();
    Map<Integer, List<ILoggingEvent>> partitionedFetchedLogs = new HashMap<>();
    int totalFetchedLogs = 0;
    for (Map.Entry<Integer, TopicId> topicId : topicIds.entrySet()) {
        List<ILoggingEvent> fetchedLogs = new ArrayList<>();
        MessageFetcher messageFetcher = client.prepareFetch(topicId.getValue());
        try (CloseableIterator<RawMessage> messages = messageFetcher.fetch()) {
            while (messages.hasNext()) {
                RawMessage message = messages.next();
                ILoggingEvent iLoggingEvent = loggingEventSerializer.fromBytes(ByteBuffer.wrap(message.getPayload()));
                fetchedLogs.add(iLoggingEvent);
            }
        }
        totalFetchedLogs += fetchedLogs.size();
        partitionedFetchedLogs.put(topicId.getKey(), fetchedLogs);
    }
    // LoggingTester emits 240 logs in total
    Assert.assertEquals(240, totalFetchedLogs);
    // Read the partition that our LoggingContext maps to and filter the logs in there to the logs that correspond
    // to our LoggingContext.
    LogPartitionType logPartitionType = LogPartitionType.valueOf(cConf.get(Constants.Logging.LOG_PUBLISH_PARTITION_KEY).toUpperCase());
    String partitionKey = logPartitionType.getPartitionKey(loggingContext);
    int partition = TMSLogAppender.partition(partitionKey, cConf.getInt(Constants.Logging.NUM_PARTITIONS));
    Filter logFilter = LoggingContextHelper.createFilter(loggingContext);
    List<ILoggingEvent> filteredLogs = partitionedFetchedLogs.get(partition).stream().filter(logFilter::match).collect(Collectors.toList());
    // LoggingTester emits 60 logs with the given LoggingContext
    Assert.assertEquals(60, filteredLogs.size());
    for (int i = 0; i < filteredLogs.size(); i++) {
        ILoggingEvent loggingEvent = filteredLogs.get(i);
        Assert.assertEquals(String.format("Test log message %s arg1 arg2", i), loggingEvent.getFormattedMessage());
    }
}
Also used : MessageFetcher(io.cdap.cdap.messaging.MessageFetcher) MapReduceLoggingContext(io.cdap.cdap.logging.context.MapReduceLoggingContext) LoggingContext(io.cdap.cdap.common.logging.LoggingContext) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) LoggingEventSerializer(io.cdap.cdap.logging.serialize.LoggingEventSerializer) Logger(org.slf4j.Logger) ILoggingEvent(ch.qos.logback.classic.spi.ILoggingEvent) MapReduceLoggingContext(io.cdap.cdap.logging.context.MapReduceLoggingContext) LoggingTester(io.cdap.cdap.logging.appender.LoggingTester) LogAppenderInitializer(io.cdap.cdap.logging.appender.LogAppenderInitializer) LogPartitionType(io.cdap.cdap.logging.appender.kafka.LogPartitionType) Filter(io.cdap.cdap.logging.filter.Filter) ArrayList(java.util.ArrayList) List(java.util.List) TopicId(io.cdap.cdap.proto.id.TopicId) RawMessage(io.cdap.cdap.messaging.data.RawMessage) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Aggregations

LoggingTester (io.cdap.cdap.logging.appender.LoggingTester)14 WorkerLoggingContext (io.cdap.cdap.logging.context.WorkerLoggingContext)12 LoggingContext (io.cdap.cdap.common.logging.LoggingContext)10 Test (org.junit.Test)10 LogAppenderInitializer (io.cdap.cdap.logging.appender.LogAppenderInitializer)6 Logger (org.slf4j.Logger)6 FileLogReader (io.cdap.cdap.logging.read.FileLogReader)4 KafkaLogReader (io.cdap.cdap.logging.read.KafkaLogReader)4 BeforeClass (org.junit.BeforeClass)3 ILoggingEvent (ch.qos.logback.classic.spi.ILoggingEvent)2 AbstractModule (com.google.inject.AbstractModule)2 MetricsCollectionService (io.cdap.cdap.api.metrics.MetricsCollectionService)2 CConfiguration (io.cdap.cdap.common.conf.CConfiguration)2 ConfigModule (io.cdap.cdap.common.guice.ConfigModule)2 NonCustomLocationUnitTestModule (io.cdap.cdap.common.guice.NonCustomLocationUnitTestModule)2 NoOpMetricsCollectionService (io.cdap.cdap.common.metrics.NoOpMetricsCollectionService)2 NamespaceQueryAdmin (io.cdap.cdap.common.namespace.NamespaceQueryAdmin)2 SimpleNamespaceQueryAdmin (io.cdap.cdap.common.namespace.SimpleNamespaceQueryAdmin)2 DataSetsModules (io.cdap.cdap.data.runtime.DataSetsModules)2 StorageModule (io.cdap.cdap.data.runtime.StorageModule)2