Make resolve timeout configurable

This commit is contained in:
Fabian Reinartz 2015-11-27 15:41:22 +01:00
parent 9fbc76a52f
commit 00b8a2ad03
4 changed files with 18 additions and 13 deletions

8
api.go
View File

@ -36,6 +36,7 @@ type API struct {
alerts provider.Alerts alerts provider.Alerts
silences provider.Silences silences provider.Silences
config string config string
resolveTimeout time.Duration
uptime time.Time uptime time.Time
groups func() AlertOverview groups func() AlertOverview
@ -79,11 +80,12 @@ func (api *API) Register(r *route.Router) {
} }
// Update sets the configuration string to a new value. // Update sets the configuration string to a new value.
func (api *API) Update(config string) { func (api *API) Update(config string, resolveTimeout time.Duration) {
api.mtx.Lock() api.mtx.Lock()
defer api.mtx.Unlock() defer api.mtx.Unlock()
api.config = config api.config = config
api.resolveTimeout = resolveTimeout
} }
type errorType string type errorType string
@ -193,7 +195,7 @@ func (api *API) legacyAddAlerts(w http.ResponseWriter, r *http.Request) {
} }
if alert.EndsAt.IsZero() { if alert.EndsAt.IsZero() {
alert.Timeout = true alert.Timeout = true
alert.EndsAt = alert.StartsAt.Add(ResolveTimeout) alert.EndsAt = alert.StartsAt.Add(api.resolveTimeout)
} }
} }
@ -226,7 +228,7 @@ func (api *API) addAlerts(w http.ResponseWriter, r *http.Request) {
} }
if alert.EndsAt.IsZero() { if alert.EndsAt.IsZero() {
alert.Timeout = true alert.Timeout = true
alert.EndsAt = alert.StartsAt.Add(ResolveTimeout) alert.EndsAt = alert.StartsAt.Add(api.resolveTimeout)
} }
} }

View File

@ -20,6 +20,7 @@ import (
"path/filepath" "path/filepath"
"regexp" "regexp"
"strings" "strings"
"time"
"github.com/prometheus/common/model" "github.com/prometheus/common/model"
"gopkg.in/yaml.v2" "gopkg.in/yaml.v2"
@ -181,6 +182,8 @@ func (c *Config) UnmarshalYAML(unmarshal func(interface{}) error) error {
// DefaultGlobalConfig provides global default values. // DefaultGlobalConfig provides global default values.
var DefaultGlobalConfig = GlobalConfig{ var DefaultGlobalConfig = GlobalConfig{
ResolveTimeout: model.Duration(5 * time.Minute),
PagerdutyURL: "https://events.pagerduty.com/generic/2010-04-15/create_event.json", PagerdutyURL: "https://events.pagerduty.com/generic/2010-04-15/create_event.json",
OpsGenieAPIHost: "https://api.opsgenie.com/", OpsGenieAPIHost: "https://api.opsgenie.com/",
} }
@ -188,6 +191,10 @@ var DefaultGlobalConfig = GlobalConfig{
// GlobalConfig defines configuration parameters that are valid globally // GlobalConfig defines configuration parameters that are valid globally
// unless overwritten. // unless overwritten.
type GlobalConfig struct { type GlobalConfig struct {
// ResolveTimeout is the time after which an alert is declared resolved
// if it has not been updated.
ResolveTimeout model.Duration `yaml:"resolve_timeout"`
SMTPFrom string `yaml:"smtp_from"` SMTPFrom string `yaml:"smtp_from"`
SMTPSmarthost string `yaml:"smtp_smarthost"` SMTPSmarthost string `yaml:"smtp_smarthost"`
SlackURL string `yaml:"slack_url"` SlackURL string `yaml:"slack_url"`

View File

@ -15,11 +15,6 @@ import (
"github.com/prometheus/alertmanager/types" "github.com/prometheus/alertmanager/types"
) )
// ResolveTimeout is the time after which an alert is declared resolved
// if it has not been updated.
// TODO(fabxc): Make it configurable.
const ResolveTimeout = 5 * time.Minute
// Dispatcher sorts incoming alerts into aggregation groups and // Dispatcher sorts incoming alerts into aggregation groups and
// assigns the correct notifiers to each. // assigns the correct notifiers to each.
type Dispatcher struct { type Dispatcher struct {

View File

@ -27,6 +27,7 @@ import (
"strings" "strings"
"syscall" "syscall"
tmpltext "text/template" tmpltext "text/template"
"time"
"github.com/prometheus/common/log" "github.com/prometheus/common/log"
"github.com/prometheus/common/route" "github.com/prometheus/common/route"
@ -133,7 +134,7 @@ func main() {
return err return err
} }
api.Update(conf.String()) api.Update(conf.String(), time.Duration(conf.Global.ResolveTimeout))
tmpl, err = template.FromGlobs(conf.Templates...) tmpl, err = template.FromGlobs(conf.Templates...)
if err != nil { if err != nil {