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
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 80 additions & 0 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 8 additions & 1 deletion cmd/loki/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import (
"github.com/cortexproject/cortex/pkg/util"
"github.com/cortexproject/cortex/pkg/util/flagext"
"github.com/cortexproject/cortex/pkg/util/validation"
"github.com/spf13/pflag"
"github.com/spf13/viper"
)

func init() {
Expand All @@ -30,7 +32,12 @@ func main() {
)
flag.StringVar(&configFile, "config.file", "", "Configuration file to load.")
flagext.RegisterFlags(&cfg)
flag.Parse()
pflag.CommandLine.AddGoFlagSet(flag.CommandLine)
pflag.Parse()
if err := viper.BindPFlags(pflag.CommandLine); err != nil {
daixiang0 marked this conversation as resolved.
Show resolved Hide resolved
level.Error(util.Logger).Log("msg", "error parsing flags", "err", err)
os.Exit(1)
}

// LimitsConfig has a customer UnmarshalYAML that will set the defaults to a global.
// This global is set to the config passed into the last call to `NewOverrides`. If we don't
Expand Down
34 changes: 27 additions & 7 deletions cmd/promtail/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ package main
import (
"flag"
"os"
"path"
"reflect"
"strings"

"github.com/cortexproject/cortex/pkg/util"
"github.com/cortexproject/cortex/pkg/util/flagext"
Expand All @@ -12,9 +14,12 @@ import (
"github.com/prometheus/common/version"
"github.com/weaveworks/common/logging"

"github.com/grafana/loki/pkg/helpers"
"github.com/grafana/loki/pkg/promtail"
"github.com/grafana/loki/pkg/promtail/config"

"github.com/mitchellh/mapstructure"
"github.com/spf13/pflag"
"github.com/spf13/viper"
)

func init() {
Expand All @@ -28,15 +33,30 @@ func main() {
)
flag.StringVar(&configFile, "config.file", "promtail.yml", "The config file.")
flagext.RegisterFlags(&config)
flag.Parse()
pflag.CommandLine.AddGoFlagSet(flag.CommandLine)
pflag.Parse()

util.InitLogger(&config.ServerConfig.Config)

if configFile != "" {
if err := helpers.LoadConfig(configFile, &config); err != nil {
level.Error(util.Logger).Log("msg", "error loading config", "filename", configFile, "err", err)
os.Exit(1)
}
if err := viper.BindPFlags(pflag.CommandLine); err != nil {
level.Error(util.Logger).Log("msg", "error parsing flags", "err", err)
os.Exit(1)
}

configFile = viper.GetString("config.file")
viper.SetConfigType("yaml")
viper.SetConfigName(strings.TrimSuffix(path.Base(configFile), path.Ext(configFile)))
viper.AddConfigPath(path.Dir(configFile))
if err := viper.ReadInConfig(); err != nil {
level.Error(util.Logger).Log("msg", "error reading config", "filename", configFile, "err", err)
os.Exit(1)
}

if err := viper.Unmarshal(&config, func(decoderConfig *mapstructure.DecoderConfig) {
decoderConfig.TagName = "yaml"
}); err != nil {
level.Error(util.Logger).Log("msg", "error decoding config", "filename", configFile, "err", err)
os.Exit(1)
}

// Re-init the logger which will now honor a different log level set in ServerConfig.Config
Expand Down
3 changes: 2 additions & 1 deletion pkg/promtail/client/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ import (

// Config describes configuration for a HTTP pusher client.
type Config struct {
URL flagext.URLValue
URL flagext.URLValue `yaml:"url,omitempty"`
//URL flagext.URLValue `yaml:"url,omitempty" mapstructure:"url"`
BatchWait time.Duration
BatchSize int

Expand Down
6 changes: 4 additions & 2 deletions pkg/promtail/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@ import (
type Config struct {
ServerConfig server.Config `yaml:"server,omitempty"`
// deprecated use ClientConfigs instead
ClientConfig client.Config `yaml:"client,omitempty"`
ClientConfigs []client.Config `yaml:"clients,omitempty"`
ClientConfig client.Config `yaml:"client,omitempty"`
ClientConfigs []client.Config `yaml:"clients,omitempty"`
//ClientConfig client.Config `yaml:"client,omitempty" mapstructure:"client"`
//ClientConfigs []client.Config `yaml:"clients,omitempty" mapstructure:"clients"`
PositionsConfig positions.Config `yaml:"positions,omitempty"`
ScrapeConfig []scrape.Config `yaml:"scrape_configs,omitempty"`
TargetConfig targets.Config `yaml:"target_config,omitempty"`
Expand Down
9 changes: 9 additions & 0 deletions vendor/github.com/hashicorp/hcl/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions vendor/github.com/hashicorp/hcl/.travis.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading