Search in sources :

Example 6 with ActionDocument

use of core.log.domain.ActionDocument in project core-ng-project by neowu.

the class ActionDiagram method tooltip.

String tooltip(String action, String app, List<ActionDocument> actions) {
    var builder = new CodeBuilder();
    builder.append("<table>\n").append("<caption>{}</caption>\n", action).append("<tr><td>app</td><td>{}</td></tr>\n", app);
    buildActionInfo(builder, actions);
    builder.append("<tr><td colspan=2 class=section>action id</td></tr>\n");
    for (ActionDocument doc : actions) {
        if ("WARN".equals(doc.result) || "ERROR".equals(doc.result)) {
            String color = "WARN".equals(doc.result) ? "OrangeRed" : "Red";
            builder.append("<tr style='color:{}'><td>{}</td><td>{}</td></tr>\n", color, doc.id, doc.errorCode);
        } else {
            builder.append("<tr><td colspan=2>{}</td></tr>\n", doc.id);
        }
    }
    builder.append("</table>");
    return builder.build();
}
Also used : CodeBuilder(core.framework.internal.asm.CodeBuilder) ActionDocument(core.log.domain.ActionDocument)

Example 7 with ActionDocument

use of core.log.domain.ActionDocument in project core-ng-project by neowu.

the class ActionDiagram method buildActionInfo.

private void buildActionInfo(CodeBuilder builder, List<ActionDocument> actions) {
    ActionDocument firstAction = actions.get(0);
    List<String> controller = firstAction.context.get("controller");
    if (controller != null) {
        builder.append("<tr><td>controller</td><td>{}</td></tr>\n", controller.get(0));
    }
    List<String> jobClass = firstAction.context.get("job_class");
    if (jobClass != null) {
        builder.append("<tr><td>job class</td><td>{}</td></tr>\n", jobClass.get(0));
    }
    List<String> handler = firstAction.context.get("handler");
    if (handler != null) {
        builder.append("<tr><td>handler</td><td>{}</td></tr>\n", handler.get(0));
    }
}
Also used : ActionDocument(core.log.domain.ActionDocument)

Example 8 with ActionDocument

use of core.log.domain.ActionDocument in project core-ng-project by neowu.

the class ActionDiagram method messagePublishes.

private Map<String, Set<String>> messagePublishes() {
    // topic -> clients
    Map<String, Set<String>> publishes = new HashMap<>();
    actions.forEach((key, value) -> {
        if (key.action.startsWith("topic:") && !key.action.contains(":task:")) {
            String topic = key.action.substring(6);
            Set<String> clients = publishes.computeIfAbsent(topic, k -> new HashSet<>());
            for (ActionDocument action : value) {
                if (action.clients == null) {
                    clients.add("_direct_" + key.app);
                } else {
                    clients.addAll(action.clients);
                }
            }
        }
    });
    return publishes;
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) HashMap(java.util.HashMap) ActionDocument(core.log.domain.ActionDocument)

Example 9 with ActionDocument

use of core.log.domain.ActionDocument 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 10 with ActionDocument

use of core.log.domain.ActionDocument 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

ActionDocument (core.log.domain.ActionDocument)10 ActionLogMessage (core.framework.log.message.ActionLogMessage)3 IntegrationTest (core.log.IntegrationTest)2 TraceDocument (core.log.domain.TraceDocument)2 LocalDate (java.time.LocalDate)2 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 Test (org.junit.jupiter.api.Test)2 Query (co.elastic.clients.elasticsearch._types.query_dsl.Query)1 CodeBuilder (core.framework.internal.asm.CodeBuilder)1 PerformanceStatMessage (core.framework.log.message.PerformanceStatMessage)1 SearchRequest (core.framework.search.SearchRequest)1 NotFoundException (core.framework.web.exception.NotFoundException)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Map (java.util.Map)1 Set (java.util.Set)1