Search in sources :

Example 1 with ActionLogMessage

use of core.framework.log.message.ActionLogMessage in project core-ng-project by neowu.

the class ActionLogMessageFactoryTest method actionLog.

@Test
void actionLog() {
    var log = new ActionLog("begin", null);
    log.action("action");
    log.process(new LogEvent("logger", Markers.errorCode("ERROR_CODE"), LogLevel.WARN, "message", null, null));
    log.track("db", 1000, 1, 2);
    log.track("http", 2000, 0, 0);
    log.context("order_id", "id1", "id2");
    ActionLogMessage message = factory.create(log);
    assertThat(message).isNotNull();
    assertThat(message.app).isEqualTo(LogManager.APP_NAME);
    assertThat(message.action).isEqualTo("action");
    assertThat(message.errorCode).isEqualTo("ERROR_CODE");
    assertThat(message.traceLog).isNotEmpty();
    PerformanceStatMessage stats = message.performanceStats.get("db");
    assertThat(stats.totalElapsed).isEqualTo(1000);
    assertThat(stats.count).isEqualTo(1);
    assertThat(stats.readEntries).isEqualTo(1);
    assertThat(stats.writeEntries).isEqualTo(2);
    stats = message.performanceStats.get("http");
    assertThat(stats.totalElapsed).isEqualTo(2000);
    assertThat(stats.count).isEqualTo(1);
    assertThat(stats.readEntries).isNull();
    assertThat(stats.writeEntries).isNull();
}
Also used : PerformanceStatMessage(core.framework.log.message.PerformanceStatMessage) ActionLogMessage(core.framework.log.message.ActionLogMessage) Test(org.junit.jupiter.api.Test)

Example 2 with ActionLogMessage

use of core.framework.log.message.ActionLogMessage in project core-ng-project by neowu.

the class LogProcessorApp method configureLogForwarders.

private Forwarders configureLogForwarders() {
    var forwarders = new Forwarders();
    // configure by env APP_LOG_FORWARD_CONFIG
    String configValue = property("app.log.forward.config").orElse(null);
    if (configValue != null) {
        Bean.register(LogForwardConfig.class);
        LogForwardConfig config = Bean.fromJSON(LogForwardConfig.class, configValue);
        kafka("forward").uri(config.kafkaURI);
        LogForwardConfig.Forward actionConfig = config.action;
        if (actionConfig != null) {
            MessagePublisher<ActionLogMessage> publisher = kafka("forward").publish(ActionLogMessage.class);
            forwarders.action = new ActionLogForwarder(publisher, actionConfig.topic, actionConfig.apps, actionConfig.ignoreErrorCodes);
        }
        LogForwardConfig.Forward eventConfig = config.event;
        if (eventConfig != null) {
            MessagePublisher<EventMessage> publisher = kafka("forward").publish(EventMessage.class);
            forwarders.event = new EventForwarder(publisher, eventConfig.topic, eventConfig.apps, eventConfig.ignoreErrorCodes);
        }
    }
    return forwarders;
}
Also used : EventForwarder(core.log.service.EventForwarder) EventMessage(core.framework.log.message.EventMessage) LogForwardConfig(core.log.LogForwardConfig) ActionLogMessage(core.framework.log.message.ActionLogMessage) ActionLogForwarder(core.log.service.ActionLogForwarder)

Example 3 with ActionLogMessage

use of core.framework.log.message.ActionLogMessage in project core-ng-project by neowu.

the class ActionServiceTest method bulkIndex.

@Test
void bulkIndex() {
    List<ActionLogMessage> messages = Lists.newArrayList();
    for (int i = 0; i < 6; i++) {
        ActionLogMessage message = message("bulk-" + i, "TRACE");
        message.traceLog = "trace";
        messages.add(message);
    }
    LocalDate now = LocalDate.of(2016, Month.JANUARY, 15);
    actionService.index(messages, now);
    ActionDocument action = actionDocument(now, messages.get(0).id);
    assertThat(action.result).isEqualTo("TRACE");
}
Also used : ActionLogMessage(core.framework.log.message.ActionLogMessage) LocalDate(java.time.LocalDate) ActionDocument(core.log.domain.ActionDocument) Test(org.junit.jupiter.api.Test) IntegrationTest(core.log.IntegrationTest)

Example 4 with ActionLogMessage

use of core.framework.log.message.ActionLogMessage in project core-ng-project by neowu.

the class ActionService method index.

void index(List<ActionLogMessage> messages, LocalDate now) {
    if (messages.size() <= 5) {
        // use single index in quiet time
        for (ActionLogMessage message : messages) {
            index(message, now);
        }
    } else {
        Map<String, ActionDocument> actions = Maps.newHashMapWithExpectedSize(messages.size());
        Map<String, TraceDocument> traces = Maps.newHashMap();
        for (ActionLogMessage message : messages) {
            actions.put(message.id, action(message));
            if (message.traceLog != null) {
                traces.put(message.id, trace(message));
            }
        }
        indexActions(actions, now);
        if (!traces.isEmpty()) {
            indexTraces(traces, now);
        }
    }
}
Also used : ActionLogMessage(core.framework.log.message.ActionLogMessage) ActionDocument(core.log.domain.ActionDocument) TraceDocument(core.log.domain.TraceDocument)

Example 5 with ActionLogMessage

use of core.framework.log.message.ActionLogMessage in project core-ng-project by neowu.

the class ActionServiceTest method index.

@Test
void index() {
    ActionLogMessage message1 = message("1", "OK");
    message1.context = Map.of("key", List.of("value"));
    message1.stats = Map.of("count", 1d);
    message1.correlationIds = List.of("id1", "id2");
    message1.clients = List.of("client");
    var stat = new PerformanceStatMessage();
    stat.count = 1;
    stat.totalElapsed = 10L;
    stat.readEntries = 1;
    stat.writeEntries = 2;
    message1.performanceStats = Map.of("redis", stat);
    ActionLogMessage message2 = message("2", "WARN");
    message2.traceLog = "trace";
    LocalDate now = LocalDate.of(2016, Month.JANUARY, 15);
    actionService.index(List.of(message1, message2), now);
    ActionDocument action = actionDocument(now, message1.id);
    assertThat(action.timestamp).isEqualTo(message1.date);
    assertThat(action.result).isEqualTo(message1.result);
    assertThat(action.correlationIds).isEqualTo(message1.correlationIds);
    assertThat(action.refIds).isEqualTo(message1.refIds);
    assertThat(action.clients).isEqualTo(message1.clients);
    assertThat(action.performanceStats.get("redis")).usingRecursiveComparison().isEqualTo(message1.performanceStats.get("redis"));
    assertThat(action.context).containsEntry("key", List.of("value"));
    TraceDocument trace = traceDocument(now, message2.id);
    assertThat(trace.content).isEqualTo(message2.traceLog);
    elasticSearch.refreshIndex(indexService.indexName("action", now));
    List<ActionDocument> actions = searchActionDocument(now, "context.key", "value");
    assertThat(actions).hasSize(1);
}
Also used : PerformanceStatMessage(core.framework.log.message.PerformanceStatMessage) ActionLogMessage(core.framework.log.message.ActionLogMessage) LocalDate(java.time.LocalDate) ActionDocument(core.log.domain.ActionDocument) TraceDocument(core.log.domain.TraceDocument) Test(org.junit.jupiter.api.Test) IntegrationTest(core.log.IntegrationTest)

Aggregations

ActionLogMessage (core.framework.log.message.ActionLogMessage)6 Test (org.junit.jupiter.api.Test)4 IntegrationTest (core.log.IntegrationTest)3 ActionDocument (core.log.domain.ActionDocument)3 PerformanceStatMessage (core.framework.log.message.PerformanceStatMessage)2 TraceDocument (core.log.domain.TraceDocument)2 LocalDate (java.time.LocalDate)2 EventMessage (core.framework.log.message.EventMessage)1 LogForwardConfig (core.log.LogForwardConfig)1 ActionLogForwarder (core.log.service.ActionLogForwarder)1 EventForwarder (core.log.service.EventForwarder)1