mirror of
https://github.com/prometheus/prometheus.git
synced 2024-12-29 07:29:42 -08:00
Merge pull request #1330 from prometheus/swapfix
Fix swapped constants, improve instrumentation
This commit is contained in:
commit
c56f35274e
|
@ -36,11 +36,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
// Constants for instrumentation.
|
// Constants for instrumentation.
|
||||||
const (
|
const namespace = "prometheus"
|
||||||
namespace = "prometheus"
|
|
||||||
|
|
||||||
ruleTypeLabel = "rule_type"
|
|
||||||
)
|
|
||||||
|
|
||||||
var (
|
var (
|
||||||
evalDuration = prometheus.NewSummaryVec(
|
evalDuration = prometheus.NewSummaryVec(
|
||||||
|
@ -49,21 +45,23 @@ var (
|
||||||
Name: "rule_evaluation_duration_seconds",
|
Name: "rule_evaluation_duration_seconds",
|
||||||
Help: "The duration for a rule to execute.",
|
Help: "The duration for a rule to execute.",
|
||||||
},
|
},
|
||||||
[]string{ruleTypeLabel},
|
[]string{"rule_type"},
|
||||||
)
|
)
|
||||||
evalFailures = prometheus.NewCounter(
|
evalFailures = prometheus.NewCounterVec(
|
||||||
prometheus.CounterOpts{
|
prometheus.CounterOpts{
|
||||||
Namespace: namespace,
|
Namespace: namespace,
|
||||||
Name: "rule_evaluation_failures_total",
|
Name: "rule_evaluation_failures_total",
|
||||||
Help: "The total number of rule evaluation failures.",
|
Help: "The total number of rule evaluation failures.",
|
||||||
},
|
},
|
||||||
|
[]string{"rule_type"},
|
||||||
)
|
)
|
||||||
evalTotal = prometheus.NewCounter(
|
evalTotal = prometheus.NewCounterVec(
|
||||||
prometheus.CounterOpts{
|
prometheus.CounterOpts{
|
||||||
Namespace: namespace,
|
Namespace: namespace,
|
||||||
Name: "rule_evaluations_total",
|
Name: "rule_evaluations_total",
|
||||||
Help: "The total number of rule evaluations.",
|
Help: "The total number of rule evaluations.",
|
||||||
},
|
},
|
||||||
|
[]string{"rule_type"},
|
||||||
)
|
)
|
||||||
iterationDuration = prometheus.NewSummary(prometheus.SummaryOpts{
|
iterationDuration = prometheus.NewSummary(prometheus.SummaryOpts{
|
||||||
Namespace: namespace,
|
Namespace: namespace,
|
||||||
|
@ -74,6 +72,11 @@ var (
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
evalTotal.WithLabelValues(string(ruleTypeAlert))
|
||||||
|
evalTotal.WithLabelValues(string(ruleTypeRecording))
|
||||||
|
evalFailures.WithLabelValues(string(ruleTypeAlert))
|
||||||
|
evalFailures.WithLabelValues(string(ruleTypeRecording))
|
||||||
|
|
||||||
prometheus.MustRegister(iterationDuration)
|
prometheus.MustRegister(iterationDuration)
|
||||||
prometheus.MustRegister(evalFailures)
|
prometheus.MustRegister(evalFailures)
|
||||||
prometheus.MustRegister(evalDuration)
|
prometheus.MustRegister(evalDuration)
|
||||||
|
@ -200,6 +203,16 @@ func (g *Group) copyState(from *Group) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func typeForRule(r Rule) ruleType {
|
||||||
|
switch r.(type) {
|
||||||
|
case *AlertingRule:
|
||||||
|
return ruleTypeAlert
|
||||||
|
case *RecordingRule:
|
||||||
|
return ruleTypeRecording
|
||||||
|
}
|
||||||
|
panic(fmt.Errorf("unknown rule type: %T", r))
|
||||||
|
}
|
||||||
|
|
||||||
// eval runs a single evaluation cycle in which all rules are evaluated in parallel.
|
// eval runs a single evaluation cycle in which all rules are evaluated in parallel.
|
||||||
// In the future a single group will be evaluated sequentially to properly handle
|
// In the future a single group will be evaluated sequentially to properly handle
|
||||||
// rule dependency.
|
// rule dependency.
|
||||||
|
@ -210,13 +223,18 @@ func (g *Group) eval() {
|
||||||
)
|
)
|
||||||
|
|
||||||
for _, rule := range g.rules {
|
for _, rule := range g.rules {
|
||||||
|
rtyp := string(typeForRule(rule))
|
||||||
|
|
||||||
wg.Add(1)
|
wg.Add(1)
|
||||||
// BUG(julius): Look at fixing thundering herd.
|
// BUG(julius): Look at fixing thundering herd.
|
||||||
go func(rule Rule) {
|
go func(rule Rule) {
|
||||||
defer wg.Done()
|
defer wg.Done()
|
||||||
|
|
||||||
start := time.Now()
|
defer func(t time.Time) {
|
||||||
evalTotal.Inc()
|
evalDuration.WithLabelValues(rtyp).Observe(float64(time.Since(t)) / float64(time.Second))
|
||||||
|
}(time.Now())
|
||||||
|
|
||||||
|
evalTotal.WithLabelValues(rtyp).Inc()
|
||||||
|
|
||||||
vector, err := rule.eval(now, g.opts.QueryEngine)
|
vector, err := rule.eval(now, g.opts.QueryEngine)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -225,26 +243,13 @@ func (g *Group) eval() {
|
||||||
if _, ok := err.(promql.ErrQueryCanceled); !ok {
|
if _, ok := err.(promql.ErrQueryCanceled); !ok {
|
||||||
log.Warnf("Error while evaluating rule %q: %s", rule, err)
|
log.Warnf("Error while evaluating rule %q: %s", rule, err)
|
||||||
}
|
}
|
||||||
evalFailures.Inc()
|
evalFailures.WithLabelValues(rtyp).Inc()
|
||||||
}
|
return
|
||||||
var rtyp ruleType
|
|
||||||
|
|
||||||
switch r := rule.(type) {
|
|
||||||
case *AlertingRule:
|
|
||||||
rtyp = ruleTypeRecording
|
|
||||||
g.sendAlerts(r, now)
|
|
||||||
|
|
||||||
case *RecordingRule:
|
|
||||||
rtyp = ruleTypeAlert
|
|
||||||
|
|
||||||
default:
|
|
||||||
panic(fmt.Errorf("unknown rule type: %T", rule))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
evalDuration.WithLabelValues(string(rtyp)).Observe(
|
if ar, ok := rule.(*AlertingRule); ok {
|
||||||
float64(time.Since(start)) / float64(time.Second),
|
g.sendAlerts(ar, now)
|
||||||
)
|
}
|
||||||
|
|
||||||
for _, s := range vector {
|
for _, s := range vector {
|
||||||
g.opts.SampleAppender.Append(s)
|
g.opts.SampleAppender.Append(s)
|
||||||
}
|
}
|
||||||
|
|
|
@ -864,6 +864,7 @@ type bintree struct {
|
||||||
Func func() (*asset, error)
|
Func func() (*asset, error)
|
||||||
Children map[string]*bintree
|
Children map[string]*bintree
|
||||||
}
|
}
|
||||||
|
|
||||||
var _bintree = &bintree{nil, map[string]*bintree{
|
var _bintree = &bintree{nil, map[string]*bintree{
|
||||||
"web": &bintree{nil, map[string]*bintree{
|
"web": &bintree{nil, map[string]*bintree{
|
||||||
"ui": &bintree{nil, map[string]*bintree{
|
"ui": &bintree{nil, map[string]*bintree{
|
||||||
|
@ -979,4 +980,3 @@ func _filePath(dir, name string) string {
|
||||||
cannonicalName := strings.Replace(name, "\\", "/", -1)
|
cannonicalName := strings.Replace(name, "\\", "/", -1)
|
||||||
return filepath.Join(append([]string{dir}, strings.Split(cannonicalName, "/")...)...)
|
return filepath.Join(append([]string{dir}, strings.Split(cannonicalName, "/")...)...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue