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

Split Container Logs sources for stdout vs stderr #11

Merged
merged 3 commits into from
Oct 3, 2023
Merged

Split Container Logs sources for stdout vs stderr #11

merged 3 commits into from
Oct 3, 2023

Conversation

tlmii
Copy link
Member

@tlmii tlmii commented Oct 2, 2023

The Container logs had stdout/stderr as separate streams, but we were reading them into one channel without differentiation. This PR splits them up so that error log entries can be rendered differently to the page based on their actual source.

As an example, prometheus logs are apparently all stderr at the moment (even though they say "level=info" in them), so they all show up red:

image

I also cleaned up the way line numbers were rendered in the logs (doesn't change the display, just how we do the display) and detection of timestamps in the logs (RFC3339Nano only at the moment) so that we don't just render whatever the first non-whitespace characters are as the timestamp.

@davidfowl
Copy link
Member

Image/gif?

@tlmii
Copy link
Member Author

tlmii commented Oct 2, 2023

Image/gif?

Added an image, though its nothing new - just the same red coloring for error logs, and a little clarification of what changed. I do have concerns about the stdout vs stderr intermingling, though, which I just added in chat.

@tlmii tlmii changed the title Split Container Logs Split Container Logs sources for stdout vs stderr Oct 2, 2023
@karolz-ms
Copy link
Member

We should rethink the coloring of logs based on whether they are delivered via stdout vs stderr

The classic Unix design is stdout is for machine-readable DATA vs stderr is for human-readable MESSAGES. So if something shows up on stderr, it does not necessarily mean it is a problem and what Prometheus does is arguably the right thing to do.

Copy link
Member

@karolz-ms karolz-ms left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great to me, just a couple suggestions/questions--HTH!

}
}

[GeneratedRegex("^(?:\\d{4})-(?:0[1-9]|1[0-2])-(?:0[1-9]|[12][0-9]|3[01])T(?:[01][0-9]|2[0-3]):(?:[0-5][0-9]):(?:[0-5][0-9])(?:\\.\\d{1,9})(?:Z|[+-](?:[01][0-9]|2[0-3]):[0-5][0-9])?$")]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where this came from? How do I ensure that this is correct, or update this? I think a comment would be very helpful here.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added a comment with details on the parts of this. It's both straightforward (no real regex trickery) and complicated (because its still regex). That also led me to realize part of it was wrong, so good idea there. The source was a combination of things, because no single source seemed to have a complete answer.

@tlmii
Copy link
Member Author

tlmii commented Oct 2, 2023

We should rethink the coloring of logs based on whether they are delivered via stdout vs stderr

The classic Unix design is stdout is for machine-readable DATA vs stderr is for human-readable MESSAGES. So if something shows up on stderr, it does not necessarily mean it is a problem and what Prometheus does is arguably the right thing to do.

Interesting. I wasn't aware of that. It seems like we have a blend of both though, as postgres is clearly treating stderr as human readable messages (even pointing you to documentation, etc). This is another scenario of how I'm not sure what to do about the stdout vs stderr "how to display issue.

@tlmii
Copy link
Member Author

tlmii commented Oct 2, 2023

We should rethink the coloring of logs based on whether they are delivered via stdout vs stderr

The classic Unix design is stdout is for machine-readable DATA vs stderr is for human-readable MESSAGES. So if something shows up on stderr, it does not necessarily mean it is a problem and what Prometheus does is arguably the right thing to do.

We discussed this a bit during dashboard triage and we're going to follow up as part of a larger conversation about the log display. Lots of questions (timestamps vs none, timestamps on each row vs on each "log entry", stdout vs std error interleaving and synchronization, stdout vs std error coloring/rendering, etc).

Copy link
Member

@karolz-ms karolz-ms left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great

}
}

// Regular Expression for an RFC3339 timestamp, including RFC3339Nano
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you 🤗

// $ - Ends the string
//
// Note: (?:) is a non-capturing group, since we don't care about the values, we are just interested in whether or not there is a match
[GeneratedRegex("^(?:\\d{4})-(?:0[1-9]|1[0-2])-(?:0[1-9]|[12][0-9]|3[01])T(?:[01][0-9]|2[0-3]):(?:[0-5][0-9]):(?:[0-5][0-9])(?:\\.\\d{1,9})?(?:Z|(?:[Z+-](?:[01][0-9]|2[0-3]):(?:[0-5][0-9])))?$")]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not saying this has to be done now, but for such long regular expressions, I like to define the fragments as C# constant strings, and then interpolate them into the final regex. If you chose the names well (for the fragments), it is self-documenting. IgnorePatternWhitespace option can also help.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense. Whenever I need to change this (probably whenever we figure out the project timestamps) I'll change it to work that way. Thanks for the suggestion!

@tlmii tlmii merged commit d9b098b into dotnet:main Oct 3, 2023
@tlmii tlmii deleted the dev/split-container-logs branch October 3, 2023 20:32
@github-actions github-actions bot locked and limited conversation to collaborators May 1, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants