Drop legacy settings

Those were left for compatibility and marked as deprecated, remove it for the next release
This commit is contained in:
Łukasz Mierzwa
2018-01-31 21:16:40 -08:00
parent 58077fa0ec
commit f6efebb934
3 changed files with 1 additions and 113 deletions

View File

@@ -93,9 +93,6 @@ func (config *configSchema) Read() {
// raven-go expects this
v.BindEnv("sentry.private", "SENTRY_DSN")
// bind legacy env variables
config.legacyEnvs(v)
configFile := v.GetString("config.file")
configDir := v.GetString("config.dir")
v.SetConfigType("yaml")
@@ -142,9 +139,6 @@ func (config *configSchema) Read() {
log.Fatal(err)
}
// populate legacy settings if needed
config.legacySettingsFallback()
// accept single Alertmanager server from flag/env if nothing is set yet
if len(config.Alertmanager.Servers) == 0 && v.GetString("alertmanager.uri") != "" {
log.Info("Using simple config with a single Alertmanager server")

View File

@@ -17,10 +17,8 @@ func resetEnv() {
unseeEnvVariables := []string{
"ALERTMANAGER_INTERVAL",
"ALERTMANAGER_URI",
"ALERTMANAGER_URIS",
"ALERTMANAGER_NAME",
"ALERTMANAGET_TIMEOUT",
"ALERTMANAGER_TTL",
"ANNOTATIONS_DEFAULT_HIDDEN",
"ANNOTATIONS_HIDDEN",
"ANNOTATIONS_VISIBLE",
@@ -96,11 +94,7 @@ listen:
log:
config: true
level: info
jira:
- regex: DEVOPS-[0-9]+
uri: https://jira.example.com
- regex: FOO-[0-9]+
uri: https://foo.example.com
jira: []
receivers:
keep: []
strip: []
@@ -130,28 +124,6 @@ sentry:
}
}
func TestReadConfigLegacy(t *testing.T) {
resetEnv()
log.SetLevel(log.ErrorLevel)
os.Setenv("ALERTMANAGER_TTL", "1s")
os.Setenv("ALERTMANAGER_URIS", "default:http://localhost")
os.Setenv("ANNOTATIONS_DEFAULT_HIDDEN", "true")
os.Setenv("ANNOTATIONS_VISIBLE", "summary")
os.Setenv("COLOR_LABELS_STATIC", "a bb ccc")
os.Setenv("COLOR_LABELS_UNIQUE", "f gg")
os.Setenv("DEBUG", "true")
os.Setenv("FILTER_DEFAULT", "@state=active,foo=bar")
os.Setenv("JIRA_REGEX", "DEVOPS-[0-9]+@https://jira.example.com FOO-[0-9]+@https://foo.example.com")
os.Setenv("KEEP_LABELS", "foo bar")
os.Setenv("STRIP_LABELS", "abc def")
os.Setenv("SENTRY_DSN", "secret key")
os.Setenv("SENTRY_PUBLIC_DSN", "public key")
os.Setenv("HOST", "0.0.0.0")
os.Setenv("PORT", "80")
Config.Read()
testReadConfig(t)
}
func TestReadConfig(t *testing.T) {
resetEnv()
log.SetLevel(log.ErrorLevel)
@@ -161,7 +133,6 @@ func TestReadConfig(t *testing.T) {
os.Setenv("ANNOTATIONS_VISIBLE", "summary")
os.Setenv("DEBUG", "true")
os.Setenv("FILTERS_DEFAULT", "@state=active foo=bar")
os.Setenv("JIRA_REGEX", "DEVOPS-[0-9]+@https://jira.example.com FOO-[0-9]+@https://foo.example.com")
os.Setenv("LABELS_COLOR_STATIC", "a bb ccc")
os.Setenv("LABELS_COLOR_UNIQUE", "f gg")
os.Setenv("LABELS_KEEP", "foo bar")

View File

@@ -1,77 +0,0 @@
package config
import (
"os"
"strings"
"time"
log "github.com/sirupsen/logrus"
"github.com/spf13/viper"
)
func (config *configSchema) legacyEnvs(v *viper.Viper) {
// legacy env variables
v.BindEnv("alertmanager.interval", "ALERTMANAGER_TTL")
v.BindEnv("annotations.default.hidden", "ANNOTATIONS_DEFAULT_HIDDEN")
v.BindEnv("annotations.hidden", "ANNOTATIONS_HIDE")
v.BindEnv("annotations.visible", "ANNOTATIONS_SHOW")
v.BindEnv("labels.color.static", "COLOR_LABELS_STATIC")
v.BindEnv("labels.color.unique", "COLOR_LABELS_UNIQUE")
v.BindEnv("labels.keep", "KEEP_LABELS")
v.BindEnv("labels.strip", "STRIP_LABELS")
v.BindEnv("listen.prefix", "WEB_PREFIX")
v.BindEnv("receivers.strip", "STRIP_RECEIVERS")
v.BindEnv("sentry.public", "SENTRY_PUBLIC_DSN")
}
func (config *configSchema) legacySettingsFallback() {
// no Alertmanager servers configured and legacy ALERTMANAGER_URIS is present
if len(config.Alertmanager.Servers) == 0 && os.Getenv("ALERTMANAGER_URIS") != "" {
log.Warn("ALERTMANAGER_URIS env variable is deprecated")
for _, s := range strings.Split(os.Getenv("ALERTMANAGER_URIS"), " ") {
z := strings.SplitN(s, ":", 2)
if len(z) != 2 {
log.Fatalf("Invalid Alertmanager URI '%s', expected format 'name:uri'", s)
continue
}
name := z[0]
uri := z[1]
ac := alertmanagerConfig{
Name: name,
URI: uri,
Timeout: time.Second * 40,
}
if os.Getenv("ALERTMANAGER_TIMEOUT") != "" {
log.Warn("ALERTMANAGER_TIMEOUT env variable is deprecated and will be removed in the next release")
timeout, err := time.ParseDuration(os.Getenv("ALERTMANAGER_TIMEOUT"))
if err != nil {
log.Fatalf("Invalid ALERTMANAGER_TIMEOUT: %s", err)
}
ac.Timeout = timeout
}
config.Alertmanager.Servers = append(config.Alertmanager.Servers, ac)
}
}
// no default filters and legacy FILTER_DEFAULT is present
if len(config.Filters.Default) == 0 && os.Getenv("FILTER_DEFAULT") != "" {
log.Warn("FILTER_DEFAULT env variable is deprecated and will be removed in the next release")
config.Filters.Default = strings.Split(os.Getenv("FILTER_DEFAULT"), ",")
}
// no jira rules configured and legacy JIRA_REGEX is present
if len(config.JIRA) == 0 && os.Getenv("JIRA_REGEX") != "" {
log.Warn("JIRA_REGEX env variable is deprecated and will be removed in the next release")
rules := []jiraRule{}
for _, s := range strings.Split(os.Getenv("JIRA_REGEX"), " ") {
ss := strings.SplitN(s, "@", 2)
re := ss[0]
url := ss[1]
if re == "" || url == "" {
log.Fatalf("Invalid JIRA rule '%s', regexp part is '%s', url is '%s'", s, re, url)
}
rules = append(rules, jiraRule{Regex: re, URI: url})
}
config.JIRA = rules
}
}