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

ref!: adopt log/slog + other prom configs, drop custom logging pkg #1586

Merged
merged 3 commits into from
Dec 28, 2024

Conversation

tjhop
Copy link
Contributor

@tjhop tjhop commented Dec 3, 2024

I would call this a breaking change, as there are updates to command line flag interactions.

Changes included:

  • convert --debug bool flag -> --log.level string flag. this aligns with prom conventions. This project uses urfave/cli for application commands/flags rather than kingpin as other go packages do, so I couldn't use the promslog/flag pkg directly. Rather, I use our upstream promslog/kingpin configs in the configs we pass here for urfave/cli. We can decide to move off urfave/cli and/or adopt kingpin in the future.
  • removes pkg/logging in favor of using prometheus/common/promslog. A small utility function is included in main to simplify some boilerplate with logger initialization, since we instantiate in main in a few places. All functions have been converted to accept/use *slog.Loggers rather than the custom logger interface.
  • the removal of the custom logging pkg also removes the IsDebugEnabled() method, but this is fine because the logger is leveled; debug logs will not print unless --log.level debug is passed at the command line, there is no need to check if debug is enabled at log time in the vast majority of cases.
  • Updates tests as needed; updates nop loggers, test signatures that used IsDebugEnabled(), etc.
  • enable sloglint in golangci-lint, remove go-kit/log configs

I would call this a breaking change, as there are updates to command
line flag interactions.

Changes included:
- convert `--debug` bool flag -> `--log.level` string flag. this aligns
  with prom conventions. This project uses urfave/cli for application
commands/flags rather than kingpin as other go packages do, so I
couldn't use the promslog/flag pkg directly. Rather, I use our upstream
promslog/kingpin configs in the configs we pass here for urfave/cli. We
can decide to move off urfave/cli and/or adopt kingpin in the future.
- removes `pkg/logging` in favor of using `prometheus/common/promslog`.
  A small utility function is included in main to simplify some
boilerplate with logger initialization, since we instantiate in main in
a few places. All functions have been converted to accept/use
*slog.Loggers rather than the custom logger interface.
- the removal of the custom logging pkg also removes the
  `IsDebugEnabled()` method, but this is fine because the logger is
leveled; debug logs will not print unless `--log.level debug` is passed
at the command line, there is no need to check if debug is enabled at
log time in the vast majority of cases.
- Updates tests as needed; updates nop loggers, test signatures that
  used `IsDebugEnabled()`, etc.
- enable sloglint in golangci-lint, remove go-kit/log configs

Signed-off-by: TJ Hoplock <[email protected]>
@tjhop
Copy link
Contributor Author

tjhop commented Dec 3, 2024

Supercedes #1577

cc: @SuperQ

@SuperQ
Copy link
Contributor

SuperQ commented Dec 3, 2024

Thanks, we'll probably slowly convert over other things like urfave/cli to Prometheus community normal components over time.

Copy link
Contributor

@SuperQ SuperQ left a comment

Choose a reason for hiding this comment

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

Great work!

@tjhop
Copy link
Contributor Author

tjhop commented Dec 4, 2024

Looking into the config verification failure in tests

tjhop added 2 commits December 4, 2024 20:34
Code was totally valid, but it was setting the format twice. Intention
is to set the level. 🤦

Prevents panics when using the logger due to level being nil:

https://github.com/prometheus-community/yet-another-cloudwatch-exporter/actions/runs/12147649411/job/33881684148?pr=1586

Signed-off-by: TJ Hoplock <[email protected]>
@tjhop
Copy link
Contributor Author

tjhop commented Dec 5, 2024

Alright, I fixed up the verification test; panic was caused by a typo/wrong variable reference. Sorted out now 👍

@tjhop
Copy link
Contributor Author

tjhop commented Dec 28, 2024

Bump, lemme know if there's any other feedback 👍

@SuperQ
Copy link
Contributor

SuperQ commented Dec 28, 2024

Thanks!

@SuperQ SuperQ merged commit 951e1f0 into prometheus-community:master Dec 28, 2024
4 checks passed
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

Successfully merging this pull request may close these issues.

2 participants