Skip to content

Conversation

wafuwafu13
Copy link
Contributor

part of: #810

example of WARNING

$ cat /usr/local/etc/mackerel-agent-sample.conf
apikey = "foo"
podfile = "/path/to/pidfile"

[foobar]
command = "test command"
env = { FOO = "BAR" }

[plugin.foo.bar]
command = "test command"
env = { FOO = "BAR" }

[plugin.metric.first]
command = "test command"

[plugin.check.first]
command = "test command"

[plugin.check.second]
command = "test command"

[plugins.check.first]
command = "test command"

[plugin.metrics.correct]
command = "test command"

[plugin.checks.correct]
command = "test command"
~/desktop/mackerel-agent
$ ./build/mackerel-agent configtest -conf=/usr/local/etc/mackerel-agent-sample.conf
[WARNING] podfile is unexpected key  
[WARNING] foobar is unexpected key  
[WARNING] foobar.command is unexpected key  
[WARNING] foobar.env.FOO is unexpected key  
[WARNING] foobar.env is unexpected key  
[WARNING] plugins.check.first is unexpected key  
[WARNING] plugins.check.first.command is unexpected key  
[WARNING] plugin.metric.first is unexpected key  
[WARNING] plugin.check.first is unexpected key  
[WARNING] plugin.check.second is unexpected key  
[WARNING] plugin.foo.bar is unexpected key  

スクリーンショット 2022-09-12 16 47 52

example of CRITICAL

$ cat /usr/local/etc/mackerel-agent-sample-2.conf
uncorrectapikey = "foo"
~/desktop/mackerel-agent
$ ./build/mackerel-agent configtest -conf=/usr/local/etc/mackerel-agent-sample-2.conf
[CRITICAL] failed to test config: apikey must be specified in the config file (or by the DEPRECATED command-line flag) 

スクリーンショット 2022-09-12 16 45 55

@wafuwafu13 wafuwafu13 mentioned this pull request Sep 12, 2022
2 tasks
return nil, fmt.Errorf("failed to test config: %s", err)
}

var unexpectedKey []string = make([]string, 0)
Copy link
Member

Choose a reason for hiding this comment

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

[may] This might be declared just var unexpectedKey []string simply.

more better name: unexpectedKeys

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed 0554f6b

}

for k1, v := range config.Plugin {
/*
Copy link
Member

Choose a reason for hiding this comment

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

a good comment
👍

commands.go Outdated

do configtest
*/
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)
return fmt.Errorf("\x1b[31m[CRITICAL] failed to test config: %s \x1b[0m", err)
Copy link
Member

Choose a reason for hiding this comment

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

mackerel-agent runs on Windows, so we had better either to use https://github.com/mattn/go-colorable or https://github.com/fatih/color, or to disable ANSI escape codes except on go:build unix.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed 56a0642

Copy link
Member

@lufia lufia left a comment

Choose a reason for hiding this comment

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

Thanks!

@lufia lufia merged commit 70c1b31 into mackerelio:master Sep 21, 2022
This was referenced Nov 2, 2022
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.

2 participants