tkowalcz / tjahzi

Java clients, log4j2 and logback appenders for Grafana Loki
MIT License
106 stars 18 forks source link

Dropping Log lines when logBuffer.tryClaim fails to get positive claim value #106

Open ayubkhan opened 1 year ago

ayubkhan commented 1 year ago

We are loosing logs using this library. We have tried bufferSizeMegabytes="128" but still can reproduce.

https://github.com/tkowalcz/tjahzi/blob/master/core/src/main/java/pl/tkowalcz/tjahzi/TjahziLogger.java#L35

I have tested this with "LokiAppenderTest.java" after modifying TjahziLogger.java to randomly fix claim=0. When claim=0, the "LokiAppenderTest.java" test fails after repeatedly printing status logs.

    public TjahziLogger log(long timestamp,
                            LabelSerializer serializedLabels,
                            ByteBuffer line) {
...
        int claim = logBuffer.tryClaim(LOG_MESSAGE_TYPE_ID, requiredSize);
        boolean tryToFail = new Random().nextBoolean();
        if (tryToFail) {
            claim = 0;
        }
        if (claim > 0) {
            putMessageOnRing(
tkowalcz commented 1 year ago

Thanks for the bug report. I'll investigate.