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

Improve mackerel-agent configtest #810

Closed
2 tasks done
wafuwafu13 opened this issue Sep 5, 2022 · 0 comments
Closed
2 tasks done

Improve mackerel-agent configtest #810

wafuwafu13 opened this issue Sep 5, 2022 · 0 comments

Comments

@wafuwafu13
Copy link
Contributor

wafuwafu13 commented Sep 5, 2022

Now, we run resolveConfig to do configtest and detect Invalid syntax (config_test.go shows that).
But, we can't detect unexpected key, so I want to improve by using Undecoded().
It would be better if it could suggest intended key.

This is sample of mackerel-agent.conf which includes unexpected key.

1  apikey = "abcdefg"
2  podfile = "/path/to/pidfile"
3 
4  [foo]
5  command = "bar"
6 
7  [plugins.checks.foo]
8  command = "bar"
9 
10 [plugin.check.foo]
11 command = "bar"

Actual behavior

$ mackerel-agent configtest
/path/to/mackerel-agent.conf Syntax OK

Expected behavior

$ mackerel-agent configtest
warn: podfile is invalid key. Do you mean pidfile ?(line 2)
warn: foo is invalid key (line 4)
warn: plugins.checks.foo is invalid key. Do you mean plugin.checks.foo ? (line 7)
warn: plugin.check.foo is invalid key. Do you mean plugin.checks.foo ? (line 10)

Implementation image

Create config/validate.go#ValidateConfigFile and use it in commands.go#doConfigtest

func doConfigtest(fs *flag.FlagSet, argv []string) error {
	conf, err := resolveConfig(fs, argv)
	if err != nil {
		return fmt.Errorf("failed to test config: %s", err)
	}
	warnings := config.ValidateConfigFile(conf.Conffile)
	if warnings != nil {
                 return <display warnings>
        }
        fmt.Fprintf(os.Stderr, "%s Syntax OK\n", conf.Conffile)
	return nil
}

Implementation stage

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

No branches or pull requests

1 participant