-
Notifications
You must be signed in to change notification settings - Fork 4
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
Various improvements around logging & JSON #9
base: main
Are you sure you want to change the base?
Conversation
When using the JSON logging backend, tracing expects the fields to have been formatted as a JSON string. However, the layer wasn't set up properly for that, resulting in a variety of "field_error"s in the logs (and panics on debug builds). As it turns out, we were setting it up in an overcomplicated way regardless, so use the simpler helper functions in tracing that set all of this up for us. Signed-off-by: Ryan Gonzalez <[email protected]>
While thinking on #6 and the accidental / intentional use of gitlab.output, it occurred to me that the way we show errors for GitLab is not actually how we'd want them logged with JSON logging (which currently dumps the entire error string, *including ANSI codes*, inside the JSON objects). With this in mind, I realized we can get the color-eyre handler's span traces and just convert it to JSON manually. This would be all, if we could actually log JSON from tracing. Unfortunately, any extra fields logged are converted to strings via Debug and stored as such in the JSON fields. That means we end up with our beautiful JSON errors stuck as strings and filled with dozens of escape sequences, which also makes them entirely unreadable without taking the JSON apart. But! tracing has "unstable" (can change in a bugfix release, but isn't that what Cargo.lock is for anyway?) functionality that integrates with the valuable crate, such that any field value that's a Valuable will be serialized as JSON. So, the eyre Report is converted to an intermediate Valuable that gets sent to tracing, which dutifully serializes it as an actual JSON object. This does, however, still have an unfortunate missing piece, which is serializing the fields in the span trace. tracing-error serializes fields into a string to be retrieved when the span trace is collected, which isn't the JSON format we would want. Now, this *can* be changed to format JSON, but that's not very useful because: - It means that span trace fields will be shown as JSON in the GitLab logs too, which isn't great. - There is no straightforward way to go from a JSON string to a Valuable: valuable only includes ways to go serialize a Valuable via Serde, without any way of *deserializing*. This would only be possible by manually converting everything, which is increasing the already-high complexity. In practice, the individual field values don't really have complex JSON values, so leaving the default non-JSON formatting there is fine. Signed-off-by: Ryan Gonzalez <[email protected]>
Terminology like "build status" and "dirty" isn't super helpful, so try to make it clearer what's going on. Signed-off-by: Ryan Gonzalez <[email protected]>
This can happen due to e.g. configuration issues on the repo, so it makes sense to log it somewhere other than just the service logs. Signed-off-by: Ryan Gonzalez <[email protected]>
The one thing i don't like here is the amount of boilerplate/scaffolding that's being added for logging; That's really something we should see if we can improve in the runner crate itself rather then having all these gymnastics in a runner implementation |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me, but for an actual review you need @sjoerdsimons.
previous_code = Some(code); | ||
} | ||
|
||
tokio::time::sleep(options.sleep_on_building).await; | ||
} | ||
PackageBuildState::Dirty => { | ||
if !was_dirty { | ||
outputln!("Package is dirty, trying again later..."); | ||
outputln!( | ||
"Package build is dirty / being re-scheduled, \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe "Package build status is being re-calculated"?
Commits have more detailed descriptions of the changes, the TLDR is that I wanted errors to be formatted normally in the service logs and ended up down a terrifying rabbit hole. Supersedes #6.