chore(config): simplify configuration flags

Drop config.dir and use config.file to pass full path to the config file. Passing two options is just an unnecessary complexity
Fixes #22.
This commit is contained in:
Łukasz Mierzwa
2018-09-15 14:13:51 +01:00
parent ebd480663c
commit 6932f25a37
4 changed files with 11 additions and 26 deletions

View File

@@ -23,7 +23,7 @@ stderr_logfile=/dev/stderr
stderr_logfile_maxbytes=0
[program:karma]
command=/karma --config.dir /etc/
command=/karma --config.file /etc/karma.yaml
autorestart=true
stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0

View File

@@ -8,22 +8,15 @@ it needs to have `.yaml` extension.
Custom filename and directory can be passed via command line flags or
environment variables:
- `--config.file` flag or `CONFIG_FILE` env variable - name of the config file
to load (without extension).
- `--config.dir` flag or `CONFIG_DIR` env variable - directory where config file
can be found.
- `--config.file` flag or `CONFIG_FILE` env variable - path to the config file
Example with flags:
karma --config.file example --config.dir ./docs/
karma --config.file docs/example.yaml
Example with environment variables:
CONFIG_FILE="example" CONFIG_DIR="./docs/" karma
Example using both:
CONFIG_FILE="example" karma --config.dir ./docs/
CONFIG_FILE="docs/example.yaml"
### Alertmanagers

View File

@@ -3,7 +3,6 @@ package config
import (
"bufio"
"bytes"
"path"
"strings"
"time"
@@ -40,10 +39,7 @@ func init() {
pflag.StringSlice("annotations.visible", []string{},
"List of annotations that are visible by default")
pflag.String("config.dir", ".",
"Directory with configuration file to read")
pflag.String("config.file", "karma",
"Name of the configuration file to read")
pflag.String("config.path", "", "Full path to the configuration file")
pflag.Bool("debug", false, "Enable debug mode")
@@ -105,21 +101,18 @@ func (config *configSchema) Read() {
log.Errorf("Failed to bind sentry.private config key to the SENTRY_DSN env variable: %s", err)
}
configFile := v.GetString("config.file")
configDir := v.GetString("config.dir")
v.SetConfigType("yaml")
v.SetConfigName(configFile)
v.AddConfigPath(configDir)
log.Infof("Reading configuration file %s.yaml", path.Join(configDir, configFile))
configPath := v.GetString("config.path")
if configPath != "" {
log.Infof("Reading configuration file %s", configPath)
v.SetConfigFile(configPath)
}
err = v.ReadInConfig()
if v.ConfigFileUsed() != "" && err != nil {
log.Fatal(err)
}
if v.ConfigFileUsed() != "" {
log.Infof("Config file used: %s", v.ConfigFileUsed())
}
config.Alertmanager.Servers = []alertmanagerConfig{}
config.Alertmanager.Interval = v.GetDuration("alertmanager.interval")
config.Annotations.Default.Hidden = v.GetBool("annotations.default.hidden")

View File

@@ -24,7 +24,6 @@ func resetEnv() {
"ANNOTATIONS_DEFAULT_HIDDEN",
"ANNOTATIONS_HIDDEN",
"ANNOTATIONS_VISIBLE",
"CONFIG_DIR",
"CONFIG_FILE",
"DEBUG",
"FILTERS_DEFAULT",