mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-12-01 14:47:38 +00:00
Merge branch 'public-single-node' into pmm-6401-read-prometheus-data-files
This commit is contained in:
commit
83b7eb8ca6
6 changed files with 43 additions and 11 deletions
|
@ -53,7 +53,7 @@ func newAlertingRule(group *Group, cfg config.Rule) *AlertingRule {
|
||||||
RuleID: cfg.ID,
|
RuleID: cfg.ID,
|
||||||
Name: cfg.Alert,
|
Name: cfg.Alert,
|
||||||
Expr: cfg.Expr,
|
Expr: cfg.Expr,
|
||||||
For: cfg.For,
|
For: cfg.For.Duration(),
|
||||||
Labels: cfg.Labels,
|
Labels: cfg.Labels,
|
||||||
Annotations: cfg.Annotations,
|
Annotations: cfg.Annotations,
|
||||||
GroupID: group.ID(),
|
GroupID: group.ID(),
|
||||||
|
|
|
@ -94,7 +94,7 @@ type Rule struct {
|
||||||
Record string `yaml:"record,omitempty"`
|
Record string `yaml:"record,omitempty"`
|
||||||
Alert string `yaml:"alert,omitempty"`
|
Alert string `yaml:"alert,omitempty"`
|
||||||
Expr string `yaml:"expr"`
|
Expr string `yaml:"expr"`
|
||||||
For time.Duration `yaml:"for,omitempty"`
|
For PromDuration `yaml:"for,omitempty"`
|
||||||
Labels map[string]string `yaml:"labels,omitempty"`
|
Labels map[string]string `yaml:"labels,omitempty"`
|
||||||
Annotations map[string]string `yaml:"annotations,omitempty"`
|
Annotations map[string]string `yaml:"annotations,omitempty"`
|
||||||
|
|
||||||
|
@ -102,6 +102,37 @@ type Rule struct {
|
||||||
XXX map[string]interface{} `yaml:",inline"`
|
XXX map[string]interface{} `yaml:",inline"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// PromDuration is Prometheus duration.
|
||||||
|
type PromDuration struct {
|
||||||
|
milliseconds int64
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewPromDuration returns PromDuration for given d.
|
||||||
|
func NewPromDuration(d time.Duration) PromDuration {
|
||||||
|
return PromDuration{
|
||||||
|
milliseconds: d.Milliseconds(),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// UnmarshalYAML implements yaml.Unmarshaler interface.
|
||||||
|
func (pd *PromDuration) UnmarshalYAML(unmarshal func(interface{}) error) error {
|
||||||
|
var s string
|
||||||
|
if err := unmarshal(&s); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
ms, err := metricsql.DurationValue(s, 0)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
pd.milliseconds = ms
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Duration returns duration for pd.
|
||||||
|
func (pd *PromDuration) Duration() time.Duration {
|
||||||
|
return time.Duration(pd.milliseconds) * time.Millisecond
|
||||||
|
}
|
||||||
|
|
||||||
// UnmarshalYAML implements the yaml.Unmarshaler interface.
|
// UnmarshalYAML implements the yaml.Unmarshaler interface.
|
||||||
func (r *Rule) UnmarshalYAML(unmarshal func(interface{}) error) error {
|
func (r *Rule) UnmarshalYAML(unmarshal func(interface{}) error) error {
|
||||||
type rule Rule
|
type rule Rule
|
||||||
|
|
|
@ -270,7 +270,7 @@ func TestHashRule(t *testing.T) {
|
||||||
true,
|
true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Rule{Alert: "alert", Expr: "up == 1", For: time.Minute},
|
Rule{Alert: "alert", Expr: "up == 1", For: NewPromDuration(time.Minute)},
|
||||||
Rule{Alert: "alert", Expr: "up == 1"},
|
Rule{Alert: "alert", Expr: "up == 1"},
|
||||||
true,
|
true,
|
||||||
},
|
},
|
||||||
|
|
4
app/vmalert/config/testdata/kube-good.rules
vendored
4
app/vmalert/config/testdata/kube-good.rules
vendored
|
@ -665,7 +665,7 @@
|
||||||
/
|
/
|
||||||
sum(rate(kube_state_metrics_list_total{job="kube-state-metrics"}[5m])))
|
sum(rate(kube_state_metrics_list_total{job="kube-state-metrics"}[5m])))
|
||||||
> 0.01
|
> 0.01
|
||||||
for: 15m
|
for: 1d
|
||||||
labels:
|
labels:
|
||||||
severity: critical
|
severity: critical
|
||||||
- alert: KubeStateMetricsWatchErrors
|
- alert: KubeStateMetricsWatchErrors
|
||||||
|
@ -1724,4 +1724,4 @@
|
||||||
rate(prometheus_operator_node_address_lookup_errors_total{job="prometheus-operator",namespace="monitoring"}[5m]) > 0.1
|
rate(prometheus_operator_node_address_lookup_errors_total{job="prometheus-operator",namespace="monitoring"}[5m]) > 0.1
|
||||||
for: 10m
|
for: 10m
|
||||||
labels:
|
labels:
|
||||||
severity: warning
|
severity: warning
|
||||||
|
|
|
@ -32,7 +32,7 @@ func TestUpdateWith(t *testing.T) {
|
||||||
[]config.Rule{{
|
[]config.Rule{{
|
||||||
Alert: "foo",
|
Alert: "foo",
|
||||||
Expr: "up > 0",
|
Expr: "up > 0",
|
||||||
For: time.Second,
|
For: config.NewPromDuration(time.Second),
|
||||||
Labels: map[string]string{
|
Labels: map[string]string{
|
||||||
"bar": "baz",
|
"bar": "baz",
|
||||||
},
|
},
|
||||||
|
@ -44,7 +44,7 @@ func TestUpdateWith(t *testing.T) {
|
||||||
[]config.Rule{{
|
[]config.Rule{{
|
||||||
Alert: "foo",
|
Alert: "foo",
|
||||||
Expr: "up > 10",
|
Expr: "up > 10",
|
||||||
For: time.Second,
|
For: config.NewPromDuration(time.Second),
|
||||||
Labels: map[string]string{
|
Labels: map[string]string{
|
||||||
"baz": "bar",
|
"baz": "bar",
|
||||||
},
|
},
|
||||||
|
|
|
@ -93,7 +93,7 @@ scrape_configs:
|
||||||
t.Fatalf("cannot parase data: %s", err)
|
t.Fatalf("cannot parase data: %s", err)
|
||||||
}
|
}
|
||||||
sws := cfg.getStaticScrapeWork()
|
sws := cfg.getStaticScrapeWork()
|
||||||
resetScrapeWorkIDs(sws)
|
resetNonEssentialFields(sws)
|
||||||
swsExpected := []ScrapeWork{{
|
swsExpected := []ScrapeWork{{
|
||||||
ScrapeURL: "http://black:9115/probe?module=dns_udp_example&target=8.8.8.8",
|
ScrapeURL: "http://black:9115/probe?module=dns_udp_example&target=8.8.8.8",
|
||||||
ScrapeInterval: defaultScrapeInterval,
|
ScrapeInterval: defaultScrapeInterval,
|
||||||
|
@ -440,9 +440,10 @@ scrape_configs:
|
||||||
`)
|
`)
|
||||||
}
|
}
|
||||||
|
|
||||||
func resetScrapeWorkIDs(sws []ScrapeWork) {
|
func resetNonEssentialFields(sws []ScrapeWork) {
|
||||||
for i := range sws {
|
for i := range sws {
|
||||||
sws[i].ID = 0
|
sws[i].ID = 0
|
||||||
|
sws[i].OriginalLabels = nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -453,7 +454,7 @@ func TestGetFileSDScrapeWorkSuccess(t *testing.T) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("unexpected error: %s", err)
|
t.Fatalf("unexpected error: %s", err)
|
||||||
}
|
}
|
||||||
resetScrapeWorkIDs(sws)
|
resetNonEssentialFields(sws)
|
||||||
|
|
||||||
// Remove `__vm_filepath` label, since its value depends on the current working dir.
|
// Remove `__vm_filepath` label, since its value depends on the current working dir.
|
||||||
for i := range sws {
|
for i := range sws {
|
||||||
|
@ -609,7 +610,7 @@ func TestGetStaticScrapeWorkSuccess(t *testing.T) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("unexpected error: %s", err)
|
t.Fatalf("unexpected error: %s", err)
|
||||||
}
|
}
|
||||||
resetScrapeWorkIDs(sws)
|
resetNonEssentialFields(sws)
|
||||||
if !reflect.DeepEqual(sws, expectedSws) {
|
if !reflect.DeepEqual(sws, expectedSws) {
|
||||||
t.Fatalf("unexpected scrapeWork; got\n%v\nwant\n%v", sws, expectedSws)
|
t.Fatalf("unexpected scrapeWork; got\n%v\nwant\n%v", sws, expectedSws)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue