Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

loki.source.journal - logs not preserving order when sent to loki with duplicate timestamps #2390

Open
Amoolaa opened this issue Jan 13, 2025 · 0 comments
Labels
bug Something isn't working

Comments

@Amoolaa
Copy link

Amoolaa commented Jan 13, 2025

What's wrong?

Hello 👋

I am regularly experiencing cases where the microsecond precision of journal is not high enough and there are multiple log lines with the same REALTIME_TIMESTAMP appearing. When querying journal via journalctl, the log order is preserved correctly. However, receiving logs via loki.source.journal and sending to loki does not preserve this order (presumably because it's just ordering based on timestamp in loki, unlike journal). This is an issue as we are attempting to replace rsyslog with Alloy's journal component in Amazon Linux 2023.

With journal's microsecond precision vs loki's nanosecond precision, I'm thinking it may be possible to increment the REALTIME_TIMESTAMP by one nanosecond for each entry with the same timestamp to at least try and prevent collisions (in the same way that loki does it in limits_config.increment_duplicate_timestamp).

Steps to reproduce

Run a basic systemd unit to run this python script:

import time
from datetime import datetime
import sys

def collect_timestamps():
    timestamps = []
    for _ in range(5):
        current_time = datetime.now().strftime('%Y-%m-%d %H:%M:%S.%f')
        timestamps.append(current_time)
    return timestamps

def main():
    while True:
        timestamps = collect_timestamps()
        for timestamp in timestamps:
            print(timestamp, end='\n', flush=False)
        sys.stdout.flush()
        time.sleep(10) 

if __name__ == "__main__":
    main()

that flushes a bunch of timestamps to stdout every 10 seconds.

System information

Amazon Linux 2023

Software version

Grafana Alloy v1.5.1

Configuration


Logs


@Amoolaa Amoolaa added the bug Something isn't working label Jan 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant