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

Malformed output when log contains an equals sign #2834

Closed
tigerchase96 opened this issue Mar 19, 2024 · 8 comments
Closed

Malformed output when log contains an equals sign #2834

tigerchase96 opened this issue Mar 19, 2024 · 8 comments
Assignees

Comments

@tigerchase96
Copy link

Describe the bug
Whenever a container's console output contains a = b, Dozzle seems to misinterpret the line as a series of variables and ends up malforming the entire line.

To Reproduce

  1. Run some variation of the following code, in any container. This example is in Python but the language doesn't matter. The only important part is the second print statement.
import time

print("hello world")
print("Failed to run somecommand with somevariable = 1")

while True:
    time.sleep(1)
  1. Open the Dozzle logs for the container
  2. Observe that the output looks like the screenshot below

Expected behavior
I expected the message to be printed as-is: Failed to run somecommand with somevariable = 1

Screenshots

image

Desktop (please complete the following information):

  • OS: Windows 10
  • Docker version: 25.0.3
  • Browser & version: Chrome 122.0.6261.129
  • Version: v6.3.1
@amir20
Copy link
Owner

amir20 commented Mar 19, 2024

Hmm that does seem like a tricky bug. Dozzle supports https://grafana.com/docs/loki/latest/send-data/promtail/stages/logfmt/ but the parser seems pretty relaxed.

I am not sure how to fix it.

@amir20
Copy link
Owner

amir20 commented Mar 19, 2024

Looks like I do strings.Contains(message, "="). Maybe I should change it to some regex without spaces around =.

@ncrothers
Copy link

ncrothers commented Mar 19, 2024

Would it be reasonable to check if the message matches regex something like ^[^ ]+=[^ ].*? This would expect the message to start with a key that contains no spaces (which I think is a reasonable restriction), which I would imagine is a typical use case for key-value logs. That way it would match:

time=2012-11-01T22:08:41+00:00

But none of these:

This is a log message: "key=value"
Testing a variable = 2

@tigerchase96
Copy link
Author

Thanks for the quick reply! If you can't find a good way to improve the regex, another option could be adding a new environment variable that disables all parsing and prints all messages as-is. Just tossing out an idea. 🙂

@amir20
Copy link
Owner

amir20 commented Mar 19, 2024

adding a new environment variable that disables all parsing and prints all messages as-is. Just tossing out an idea

Not worth it. Makes testing and configuration harder.

Let me play around with regex.

@amir20
Copy link
Owner

amir20 commented Mar 19, 2024

This should be fixed with #2835. Can you try it with amir20/dozzle:pr-2835?

@tigerchase96
Copy link
Author

That appears to have fixed my problem. Just to be sure, I tested out some different variants to see what the output looks like:

print("Failed to run somecommand with somevariable = 1")
print("Failed to run somecommand with somevariable=1")
print("somevariable=1")
print("somevariable = 1")
print("somevariable=1 another=2")
print("somevariable = 1 another = 2")

image

My original test case is now correct, and somevariable=1 another=2 is still being parsed as expected.
I'm wondering if somevariable=1 should have been picked up by your updated regex, however.

@amir20
Copy link
Owner

amir20 commented Mar 19, 2024

somevariable=1 does not work because I check for at least two valid key value pairs. So I think it's ok. The reason is that a single log with key sounds like a bug. Will merge now.

@amir20 amir20 closed this as completed in 993b3fd Mar 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants