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

promtail: change to use viper #644

Closed
wants to merge 3 commits into from
Closed

Conversation

daixiang0
Copy link
Contributor

Signed-off-by: Xiang Dai 764524258@qq.com

Which issue(s) this PR fixes:
Fixes #520

@daixiang0 daixiang0 force-pushed the viper branch 3 times, most recently from 2171de9 to d338a03 Compare June 5, 2019 02:48
Copy link
Contributor

@cyriltovena cyriltovena left a comment

Choose a reason for hiding this comment

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

Thank you it's great but just like this it doesn't improve or help though it brings a lot of new dependencies.

I think if you want to take care of this we should also set default using viper, parse flag and file and merge everything together.

@daixiang0 daixiang0 force-pushed the viper branch 2 times, most recently from 8751f23 to fa560af Compare June 10, 2019 02:42
@daixiang0
Copy link
Contributor Author

@Kuqd hi, i delete unrelated dependencies, now it support parse flags with default value and then read config, what do you mean about merge? looks like issue in #638?

@daixiang0
Copy link
Contributor Author

@Kuqd met a confused issue, viper get config but can not pack them into config sturct:

Aliases:
map[string]string{}
Override:
map[string]interface {}{}
PFlags:
map[string]viper.FlagValue{"client.batch-size-bytes":viper.pflagValue{flag:(*pflag.Flag)(0xc000196c80)}, "client.batch-wait":viper.pflagValue{flag:(*pflag.Flag)(0xc000196d20)}, "client.external-labels":viper.pflagValue{flag:(*pflag.Flag)(0xc000196dc0)}, "client.max-backoff":viper.pflagValue{flag:(*pflag.Flag)(0xc000196f00)}, "client.max-retries":viper.pflagValue{flag:(*pflag.Flag)(0xc000196fa0)}, "client.min-backoff":viper.pflagValue{flag:(*pflag.Flag)(0xc000197040)}, "client.timeout":viper.pflagValue{flag:(*pflag.Flag)(0xc0001970e0)}, "client.url":viper.pflagValue{flag:(*pflag.Flag)(0xc000197180)}, "config.file":viper.pflagValue{flag:(*pflag.Flag)(0xc000197220)}, "log.level":viper.pflagValue{flag:(*pflag.Flag)(0xc0001972c0)}, "positions.file":viper.pflagValue{flag:(*pflag.Flag)(0xc000197360)}, "positions.sync-period":viper.pflagValue{flag:(*pflag.Flag)(0xc000197400)}, "server.graceful-shutdown-timeout":viper.pflagValue{flag:(*pflag.Flag)(0xc0001974a0)}, "server.grpc-listen-host":viper.pflagValue{flag:(*pflag.Flag)(0xc000197540)}, "server.grpc-listen-port":viper.pflagValue{flag:(*pflag.Flag)(0xc0001975e0)}, "server.grpc-max-concurrent-streams":viper.pflagValue{flag:(*pflag.Flag)(0xc000197680)}, "server.grpc-max-recv-msg-size-bytes":viper.pflagValue{flag:(*pflag.Flag)(0xc000197720)}, "server.grpc-max-send-msg-size-bytes":viper.pflagValue{flag:(*pflag.Flag)(0xc0001977c0)}, "server.http-idle-timeout":viper.pflagValue{flag:(*pflag.Flag)(0xc000197860)}, "server.http-listen-host":viper.pflagValue{flag:(*pflag.Flag)(0xc000197900)}, "server.http-listen-port":viper.pflagValue{flag:(*pflag.Flag)(0xc0001979a0)}, "server.http-read-timeout":viper.pflagValue{flag:(*pflag.Flag)(0xc000197a40)}, "server.http-write-timeout":viper.pflagValue{flag:(*pflag.Flag)(0xc000197ae0)}, "server.path-prefix":viper.pflagValue{flag:(*pflag.Flag)(0xc000197b80)}, "server.register-instrumentation":viper.pflagValue{flag:(*pflag.Flag)(0xc000197c20)}, "target.sync-period":viper.pflagValue{flag:(*pflag.Flag)(0xc000197cc0)}}
Env:
map[string]string{}
Key/Value Store:
map[string]interface {}{}
Config:
map[string]interface {}{"clients":[]interface {}{map[interface {}]interface {}{"url":"http://loki:3100/api/prom/push"}}, "positions":map[string]interface {}{"filename":"/tmp/positions.yaml"}, "scrape_configs":[]interface {}{map[interface {}]interface {}{"job_name":"system", "static_configs":[]interface {}{map[interface {}]interface {}{"labels":map[interface {}]interface {}{"__path__":"/var/log/*log", "job":"varlogs"}, "targets":[]interface {}{"localhost"}}}}}, "server":map[string]interface {}{"grpc_listen_port":0, "http_listen_port":9080}}
Defaults:
map[string]interface {}{}
level=error ts=2019-06-21T06:39:16.968629307Z caller=main.go:62 msg="error creating promtail" error="at least one client config should be provided"

@daixiang0
Copy link
Contributor Author

file issue to viper

Signed-off-by: Xiang Dai <764524258@qq.com>
Signed-off-by: Xiang Dai <764524258@qq.com>
Signed-off-by: Xiang Dai <764524258@qq.com>
@daixiang0
Copy link
Contributor Author

daixiang0 commented Aug 27, 2019

If use viper, since viper use mapstructure, so all config like "yaml: inline" shoulc convert to mapstructure: inline, or need to overvide default tagName as below:

viper.Unmarshal(&config, func(decoderConfig *mapstructure.DecoderConfig) {
		decoderConfig.TagName = "yaml"
	})

On the other hand, all UnmarshalYAML func would become useless since mapstructure do not cal it.

@sh0rez
Copy link
Member

sh0rez commented Sep 26, 2019

Closing this in favor of #980 which implements correct configuration source precedence (defaults < yaml < flag).

Thanks for your contribution!

@sh0rez sh0rez closed this Sep 26, 2019
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.

Improve Loki config management
3 participants