Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
pkg/util/log: selectively apply file-defaults.format-options to stderr
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 (bug fix): A bug in the log config code prevented users from setting the `datetime-format` and `datetime-timezone` log format options (set via the `format-options` structure) within their log config. Specifically, when users tried to use these options in `file-defaults` with any `json` type log format, the log config was previously unable to be parsed due to validation errors. This was because the `file-defaults.format-options` were propagated to the `sinks.stderr.format-options`. `sinks.stderr` only supports a format of `crdb-v2-tty`. Therefore, the incorrectly propagated `format-options`, which are only supported by the `json` log format, were identified as not being supported when validating `sinks.stderr`. With this patch, the `file-defaults.format-options` are only propagated to `sinks.stderr.format-options` if both of these conditions are true: 1. `file-defaults.format` is one of `crdb-v2` or `crdb-v2-tty`. 2. `sinks.stderr.format-options` are not explicitly set in the log config.
- Loading branch information