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

Only warn about unknown config options instead of rejecting them #631

Merged
merged 1 commit into from
Aug 8, 2023

Conversation

julianbrost
Copy link
Contributor

@julianbrost julianbrost commented Aug 3, 2023

This is a quick proof of concept for an idea I had how to make #605 more suitable for a bug fix release.

Currently, it would just fail with an error. This PR basically parses the config like v1.1.0 did, but additionally parses the config a second time with yaml.DisallowUnknownField() (like the current master and therefore v1.2 will do) and issue a warning if it returns an error.

The icingadb-migrate command still treats unknown options as an error. This is more of a manual one-shot tool, so making it an error there right away shouldn't break anything.

Tests

Config with unknown options and other errors

First prints error and then additionally the warning:

$ go run ./cmd/icingadb -c <(echo unknown: 42)       
invalid configuration: database host missing

warning: ignored unknown config option:

[1:1] unknown field "unknown"
    >  1 | unknown: 42
           ^

Unknown option in an otherwise valid config

Logs the warning and then continues to run:

$ go run ./cmd/icingadb -c config.yml
2023-08-04T12:06:33.213+0200	WARN	icingadb	ignoring unknown config option, this will become a fatal error in Icinga DB v1.2:

[41:1] unknown field "unknown"
      38 |   options:
      39 |     notification: 14
      40 | 
    > 41 | unknown: 42
           ^
2023-08-04T12:06:33.213+0200	INFO	icingadb	Starting Icinga DB
[...running normally...]

@julianbrost julianbrost added this to the 1.1.1 milestone Aug 3, 2023
@cla-bot cla-bot bot added the cla/signed label Aug 3, 2023
Copy link
Member

@Al2Klimov Al2Klimov left a comment

Choose a reason for hiding this comment

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

Not bad. My only complaint is the wrong base branch. (This PR won't be included in v1.2, will it?)

@julianbrost julianbrost force-pushed the unknown-config-option-warning branch from 9215bf2 to 4566091 Compare August 4, 2023 10:06
@julianbrost
Copy link
Contributor Author

I've pushed a new version that delays the warning until logging is initialized. In case there is an error (and logging won't be initialized), the warning is embedded in the error message.

Copy link
Member

@Al2Klimov Al2Klimov left a comment

Choose a reason for hiding this comment

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

Even better (for the ones who read logs 🪵 at all).

pkg/config/config.go Outdated Show resolved Hide resolved
if err := c.Validate(); err != nil {
return nil, errors.Wrap(err, "invalid configuration")
msg := "invalid configuration"
if warn := c.DecodeWarning; warn != nil {
Copy link
Member

Choose a reason for hiding this comment

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

What's warn for?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Shorthand for the longer name.

Copy link
Member

Choose a reason for hiding this comment

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

A bit too much of shorthand. But this is a matter of opinion. Same for "invalid configuration".

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was just trying hard to avoid breaking the next line, especially somewhere in the middle of the format string.

cmd/icingadb/main.go Show resolved Hide resolved
if err := c.Validate(); err != nil {
return nil, errors.Wrap(err, "invalid configuration")
msg := "invalid configuration"
Copy link
Member

Choose a reason for hiding this comment

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

This could be a const or even inlined.

pkg/config/config.go Outdated Show resolved Hide resolved
},
{
name: "mini-with-unknown",
input: miniConf + "\nunknown: 42",
output: nil,
Copy link
Member

Choose a reason for hiding this comment

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

This was the only one of its kind. You've made the existing if below obsolete.

Copy link
Member

@Al2Klimov Al2Klimov left a comment

Choose a reason for hiding this comment

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

Do we want a similar change in icingadb-migrate? This is more of a manual one-shot tool, so making it an error there right away shouldn't break anything.

You are right. To be even more specific, there are three kinds of users:

  • have done migration – won't use the tool again – not affected
  • doing migration – affected on interrupt – solutions:
    • wait with the update
    • just adjust the config
  • didn't start migration – didn't use the tool yet – not affected by my change as such (or yours)

if err := c.Validate(); err != nil {
return nil, errors.Wrap(err, "invalid configuration")
msg := "invalid configuration"
if warn := c.DecodeWarning; warn != nil {
Copy link
Member

Choose a reason for hiding this comment

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

A bit too much of shorthand. But this is a matter of opinion. Same for "invalid configuration".

@julianbrost julianbrost mentioned this pull request Aug 7, 2023
@julianbrost julianbrost changed the base branch from main to support/1.1 August 8, 2023 09:27
…them

This makes the change from #605 more suitable for the v1.1.1 bug fix release
because this way, no new fatal errors are added while keeping the helpful
information in a warning.
@julianbrost julianbrost force-pushed the unknown-config-option-warning branch from 0f0c03d to d11f03d Compare August 8, 2023 09:28
@julianbrost julianbrost marked this pull request as ready for review August 8, 2023 09:30
@julianbrost julianbrost merged commit 56e5a7b into support/1.1 Aug 8, 2023
30 of 31 checks passed
@julianbrost julianbrost deleted the unknown-config-option-warning branch August 8, 2023 09:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants