mirror of
https://github.com/prometheus/prometheus.git
synced 2025-08-06 14:17:12 +02:00
This will allow correlation of executed rule queries with their associated rule names and type Signed-off-by: Danny Kopping <danny.kopping@grafana.com>
35 lines
693 B
Go
35 lines
693 B
Go
package rules
|
|
|
|
import "context"
|
|
|
|
type ruleOrigin struct{}
|
|
|
|
type RuleDetail struct {
|
|
Name string
|
|
Kind string
|
|
Query string
|
|
}
|
|
|
|
const KindAlerting = "alerting"
|
|
const KindRecording = "recording"
|
|
|
|
func NewRuleDetail(name, query, kind string) RuleDetail {
|
|
return RuleDetail{
|
|
Name: name,
|
|
Query: query,
|
|
Kind: kind,
|
|
}
|
|
}
|
|
|
|
// NewOriginContext returns a new context with data about the origin attached.
|
|
func NewOriginContext(ctx context.Context, rule RuleDetail) context.Context {
|
|
return context.WithValue(ctx, ruleOrigin{}, rule)
|
|
}
|
|
|
|
func FromOriginContext(ctx context.Context) RuleDetail {
|
|
if rule, ok := ctx.Value(ruleOrigin{}).(RuleDetail); ok {
|
|
return rule
|
|
}
|
|
return RuleDetail{}
|
|
}
|