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

pkg/util/log: selectively apply file-defaults.format-options to stderr #113532

Merged
merged 2 commits into from
Nov 2, 2023

Conversation

abarganier
Copy link
Contributor

Fixes: #113321

The stderr sink in the log config is only allowed to use the
crdb-v2-tty format, and therefore, only format-options supported by
the crdb-v2-tty format should be applied to the stderr sink.

Unfortunately, a bug in the log config parse & validation code didn't
follow this rule. The configuration that's part of the file-defaults
is propagated to the stderr sink, and this included the
format-options, even if they were only relevant to another log format
type (e.g. json). This caused an error when trying to apply the
options to the stderr log sink on startup, e.g.:

ERROR: unknown format option: "datetime-format"

To solve this problem, we should only propagate the format-options
used in file-defaults to the stderr sink's config IFF the
file-defaults format is of a crdb-v2 variety. Since the stderr sink
also uses the crdb-v2-tty format, we can only be sure that the
format-options used in file-defaults is supported by the stderr sink
if the format used in file-defaults is also part of crdb-v2.

However, if format-options is explicitly defined within the
sinks.stderr config, we need to be careful not to overwrite them with
those defined in file-defaults.

This patch accomplishes fixes for all these issues, and adds new tests
to cover all these scenarios.

Release note: none

Code used to validate the stderr config parsing previously checked to
see if the `crdb-v1-tty` format was being used when `auditable: true`
was set. If it was, it changed the format to `crdb-v1-tty-count`.

However, the `crdb-v1` log formats have long been deprecated, and the
official logging documentation states:

https://www.cockroachlabs.com/docs/stable/configure-logs#output-to-stderr
> Note: The `format` parameter for `stderr` is set to `crdb-v2-tty` and
cannot be changed.

Given this, it not longer makes sense to have code that accounts for a
stderr log format that's no longer valid. Instead, we should *always*
assert the format to be `crdb-v2-tty` to align with what our
documentation says. A following patch will add this assertion.

Release note: none
@abarganier abarganier requested review from a team and dhartunian and removed request for a team October 31, 2023 20:46
@cockroach-teamcity
Copy link
Member

This change is Reviewable

@abarganier abarganier added the backport-23.2.x Flags PRs that need to be backported to 23.2. label Oct 31, 2023
Fixes: cockroachdb#113321

The stderr sink in the log config is only allowed to use the
`crdb-v2-tty` format, and therefore, only `format-options` supported by
the `crdb-v2-tty` format should be applied to the stderr sink.

Unfortunately, a bug in the log config parse & validation code didn't
follow this rule. The configuration that's part of the `file-defaults`
is propagated to the stderr sink, and this included the
`format-options`, even if they were only relevant to another log format
type (e.g. `json`). This caused an error when trying to apply the
options to the stderr log sink on startup, e.g.:
```
ERROR: unknown format option: "datetime-format"
```

To solve this problem, we should only propagate the `format-options`
used in `file-defaults` to the stderr sink's config IFF the
`file-defaults` format is of a `crdb-v2` variety. Since the stderr sink
also uses the `crdb-v2-tty` format, we can only be sure that the
`format-options` used in `file-defaults` is supported by the stderr sink
if the `format` used in `file-defaults` is also part of `crdb-v2`.

However, if `format-options` is explicitly defined within the
`sinks.stderr` config, we need to be careful not to overwrite them with
those defined in `file-defaults`.

This patch accomplishes fixes for all these issues, and adds new tests
to cover all these scenarios.

Release note: none
Copy link
Collaborator

@dhartunian dhartunian left a comment

Choose a reason for hiding this comment

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

:lgtm: thanks for this!

Reviewed 1 of 1 files at r1, all commit messages.
Reviewable status: :shipit: complete! 1 of 0 LGTMs obtained

@abarganier
Copy link
Contributor Author

TFTR!

bors r=dhartunian

@craig
Copy link
Contributor

craig bot commented Nov 2, 2023

Build succeeded:

@craig craig bot merged commit 4dad7f2 into cockroachdb:master Nov 2, 2023
3 checks passed
xinhaoz added a commit to xinhaoz/cockroach that referenced this pull request Sep 27, 2024
Previously in cockroachdb#113532 we fixed the stderr sink log format
to `crdb-v2-tty`. This was deemed to be a regression, as
the stderr sink could previously be set to any available
format. This commit reverts the restriction.

The following are still true after this commit:
- `format` in `file-defaults` is not propagated to
`format` of the stderr sink. To set `stderr` format,
one must explicitly define it in the `stderr` sink
section of the log config.
- `format-options` in `file-defaults` are only applied
to stderr if the format of the stderr sink and that in
file-defaults are compatible.

Epic: none
Fixes: cockroachdb#128665

Release note (ops change): Users may set the log format
for thestderr sink by setting the `format` field in the
logging config under the `stderr` sink section.
xinhaoz added a commit to xinhaoz/cockroach that referenced this pull request Sep 27, 2024
Previously in cockroachdb#113532 we fixed the stderr sink log format
to `crdb-v2-tty`. This was deemed to be a regression, as
the stderr sink could previously be set to any available
format. This commit reverts the restriction.

The following are still true after this commit:
- `format` in `file-defaults` is not propagated to
`format` of the stderr sink. To set `stderr` format,
one must explicitly define it in the `stderr` sink
section of the log config.
- `format-options` in `file-defaults` are only applied
to stderr if the format of the stderr sink and that in
file-defaults are compatible.

Epic: none
Fixes: cockroachdb#128665

Release note (ops change): Users may set the log format
for thestderr sink by setting the `format` field in the
logging config under the `stderr` sink section.
xinhaoz added a commit to xinhaoz/cockroach that referenced this pull request Sep 27, 2024
Previously in cockroachdb#113532 we fixed the stderr sink log format
to `crdb-v2-tty`. This was deemed to be a regression, as
the stderr sink could previously be set to any available
format. This commit reverts the restriction.

The following are still true after this commit:
- `format` in `file-defaults` is not propagated to
`format` of the stderr sink. To set `stderr` format,
one must explicitly define it in the `stderr` sink
section of the log config.
- `format-options` in `file-defaults` are only applied
to stderr if the format of the stderr sink and that in
file-defaults are compatible.

Epic: none
Fixes: cockroachdb#128665

Release note (ops change): Users may set the log format
for the stderr sink by setting the `format` field in the
logging config under the `stderr` sink section.
xinhaoz added a commit to xinhaoz/cockroach that referenced this pull request Sep 27, 2024
Previously in cockroachdb#113532 we fixed the stderr sink log format
to `crdb-v2-tty`. This was deemed to be a regression, as
the stderr sink could previously be set to any available
format. This commit reverts the restriction.

The following are still true after this commit:
- `format` in `file-defaults` is not propagated to
`format` of the stderr sink. To set `stderr` format,
one must explicitly define it in the `stderr` sink
section of the log config.
- `format-options` in `file-defaults` are only applied
to stderr if the format of the stderr sink and that in
file-defaults are compatible.

Epic: none
Fixes: cockroachdb#128665

Release note (ops change): Users may set the log format
for the stderr sink by setting the `format` field in the
logging config under the `stderr` sink section.
xinhaoz added a commit to xinhaoz/cockroach that referenced this pull request Sep 27, 2024
Previously in cockroachdb#113532 we fixed the stderr sink log format
to `crdb-v2-tty`. This was deemed to be a regression, as
the stderr sink could previously be set to any available
format. This commit reverts the restriction.

The following are still true after this commit:
- `format` in `file-defaults` is not propagated to
`format` of the stderr sink. To set `stderr` format,
one must explicitly define it in the `stderr` sink
section of the log config.
- `format-options` in `file-defaults` are only applied
to stderr if the format of the stderr sink and that in
file-defaults are compatible.

Epic: none
Fixes: cockroachdb#128665

Release note (ops change): Users may set the log format
for the stderr sink by setting the `format` field in the
logging config under the `stderr` sink section.
xinhaoz added a commit to xinhaoz/cockroach that referenced this pull request Sep 27, 2024
Previously in cockroachdb#113532 we fixed the stderr sink log format
to `crdb-v2-tty`. This was deemed to be a regression, as
the stderr sink could previously be set to any available
format. This commit reverts the restriction.

The following are still true after this commit:
- `format` in `file-defaults` is not propagated to
`format` of the stderr sink. To set `stderr` format,
one must explicitly define it in the `stderr` sink
section of the log config.
- `format-options` in `file-defaults` are only applied
to stderr if the format of the stderr sink and that in
file-defaults are compatible.

Epic: none
Fixes: cockroachdb#128665

Release note (ops change): Users may set the log format
for the stderr sink by setting the `format` field in the
logging config under the `stderr` sink section.
craig bot pushed a commit that referenced this pull request Sep 27, 2024
131529: util/log/logconfig: allow `format` for stderr log sink r=xinhaoz a=xinhaoz

Previously in #113532 we fixed the stderr sink log format to `crdb-v2-tty`. This was deemed to be a regression, as the stderr sink could previously be set to any available format. This commit reverts the restriction.

The following are still true after this commit:
- `format` in `file-defaults` is not propagated to `format` of the stderr sink. To set `stderr` format, one must explicitly define it in the `stderr` sink section of the log config.
- `format-options` in `file-defaults` are only applied to stderr if the format of the stderr sink and that in file-defaults are compatible.

Epic: none
Fixes: #128665

Release note (ops change): Users may set the log format for the stderr sink by setting the `format` field in the logging config under the `stderr` sink section.

Co-authored-by: Xin Hao Zhang <[email protected]>
xinhaoz added a commit that referenced this pull request Sep 27, 2024
Previously in #113532 we fixed the stderr sink log format
to `crdb-v2-tty`. This was deemed to be a regression, as
the stderr sink could previously be set to any available
format. This commit reverts the restriction.

The following are still true after this commit:
- `format` in `file-defaults` is not propagated to
`format` of the stderr sink. To set `stderr` format,
one must explicitly define it in the `stderr` sink
section of the log config.
- `format-options` in `file-defaults` are only applied
to stderr if the format of the stderr sink and that in
file-defaults are compatible.

Epic: none
Fixes: #128665

Release note (ops change): Users may set the log format
for the stderr sink by setting the `format` field in the
logging config under the `stderr` sink section.
cthumuluru-crdb pushed a commit to cthumuluru-crdb/cockroach that referenced this pull request Oct 1, 2024
Previously in cockroachdb#113532 we fixed the stderr sink log format
to `crdb-v2-tty`. This was deemed to be a regression, as
the stderr sink could previously be set to any available
format. This commit reverts the restriction.

The following are still true after this commit:
- `format` in `file-defaults` is not propagated to
`format` of the stderr sink. To set `stderr` format,
one must explicitly define it in the `stderr` sink
section of the log config.
- `format-options` in `file-defaults` are only applied
to stderr if the format of the stderr sink and that in
file-defaults are compatible.

Epic: none
Fixes: cockroachdb#128665

Release note (ops change): Users may set the log format
for the stderr sink by setting the `format` field in the
logging config under the `stderr` sink section.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport-23.2.x Flags PRs that need to be backported to 23.2.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

pkg/util/log: timezone options parsed using crdb-v2, even when format is json
3 participants