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

promslog: Make AllowedLevel concurrency safe. #754

Merged
merged 2 commits into from
Feb 3, 2025
Merged

promslog: Make AllowedLevel concurrency safe. #754

merged 2 commits into from
Feb 3, 2025

Conversation

bwplotka
Copy link
Member

Needed for prometheus/prometheus#10352

Also I renamed AllowedLevel and AllowedFormat to Level and Format. Default level (and String()) is also now 'info' not empty.

It's a breaking change, but I suspect nobody was using those constructs directly, WDYT?

cc @tjhop

@bwplotka bwplotka requested a review from SuperQ January 31, 2025 13:32
Needed for prometheus/prometheus#10352

Also I renamed AllowedLevel and AllowedFormat to Level and Format.
Default level (and String()) is also now 'info' not empty.

It's a breaking change, but I suspect nobody was using those constructs directly, WDYT?

Signed-off-by: bwplotka <[email protected]>
err := yaml.Unmarshal([]byte(``), l)
if err != nil {
t.Error(err)
}
if l.s != "" {
t.Errorf("expected empty level, got %s", l.s)
if got := l.String(); got != "info" {
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 changed the behaviour purposefully. This simplifies (and optimizes) the level code.

I don't know exactly how Unmarshal and String was envisioned to be used in the YAML context. Does this blocks anyone?

type AllowedFormat struct {
// Format controls a logging output format.
// Not concurrency-safe.
type Format struct {
Copy link
Member Author

Choose a reason for hiding this comment

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

As mentioned in the description - this is a breaking change, let me know if this is ok.

Copy link
Member

@SuperQ SuperQ Jan 31, 2025

Choose a reason for hiding this comment

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

Yes, OK this breaking change.

Any chance you would keep the old struct around and add a Deprecated comment so downstream Go users get a linter warning?

Copy link
Member

Choose a reason for hiding this comment

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

Or, maybe it's better to just drop the struct so it's a compile error.

Copy link
Member Author

Choose a reason for hiding this comment

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

For deprecated flow we would need to maintain a behaviour which means promslog.Config using old thing, we can but until we are v1 and this is not too painful we can break.

// Level controls a logging level, with an info default.
// It wraps slog.LevelVar with string-based level control.
// Level is safe to be used concurrently.
type Level struct {
Copy link
Member Author

Choose a reason for hiding this comment

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

As mentioned in the description - this (rename) is a breaking change, let me know if this is ok.

@tjhop
Copy link
Contributor

tjhop commented Jan 31, 2025

It's a breaking change, but I suspect nobody was using those constructs directly, WDYT?

There are at least a few that I know of:

promtheus json file logger:
https://github.com/prometheus/prometheus/blob/main/util/logging/file.go#L48-L53

prom api testing
https://github.com/prometheus/prometheus/blob/main/web/api/v1/api_test.go#L483-L484

blackbox exporter custom probe logging (handler.go and handler_test.go)
https://github.com/prometheus/blackbox_exporter/blob/master/prober/handler.go#L172

Updates shouldn't be difficult, but a few will be needed after the breaking change

Copy link
Contributor

@tjhop tjhop left a comment

Choose a reason for hiding this comment

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

I'm on board 👍

@bwplotka bwplotka merged commit a784287 into main Feb 3, 2025
10 checks passed
@bwplotka bwplotka deleted the iss10352 branch February 3, 2025 08:50
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.

3 participants