Add Graylog logging configuration #252#264
Conversation
ZohebShaikh
left a comment
There was a problem hiding this comment.
Looks good only few minor things
bda4336 to
831a990
Compare
- Extract GraylogOptions into its own struct, independent of TracingOptions - Remove .vscode/launch.json (to be added in a separate PR) - Remove version/build additional_field calls from Graylog logger - Switch let-else to if-let in init_graylog - Warn when Graylog URL has no port rather than silently defaulting - Add reconnect loop so dropped connections recover automatically - Improve connection error messages to distinguish DNS failure from TCP errors
831a990 to
0a86a82
Compare
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #264 +/- ##
==========================================
+ Coverage 76.44% 78.89% +2.45%
==========================================
Files 13 13
Lines 1944 2080 +136
==========================================
+ Hits 1486 1641 +155
+ Misses 458 439 -19 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
tpoliaw
left a comment
There was a problem hiding this comment.
Looks pretty good, thanks for looking at it. A couple of changes could make the error handling a bit cleaner and keep it more consistent with what is already there though.
498354e to
59d5002
Compare
59d5002 to
926a966
Compare
| #[derive(Debug, Parser)] | ||
| pub struct GraylogOptions { | ||
| /// The hostname of the Graylog GELF TCP input | ||
| #[clap(long = "graylog-host", env = "NUMTRACKER_GRAYLOG_HOST")] |
There was a problem hiding this comment.
nit: you don't need to specify the option string if it matches the field names and underscores are replaced automatically
| #[clap(long = "graylog-host", env = "NUMTRACKER_GRAYLOG_HOST")] | |
| #[clap(long, env = "NUMTRACKER_GRAYLOG_HOST")] |
| #[clap( | ||
| long = "graylog-port", | ||
| default_value_t = 12201, | ||
| env = "NUMTRACKER_GRAYLOG_PORT" | ||
| )] | ||
| pub(crate) graylog_port: u16, |
There was a problem hiding this comment.
nit: and here
| #[clap( | |
| long = "graylog-port", | |
| default_value_t = 12201, | |
| env = "NUMTRACKER_GRAYLOG_PORT" | |
| )] | |
| pub(crate) graylog_port: u16, | |
| #[clap(long, default_value_t = 12201, env = "NUMTRACKER_GRAYLOG_PORT")] | |
| pub(crate) graylog_port: u16, |
| } | ||
|
|
||
| pub fn init(logging: Option<Level>, tracing: &TracingOptions) -> Result<(), ExporterBuildError> { | ||
| fn init_graylog<S>(opts: &GraylogOptions) -> Result<Option<impl Layer<S>>, LoggingError> |
There was a problem hiding this comment.
It doesn't look like this method can ever fail. Do we need to return Result? And if not, do we need LoggingError?
| where | ||
| S: Subscriber + for<'s> LookupSpan<'s>, | ||
| { | ||
| if let Some(address) = opts.address() { |
There was a problem hiding this comment.
nit: Rather than putting the whole method in an if statement, you could use a let ... else check for the no-op case at the start and then shift everything else left.
let Some(address) = opts.address() else {
return None;
};
match Logger::builder()
// everything else the same but dedented| Ok(Some( | ||
| logger | ||
| .with_filter(LevelFilter::from_level(level)) | ||
| .with_filter(FilterFn::new(|m| { |
There was a problem hiding this comment.
Looking at the current logs in argocd, I think this would filter out the vast majority of the logging. It might be a good sign we should be logging more from numtracker directly but for now should we relax this a bit? The other loggers don't restrict messages to numtracker only.
| // Level defaults to INFO when not specified | ||
| assert_eq!(cli.graylog().level(), Level::INFO); | ||
|
|
||
| // Level can be overridden independently of host/port |
There was a problem hiding this comment.
nit: The rest of this test should probably be its own test
#252
Summary
tracing-gelflayer to ship structured logs to a Graylog instance via GELF TCP--graylog <URL>and--logging-level <LEVEL>CLI flags (also viaNUMTRACKER_GRAYLOG/NUMTRACKER_GRAYLOG_LOG_LEVELenv vars)numtracker.graylog.enabled/host/levelvalues