Skip to content

Commit

Permalink
Allow 'd', 'w', 'y' to be specified at time suffix when creating sile…
Browse files Browse the repository at this point in the history
…nce (#1091)

The time.ParseDuration refused to parse them with the reason that a day
can be shorter or longer than 24 hours. But they are already accepted in
Prometheus range query and a custom parser is included in Prometheus
common package so there's no reason amtool cannot use that.

This will be handy in cases you need to create silence for longer periods,
which are unfortunately common.
  • Loading branch information
lebinh authored and stuartnelson3 committed Nov 11, 2017
1 parent fdee5fc commit ea9a584
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions cli/silence_add.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@ import (
"time"

"github.com/prometheus/alertmanager/types"
"github.com/prometheus/common/model"
"github.com/spf13/cobra"
flag "github.com/spf13/pflag"
"github.com/spf13/viper"
)

type addResponse struct {
Status string `json:"status"`
Data struct {
Data struct {
SilenceID string `json:"silenceId"`
} `json:"data,omitempty"`
ErrorType string `json:"errorType,omitempty"`
Expand Down Expand Up @@ -102,11 +103,14 @@ func add(cmd *cobra.Command, args []string) error {
return err
}
} else {
duration, err := time.ParseDuration(expires)
duration, err := model.ParseDuration(expires)
if err != nil {
return err
}
endsAt = time.Now().UTC().Add(duration)
if duration == 0 {
return fmt.Errorf("silence duration must be greater than 0")
}
endsAt = time.Now().UTC().Add(time.Duration(duration))
}

author := viper.GetString("author")
Expand Down

0 comments on commit ea9a584

Please sign in to comment.