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

Fix logging behavior around setting goproc limits #2018

Merged
merged 8 commits into from
Aug 13, 2024

Conversation

tstirrat15
Copy link
Contributor

Fixes #2010

Description

In the implementation of #1921, we added memory and proc limits at the top level, along with logging from those libraries. Because it sits above the level of any of the commands, it didn't respect log levels. This fixes it by moving it into a PreRunE wrapper that sits below the level of log setup, which also means that it will be correctly formatted when running from the command line, and also only apply to commands that need it (we probably don't need it on version, for example).

Notes

@ecordell made the point that this would probably be useful in Materialize as well; if it's desired, we can push this up into cobrautil and pull it into both projects that way.

Questions

  • Are there any downsides to pushing this limit setting down? It makes sense to me that it should happen as early as possible in process bootstrapping, and I don't know enough about the Go runtime to know whether these are things that can be modified willy-nilly on a running process.

Changes

  • Move setup logic from main into a dedicated RunE function
  • Use that RunE function in the DefaultPreRunE function

Testing

See that spicedb version no longer reports changes from the limit libraries. See that if you set --log-level debug, you see output related to these libs nicely-formatted early in the output of spicedb serve and friends.

@tstirrat15 tstirrat15 requested a review from a team as a code owner August 12, 2024 21:34
@github-actions github-actions bot added the area/CLI Affects the command line label Aug 12, 2024
// SetLimitsRunE wraps the RunFunc with setup logic for memory limits and maxprocs
// limits for the go process. Implementing it here means that we can use already-
// established loggers and wrap only those commands that require it.
func SetLimitsRunE() cobrautil.CobraRunFunc {
Copy link
Contributor

Choose a reason for hiding this comment

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

This seems useful enough to put into cobrautil so it can be used across other projects.

Copy link
Contributor

@alecmerdler alecmerdler left a comment

Choose a reason for hiding this comment

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

I would vote to move this into cobrautil.

@github-actions github-actions bot added the area/dependencies Affects dependencies label Aug 13, 2024
Copy link
Contributor

@alecmerdler alecmerdler left a comment

Choose a reason for hiding this comment

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

Nice

@tstirrat15 tstirrat15 added this pull request to the merge queue Aug 13, 2024
Merged via the queue into main with commit 881a32e Aug 13, 2024
22 checks passed
@tstirrat15 tstirrat15 deleted the 2010-fix-logging-behavior branch August 13, 2024 19:17
@github-actions github-actions bot locked and limited conversation to collaborators Aug 13, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area/CLI Affects the command line area/dependencies Affects dependencies
Projects
None yet
Development

Successfully merging this pull request may close these issues.

GOMAXPROCS, GOMEMLIMIT logs emitted on all CLI commands
2 participants