mirror of
https://github.com/prometheus/prometheus.git
synced 2025-03-05 20:59:13 -08:00
Move back to go-yaml
Signed-off-by: Goutham Veeramachaneni <cs14btech11014@iith.ac.in>
This commit is contained in:
parent
5ff283a7b7
commit
dc69645e92
|
@ -20,7 +20,7 @@ import (
|
|||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
yaml "github.com/ghodss/yaml"
|
||||
yaml "gopkg.in/yaml.v2"
|
||||
|
||||
"github.com/prometheus/common/model"
|
||||
"github.com/prometheus/common/version"
|
||||
|
@ -244,7 +244,7 @@ func updateRules(t cli.Term, filename string) error {
|
|||
yamlRules = append(yamlRules, rulefmt.Rule{
|
||||
Alert: r.Name,
|
||||
Expr: r.Expr.String(),
|
||||
For: model.Duration(r.Duration).String(),
|
||||
For: model.Duration(r.Duration),
|
||||
Labels: r.Labels.Map(),
|
||||
Annotations: r.Annotations.Map(),
|
||||
})
|
||||
|
|
|
@ -16,10 +16,10 @@ package rulefmt
|
|||
import (
|
||||
"io/ioutil"
|
||||
|
||||
"github.com/ghodss/yaml"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/prometheus/common/model"
|
||||
"github.com/prometheus/prometheus/promql"
|
||||
yaml "gopkg.in/yaml.v2"
|
||||
)
|
||||
|
||||
// Error represents semantical errors on parsing rule groups.
|
||||
|
@ -35,8 +35,8 @@ func (err *Error) Error() string {
|
|||
|
||||
// RuleGroups is a set of rule groups that are typically exposed in a file.
|
||||
type RuleGroups struct {
|
||||
Version int `json:"version"`
|
||||
Groups []RuleGroup `json:"groups"`
|
||||
Version int `yaml:"version"`
|
||||
Groups []RuleGroup `yaml:"groups"`
|
||||
}
|
||||
|
||||
// Validate validates all rules in the rule groups.
|
||||
|
@ -75,19 +75,19 @@ func (g *RuleGroups) Validate() (errs []error) {
|
|||
|
||||
// RuleGroup is a list of sequentially evaluated recording and alerting rules.
|
||||
type RuleGroup struct {
|
||||
Name string `json:"name"`
|
||||
Interval string `json:"interval,omitempty"`
|
||||
Rules []Rule `json:"rules"`
|
||||
Name string `yaml:"name"`
|
||||
Interval model.Duration `yaml:"interval,omitempty"`
|
||||
Rules []Rule `yaml:"rules"`
|
||||
}
|
||||
|
||||
// Rule describes an alerting or recording rule.
|
||||
type Rule struct {
|
||||
Record string `json:"record,omitempty"`
|
||||
Alert string `json:"alert,omitempty"`
|
||||
Expr string `json:"expr"`
|
||||
For string `json:"for,omitempty"`
|
||||
Labels map[string]string `json:"labels,omitempty"`
|
||||
Annotations map[string]string `json:"annotations,omitempty"`
|
||||
Record string `yaml:"record,omitempty"`
|
||||
Alert string `yaml:"alert,omitempty"`
|
||||
Expr string `yaml:"expr"`
|
||||
For model.Duration `yaml:"for,omitempty"`
|
||||
Labels map[string]string `yaml:"labels,omitempty"`
|
||||
Annotations map[string]string `yaml:"annotations,omitempty"`
|
||||
}
|
||||
|
||||
// Validate the rule and return a list of encountered errors.
|
||||
|
@ -108,7 +108,7 @@ func (r *Rule) Validate() (errs []error) {
|
|||
if len(r.Annotations) > 0 {
|
||||
errs = append(errs, errors.Errorf("invalid field 'annotations' in recording rule"))
|
||||
}
|
||||
if r.For != "" {
|
||||
if r.For != 0 {
|
||||
errs = append(errs, errors.Errorf("invalid field 'for' in recording rule"))
|
||||
}
|
||||
}
|
||||
|
|
4
pkg/rulefmt/testdata/bad_annotation.bad.yaml
vendored
4
pkg/rulefmt/testdata/bad_annotation.bad.yaml
vendored
|
@ -1,5 +1,5 @@
|
|||
Version: 1
|
||||
Groups:
|
||||
version: 1
|
||||
groups:
|
||||
- name: yolo
|
||||
rules:
|
||||
- alert: hola
|
||||
|
|
4
pkg/rulefmt/testdata/bad_expr.bad.yaml
vendored
4
pkg/rulefmt/testdata/bad_expr.bad.yaml
vendored
|
@ -1,5 +1,5 @@
|
|||
Version: 1
|
||||
Groups:
|
||||
version: 1
|
||||
groups:
|
||||
- name: yolo
|
||||
rules:
|
||||
- record: yolo
|
||||
|
|
4
pkg/rulefmt/testdata/bad_lname.bad.yaml
vendored
4
pkg/rulefmt/testdata/bad_lname.bad.yaml
vendored
|
@ -1,5 +1,5 @@
|
|||
Version: 1
|
||||
Groups:
|
||||
version: 1
|
||||
groups:
|
||||
- name: yolo
|
||||
rules:
|
||||
- record: hola
|
||||
|
|
4
pkg/rulefmt/testdata/duplicate_grp.bad.yaml
vendored
4
pkg/rulefmt/testdata/duplicate_grp.bad.yaml
vendored
|
@ -1,4 +1,4 @@
|
|||
Version: 1
|
||||
Groups:
|
||||
version: 1
|
||||
groups:
|
||||
- name: yolo
|
||||
- name: yolo
|
||||
|
|
4
pkg/rulefmt/testdata/no_rec_alert.bad.yaml
vendored
4
pkg/rulefmt/testdata/no_rec_alert.bad.yaml
vendored
|
@ -1,5 +1,5 @@
|
|||
Version: 1
|
||||
Groups:
|
||||
version: 1
|
||||
groups:
|
||||
- name: yolo
|
||||
rules:
|
||||
- expr: 1
|
||||
|
|
4
pkg/rulefmt/testdata/noexpr.bad.yaml
vendored
4
pkg/rulefmt/testdata/noexpr.bad.yaml
vendored
|
@ -1,5 +1,5 @@
|
|||
Version: 1
|
||||
Groups:
|
||||
version: 1
|
||||
groups:
|
||||
- name: yolo
|
||||
rules:
|
||||
- record: ylo
|
||||
|
|
2
pkg/rulefmt/testdata/noversion.bad.yaml
vendored
2
pkg/rulefmt/testdata/noversion.bad.yaml
vendored
|
@ -1,2 +1,2 @@
|
|||
Groups:
|
||||
groups:
|
||||
- name: yolo
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
Version: 1
|
||||
Groups:
|
||||
version: 1
|
||||
groups:
|
||||
- name: yolo
|
||||
rules:
|
||||
- record: Hi
|
||||
|
|
|
@ -522,13 +522,8 @@ func (m *Manager) loadGroups(interval time.Duration, filenames ...string) (map[s
|
|||
|
||||
for _, rg := range rgs.Groups {
|
||||
itv := interval
|
||||
if rg.Interval != "" {
|
||||
dur, err := model.ParseDuration(rg.Interval)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
itv = time.Duration(dur)
|
||||
if rg.Interval != 0 {
|
||||
itv = time.Duration(rg.Interval)
|
||||
}
|
||||
|
||||
rules := make([]Rule, 0, len(rg.Rules))
|
||||
|
@ -539,15 +534,10 @@ func (m *Manager) loadGroups(interval time.Duration, filenames ...string) (map[s
|
|||
}
|
||||
|
||||
if r.Alert != "" {
|
||||
fordur, err := model.ParseDuration(r.For)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
rules = append(rules, NewAlertingRule(
|
||||
r.Alert,
|
||||
expr,
|
||||
time.Duration(fordur),
|
||||
time.Duration(r.For),
|
||||
labels.FromMap(r.Labels),
|
||||
labels.FromMap(r.Annotations),
|
||||
))
|
||||
|
|
Loading…
Reference in a new issue