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

Add support for json logging #50

Merged
merged 7 commits into from
Feb 20, 2020
Merged

Conversation

lalbers
Copy link
Contributor

@lalbers lalbers commented Jan 14, 2020

Related to issue #47.

Enable support for configurable structured json logging.

@hashicorp-cla
Copy link

hashicorp-cla commented Jan 14, 2020

CLA assistant check
All committers have signed the CLA.

@lalbers lalbers requested a review from jasonodonnell January 16, 2020 13:29
Copy link
Contributor

@jasonodonnell jasonodonnell left a comment

Choose a reason for hiding this comment

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

Thanks for the contribution! Left some minor comments. Please address these and fix the conflicts on your branch!

@@ -32,6 +32,8 @@ spec:
value: ":8080"
- name: AGENT_INJECT_LOG_LEVEL
value: "info"
- name: AGENT_INJECT_LOG_FORMAT
- value: "json"
Copy link
Contributor

Choose a reason for hiding this comment

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

Format is off here.

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think he default should be json. It's nice that there's a configurable for this now, however, not everyone is going to want JSON by default.

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 agree, default log settings should be similar to hashicorp/vault. Fixed.

subcommand/injector/flags.go Show resolved Hide resolved
@lalbers lalbers requested a review from jasonodonnell January 22, 2020 10:14
@frittentheke
Copy link

This is really great @lalbers !

Looking at the field names there is the "@" sign in front. Not that this breaks anything, but in the context of shipping stuff to an ElasticSearch this sometime needs extra treatment. Especially when looking at "@timestamp" ...

{"@level":"info","@message":"Request received","@module":"handler","@timestamp":"2020-01-21T08:43:25.828108Z","Method":"POST","URL":{"Scheme":"","Opaque":"","User":null,"Host":"","Path":"/mutate","RawPath":"","ForceQuery":false,"RawQuery":"timeout=30s","Fragment":""}}
{"@level":"debug","@message":"checking if should inject agent..","@module":"handler","@timestamp":"2020-01-21T08:43:25.828687Z"}
{"@level":"debug","@message":"checking namespaces..","@module":"handler","@timestamp":"2020-01-21T08:43:25.828707Z"}
{"@level":"debug","@message":"setting default annotations..","@module":"handler","@timestamp":"2020-01-21T08:43:25.828716Z"}
{"@level":"debug","@message":"creating new agent..","@module":"handler","@timestamp":"2020-01-21T08:43:25.828739Z"}
{"@level":"debug","@message":"validating agent configuration..","@module":"handler","@timestamp":"2020-01-21T08:43:25.828790Z"}

Is there maybe an easy way to remove those?

Copy link
Contributor

@jasonodonnell jasonodonnell left a comment

Choose a reason for hiding this comment

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

Looks great, thanks @lalbers !

@jasonodonnell jasonodonnell added this to the 0.3.0 milestone Feb 4, 2020
@jasonodonnell jasonodonnell added enhancement New feature or request injector Area: mutating webhook service labels Feb 4, 2020
@jasonodonnell jasonodonnell self-requested a review February 4, 2020 16:02
}

func (c *Command) init() {
c.flagSet = flag.NewFlagSet("", flag.ContinueOnError)
c.flagSet.StringVar(&c.flagListen, "listen", ":8080", "Address to bind listener to.")
c.flagSet.StringVar(&c.flagLogLevel, "log-level", DefaultLogLevel, "Log verbosity level. Supported values "+
`(in order of detail) are "trace", "debug", "info", "warn", and "err".`)
c.flagSet.StringVar(&c.flagLogFormat, "log-level", DefaultLogFormat, "Log output format. "+
Copy link
Contributor

Choose a reason for hiding this comment

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

Because log-level is redefined here (it should be log-format), this is causing the injector to panic.

Copy link
Contributor

Choose a reason for hiding this comment

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

flag redefined: log-level
panic: flag redefined: log-level

goroutine 1 [running]:
flag.(*FlagSet).Var(0xc0001ea5a0, 0x1435de0, 0xc0001fa210, 0x1291171, 0x9, 0x12cd800, 0x3d)
	/usr/local/Cellar/go/1.12.7/libexec/src/flag/flag.go:850 +0x4af
flag.(*FlagSet).StringVar(...)
	/usr/local/Cellar/go/1.12.7/libexec/src/flag/flag.go:753
github.com/hashicorp/vault-k8s/subcommand/injector.(*Command).init(0xc0001fa1e0)
	/Users/jasonodonnell/Git/vault-k8s/subcommand/injector/flags.go:59 +0x1b5
sync.(*Once).Do(0xc0001fa298, 0xc00006bdd0)
	/usr/local/Cellar/go/1.12.7/libexec/src/sync/once.go:44 +0xb3
github.com/hashicorp/vault-k8s/subcommand/injector.(*Command).Run(0xc0001fa1e0, 0xc00003a0b0, 0x1, 0x1, 0x0)
	/Users/jasonodonnell/Git/vault-k8s/subcommand/injector/command.go:53 +0xe1
github.com/mitchellh/cli.(*CLI).Run(0xc0001afe00, 0x9, 0xc0001d8400, 0x128fea8)
	/Users/jasonodonnell/go/pkg/mod/github.com/mitchellh/cli@v1.0.0/cli.go:255 +0x1f1
main.main()
	/Users/jasonodonnell/Git/vault-k8s/main.go:17 +0x16b

Copy link
Contributor Author

@lalbers lalbers left a comment

Choose a reason for hiding this comment

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

@jasonodonnell
Thanks a lot, I overlooked it.

@lalbers
Copy link
Contributor Author

lalbers commented Feb 14, 2020

Fixed flag-name

Copy link
Contributor

@jasonodonnell jasonodonnell left a comment

Choose a reason for hiding this comment

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

Thanks for fixing the flag name, looks good to me!

@jasonodonnell jasonodonnell merged commit 98d54a8 into hashicorp:master Feb 20, 2020
@jasonodonnell jasonodonnell mentioned this pull request Mar 4, 2020
RemcoBuddelmeijer pushed a commit to RemcoBuddelmeijer/vault-k8s that referenced this pull request Feb 22, 2022
* Add support for json logging

* adjust default logging format to txt

* add unit test for log_format env

* correct code indents for command.go

* Update flags.go
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request injector Area: mutating webhook service
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants