Search in sources :

Example 1 with ActionLog

use of core.framework.impl.log.ActionLog in project core-ng-project by neowu.

the class KafkaMessageListenerThread method handle.

private <T> void handle(String topic, KafkaMessageListener.MessageHandlerHolder<T> holder, List<ConsumerRecord<String, byte[]>> records, double longProcessThresholdInNano) {
    for (ConsumerRecord<String, byte[]> record : records) {
        ActionLog actionLog = logManager.begin("=== message handling begin ===");
        try {
            actionLog.action("topic:" + topic);
            actionLog.context("topic", topic);
            actionLog.context("handler", holder.handler.getClass().getCanonicalName());
            actionLog.context("key", record.key());
            logger.debug("message={}", new BytesParam(record.value()));
            T message = holder.reader.fromJSON(record.value());
            Headers headers = record.headers();
            actionLog.refId(header(headers, KafkaHeaders.HEADER_REF_ID));
            String client = header(headers, KafkaHeaders.HEADER_CLIENT);
            if (client != null)
                actionLog.context("client", client);
            String clientIP = header(headers, KafkaHeaders.HEADER_CLIENT_IP);
            if (clientIP != null)
                actionLog.context("clientIP", clientIP);
            if ("true".equals(header(headers, KafkaHeaders.HEADER_TRACE))) {
                actionLog.trace = true;
            }
            holder.validator.validate(message);
            holder.handler.handle(record.key(), message);
        } catch (Throwable e) {
            logManager.logError(e);
        } finally {
            long elapsedTime = actionLog.elapsedTime();
            if (elapsedTime > longProcessThresholdInNano) {
                logger.warn(Markers.errorCode("LONG_PROCESS"), "took too long to process message, elapsedTime={}", elapsedTime);
            }
            logManager.end("=== message handling end ===");
        }
    }
}
Also used : BytesParam(core.framework.impl.log.filter.BytesParam) Headers(org.apache.kafka.common.header.Headers) ActionLog(core.framework.impl.log.ActionLog)

Example 2 with ActionLog

use of core.framework.impl.log.ActionLog in project core-ng-project by neowu.

the class KafkaMessageListenerThread method handle.

private <T> void handle(String topic, KafkaMessageListener.BulkMessageHandlerHolder<T> holder, List<ConsumerRecord<String, byte[]>> records, double longProcessThresholdInNano) {
    ActionLog actionLog = logManager.begin("=== message handling begin ===");
    try {
        actionLog.action("topic:" + topic);
        actionLog.context("topic", topic);
        actionLog.context("handler", holder.handler.getClass().getCanonicalName());
        actionLog.stat("messageCount", records.size());
        List<Message<T>> messages = new ArrayList<>(records.size());
        for (ConsumerRecord<String, byte[]> record : records) {
            T message = holder.reader.fromJSON(record.value());
            validate(holder.validator, message, record);
            messages.add(new Message<>(record.key(), message));
            if ("true".equals(header(record.headers(), KafkaHeaders.HEADER_TRACE))) {
                // trigger trace if any message is trace
                actionLog.trace = true;
            }
        }
        holder.handler.handle(messages);
    } catch (Throwable e) {
        logManager.logError(e);
    } finally {
        long elapsedTime = actionLog.elapsedTime();
        if (elapsedTime > longProcessThresholdInNano) {
            logger.warn(Markers.errorCode("LONG_PROCESS"), "took too long to process message, elapsedTime={}", elapsedTime);
        }
        logManager.end("=== message handling end ===");
    }
}
Also used : Message(core.framework.kafka.Message) ArrayList(java.util.ArrayList) ActionLog(core.framework.impl.log.ActionLog)

Example 3 with ActionLog

use of core.framework.impl.log.ActionLog in project core-ng-project by neowu.

the class ActionLogContext method track.

public static void track(String action, long elapsedTime, Integer readEntries, Integer writeEntries) {
    LogManager logManager = logManager();
    ActionLog actionLog = logManager.currentActionLog();
    if (actionLog != null) {
        actionLog.track(action, elapsedTime, readEntries, writeEntries);
    }
}
Also used : LogManager(core.framework.impl.log.LogManager) ActionLog(core.framework.impl.log.ActionLog)

Example 4 with ActionLog

use of core.framework.impl.log.ActionLog in project core-ng-project by neowu.

the class ActionLogContext method put.

public static void put(String key, Object value) {
    LogManager logManager = logManager();
    ActionLog actionLog = logManager.currentActionLog();
    if (actionLog != null) {
        // here to check null is for unit testing the logManager.begin may not be called
        actionLog.context(key, value);
    }
}
Also used : LogManager(core.framework.impl.log.LogManager) ActionLog(core.framework.impl.log.ActionLog)

Example 5 with ActionLog

use of core.framework.impl.log.ActionLog in project core-ng-project by neowu.

the class ActionLogContext method id.

public static String id() {
    LogManager logManager = logManager();
    ActionLog actionLog = logManager.currentActionLog();
    if (actionLog == null)
        return null;
    return actionLog.id;
}
Also used : LogManager(core.framework.impl.log.LogManager) ActionLog(core.framework.impl.log.ActionLog)

Aggregations

ActionLog (core.framework.impl.log.ActionLog)12 LogManager (core.framework.impl.log.LogManager)5 BytesParam (core.framework.impl.log.filter.BytesParam)1 RequestImpl (core.framework.impl.web.request.RequestImpl)1 Message (core.framework.kafka.Message)1 Job (core.framework.scheduler.Job)1 Response (core.framework.web.Response)1 HeaderMap (io.undertow.util.HeaderMap)1 HttpString (io.undertow.util.HttpString)1 ArrayList (java.util.ArrayList)1 Headers (org.apache.kafka.common.header.Headers)1