mirror of
https://github.com/prometheus/prometheus.git
synced 2025-02-02 08:31:11 -08:00
1a27ab29b8
Some checks are pending
buf.build / lint and publish (push) Waiting to run
CI / Go tests (push) Waiting to run
CI / More Go tests (push) Waiting to run
CI / Go tests with previous Go version (push) Waiting to run
CI / UI tests (push) Waiting to run
CI / Go tests on Windows (push) Waiting to run
CI / Mixins tests (push) Waiting to run
CI / Build Prometheus for common architectures (0) (push) Waiting to run
CI / Build Prometheus for common architectures (1) (push) Waiting to run
CI / Build Prometheus for common architectures (2) (push) Waiting to run
CI / Build Prometheus for all architectures (0) (push) Waiting to run
CI / Build Prometheus for all architectures (1) (push) Waiting to run
CI / Build Prometheus for all architectures (10) (push) Waiting to run
CI / Build Prometheus for all architectures (11) (push) Waiting to run
CI / Build Prometheus for all architectures (2) (push) Waiting to run
CI / Build Prometheus for all architectures (3) (push) Waiting to run
CI / Build Prometheus for all architectures (4) (push) Waiting to run
CI / Build Prometheus for all architectures (5) (push) Waiting to run
CI / Build Prometheus for all architectures (6) (push) Waiting to run
CI / Build Prometheus for all architectures (7) (push) Waiting to run
CI / Build Prometheus for all architectures (8) (push) Waiting to run
CI / Build Prometheus for all architectures (9) (push) Waiting to run
CI / Report status of build Prometheus for all architectures (push) Blocked by required conditions
CI / Check generated parser (push) Waiting to run
CI / golangci-lint (push) Waiting to run
CI / fuzzing (push) Waiting to run
CI / codeql (push) Waiting to run
CI / Publish main branch artifacts (push) Blocked by required conditions
CI / Publish release artefacts (push) Blocked by required conditions
CI / Publish UI on npm Registry (push) Blocked by required conditions
Scorecards supply-chain security / Scorecards analysis (push) Waiting to run
* Rules: Store dependencies instead of boolean To improve https://github.com/prometheus/prometheus/pull/15681 further, we'll need to store the dependencies and dependents of each Right now, if a rule has both (at least 1) dependents and dependencies, it is not possible to determine the order to run the rules and they must all run sequentially This PR only changes the dependents and dependencies attributes of rules, it does not implement a new topological sort algorithm Signed-off-by: Julien Duchesne <julien.duchesne@grafana.com> * Store a slice of Rule instead Signed-off-by: Julien Duchesne <julien.duchesne@grafana.com> * Add `BenchmarkRuleDependencyController_AnalyseRules` for future reference Signed-off-by: Julien Duchesne <julien.duchesne@grafana.com> --------- Signed-off-by: Julien Duchesne <julien.duchesne@grafana.com>
87 lines
3.3 KiB
Go
87 lines
3.3 KiB
Go
// Copyright 2013 The Prometheus Authors
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
// you may not use this file except in compliance with the License.
|
|
// You may obtain a copy of the License at
|
|
//
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
//
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
// See the License for the specific language governing permissions and
|
|
// limitations under the License.
|
|
|
|
package rules
|
|
|
|
import (
|
|
"context"
|
|
"net/url"
|
|
"time"
|
|
|
|
"github.com/prometheus/prometheus/model/labels"
|
|
"github.com/prometheus/prometheus/promql"
|
|
"github.com/prometheus/prometheus/promql/parser"
|
|
)
|
|
|
|
// RuleHealth describes the health state of a rule.
|
|
type RuleHealth string
|
|
|
|
// The possible health states of a rule based on the last execution.
|
|
const (
|
|
HealthUnknown RuleHealth = "unknown"
|
|
HealthGood RuleHealth = "ok"
|
|
HealthBad RuleHealth = "err"
|
|
)
|
|
|
|
// A Rule encapsulates a vector expression which is evaluated at a specified
|
|
// interval and acted upon (currently either recorded or used for alerting).
|
|
type Rule interface {
|
|
Name() string
|
|
// Labels of the rule.
|
|
Labels() labels.Labels
|
|
// Eval evaluates the rule, including any associated recording or alerting actions.
|
|
Eval(ctx context.Context, queryOffset time.Duration, evaluationTime time.Time, queryFunc QueryFunc, externalURL *url.URL, limit int) (promql.Vector, error)
|
|
// String returns a human-readable string representation of the rule.
|
|
String() string
|
|
// Query returns the rule query expression.
|
|
Query() parser.Expr
|
|
// SetLastError sets the current error experienced by the rule.
|
|
SetLastError(error)
|
|
// LastError returns the last error experienced by the rule.
|
|
LastError() error
|
|
// SetHealth sets the current health of the rule.
|
|
SetHealth(RuleHealth)
|
|
// Health returns the current health of the rule.
|
|
Health() RuleHealth
|
|
SetEvaluationDuration(time.Duration)
|
|
// GetEvaluationDuration returns last evaluation duration.
|
|
// NOTE: Used dynamically by rules.html template.
|
|
GetEvaluationDuration() time.Duration
|
|
SetEvaluationTimestamp(time.Time)
|
|
// GetEvaluationTimestamp returns last evaluation timestamp.
|
|
// NOTE: Used dynamically by rules.html template.
|
|
GetEvaluationTimestamp() time.Time
|
|
|
|
// SetDependentRules sets rules which depend on the output of this rule.
|
|
SetDependentRules(rules []Rule)
|
|
|
|
// NoDependentRules returns true if it's guaranteed that in the rule group there's no other rule
|
|
// which depends on this one. In case this function returns false there's no such guarantee, which
|
|
// means there may or may not be other rules depending on this one.
|
|
NoDependentRules() bool
|
|
|
|
// DependentRules returns the rules which depend on the output of this rule.
|
|
DependentRules() []Rule
|
|
|
|
// SetDependencyRules sets rules on which this rule depends.
|
|
SetDependencyRules(rules []Rule)
|
|
|
|
// NoDependencyRules returns true if it's guaranteed that this rule doesn't depend on the output of
|
|
// any other rule in the group. In case this function returns false there's no such guarantee, which
|
|
// means the rule may or may not depend on other rules.
|
|
NoDependencyRules() bool
|
|
|
|
// DependencyRules returns the rules on which this rule depends.
|
|
DependencyRules() []Rule
|
|
}
|