From c8348ba3254d5aeefbbfc8e3574ffa40e1391b0e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Mierzwa?= Date: Mon, 27 Mar 2017 19:38:58 -0700 Subject: [PATCH 1/2] Don't set the default value for flags Let envconfig handle defaults, setting it for flags means that we'll always pass a value to the env if there was a default one, meaning that we're unable to override via env --- config/config.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/config/config.go b/config/config.go index 82d657f0f..54e90a9f9 100644 --- a/config/config.go +++ b/config/config.go @@ -77,7 +77,6 @@ func mapEnvConfigToFlags() { } envName := f.Tag.Get("envconfig") - defaultVal := f.Tag.Get("default") helpMsg := fmt.Sprintf("%s. This flag can also be set via %s environment variable.", f.Tag.Get("help"), f.Tag.Get("envconfig")) if f.Tag.Get("required") == "true" { @@ -89,7 +88,7 @@ func mapEnvConfigToFlags() { mapper.isBool = true mapper.boolVal = flag.Bool(flagName, false, helpMsg) } else { - mapper.stringVal = flag.String(flagName, defaultVal, helpMsg) + mapper.stringVal = flag.String(flagName, "", helpMsg) } flags[envName] = mapper } From 0eb885bded94b5e5a952e61872e00654dcf1a99a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Mierzwa?= Date: Mon, 27 Mar 2017 19:40:04 -0700 Subject: [PATCH 2/2] Compare timestamps as is when sorting Remove rounding of timestamps when sorting alert list, not sure why it was added, it's not needed --- models/models.go | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/models/models.go b/models/models.go index 3035b8faa..a60adbb3a 100644 --- a/models/models.go +++ b/models/models.go @@ -67,9 +67,8 @@ func (a UnseeAlertList) Swap(i, j int) { a[i], a[j] = a[j], a[i] } func (a UnseeAlertList) Less(i, j int) bool { - // compare timestamps rounded up to 2s, subsecond accuracy is lost to keep - // ordering stable even with small time drift - return a[i].StartsAt.Round(2 * time.Second).After(a[j].StartsAt.Round(2 * time.Second)) + // compare timestamps, if equal compare labels + return a[i].StartsAt.After(a[j].StartsAt) } // UnseeAlertGroup is vanilla Alertmanager group, but alerts are flattened