cli/format: Create labels.Matcher to format
There is non-trivial value escaping going inside pkg/labels. Signed-off-by: Kiril Vladimirov <kiril@vladimiroff.org>
This commit is contained in:
parent
f503012c0b
commit
217562e838
|
@ -21,6 +21,7 @@ import (
|
|||
|
||||
"github.com/go-openapi/strfmt"
|
||||
"github.com/prometheus/alertmanager/api/v2/models"
|
||||
"github.com/prometheus/alertmanager/pkg/labels"
|
||||
)
|
||||
|
||||
const DefaultDateFormat = "2006-01-02 15:04:05 MST"
|
||||
|
@ -48,3 +49,19 @@ var Formatters = map[string]Formatter{}
|
|||
func FormatDate(input strfmt.DateTime) string {
|
||||
return time.Time(input).Format(*dateFormat)
|
||||
}
|
||||
|
||||
func labelsMatcher(m models.Matcher) *labels.Matcher {
|
||||
var t labels.MatchType
|
||||
switch {
|
||||
case !*m.IsRegex && *m.IsEqual:
|
||||
t = labels.MatchEqual
|
||||
case !*m.IsRegex && !*m.IsEqual:
|
||||
t = labels.MatchNotEqual
|
||||
case *m.IsRegex && *m.IsEqual:
|
||||
t = labels.MatchRegexp
|
||||
case *m.IsRegex && !*m.IsEqual:
|
||||
t = labels.MatchNotRegexp
|
||||
}
|
||||
|
||||
return &labels.Matcher{Type: t, Name: *m.Name, Value: *m.Value}
|
||||
}
|
||||
|
|
|
@ -95,16 +95,5 @@ func simpleFormatMatchers(matchers models.Matchers) string {
|
|||
}
|
||||
|
||||
func simpleFormatMatcher(m models.Matcher) string {
|
||||
var op string
|
||||
switch {
|
||||
case !*m.IsRegex && *m.IsEqual:
|
||||
op = "="
|
||||
case !*m.IsRegex && !*m.IsEqual:
|
||||
op = "!="
|
||||
case *m.IsRegex && *m.IsEqual:
|
||||
op = "=~"
|
||||
case *m.IsRegex && !*m.IsEqual:
|
||||
op = "!~"
|
||||
}
|
||||
return fmt.Sprintf("%s%s%q", *m.Name, op, *m.Value)
|
||||
return labelsMatcher(m).String()
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue