mirror of
https://github.com/prometheus/prometheus.git
synced 2024-12-26 06:04:05 -08:00
37b408c6cd
* [PATCH] Allow having evaluation delay for rule groups Signed-off-by: Ganesh Vernekar <ganeshvern@gmail.com> * [PATCH] Fix lint Signed-off-by: Ganesh Vernekar <ganeshvern@gmail.com> * [PATCH] Move the option to ManagerOptions Signed-off-by: Ganesh Vernekar <ganeshvern@gmail.com> * [PATCH] Include evaluation_delay in the group config Signed-off-by: Ganesh Vernekar <ganeshvern@gmail.com> * Fix comments Signed-off-by: gotjosh <josue.abreu@gmail.com> * Add a server configuration option. Signed-off-by: gotjosh <josue.abreu@gmail.com> * Appease the linter #1 Signed-off-by: gotjosh <josue.abreu@gmail.com> * Add the new server flag documentation Signed-off-by: gotjosh <josue.abreu@gmail.com> * Improve documentation of the new flag and configuration Signed-off-by: gotjosh <josue.abreu@gmail.com> * Use named parameters for clarity on the `Rule` interface Signed-off-by: gotjosh <josue.abreu@gmail.com> * Add `initial` to the flag help Signed-off-by: gotjosh <josue.abreu@gmail.com> * Change the CHANGELOG area from `ruler` to `rules` Signed-off-by: gotjosh <josue.abreu@gmail.com> * Rename evaluation_delay to `rule_query_offset`/`query_offset` and make it a global configuration option. Signed-off-by: gotjosh <josue.abreu@gmail.com> E Your branch is up to date with 'origin/gotjosh/evaluation-delay'. * more docs Signed-off-by: gotjosh <josue.abreu@gmail.com> * Improve wording on CHANGELOG Signed-off-by: gotjosh <josue.abreu@gmail.com> * Add `RuleQueryOffset` to the default config in tests in case it changes Signed-off-by: gotjosh <josue.abreu@gmail.com> * Update docs/configuration/recording_rules.md Co-authored-by: Julius Volz <julius.volz@gmail.com> Signed-off-by: gotjosh <josue.abreu@gmail.com> * Rename `RuleQueryOffset` to `QueryOffset` when in the group context. Signed-off-by: gotjosh <josue.abreu@gmail.com> * Improve docstring and documentation on the `rule_query_offset` Signed-off-by: gotjosh <josue.abreu@gmail.com> --------- Signed-off-by: Ganesh Vernekar <ganeshvern@gmail.com> Signed-off-by: gotjosh <josue.abreu@gmail.com> Co-authored-by: Ganesh Vernekar <ganeshvern@gmail.com> Co-authored-by: Julius Volz <julius.volz@gmail.com>
81 lines
3.1 KiB
Go
81 lines
3.1 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
|
|
|
|
// SetNoDependentRules sets whether there's no other rule in the rule group that depends on this rule.
|
|
SetNoDependentRules(bool)
|
|
|
|
// 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
|
|
|
|
// SetNoDependencyRules sets whether this rule doesn't depend on the output of any rule in the rule group.
|
|
SetNoDependencyRules(bool)
|
|
|
|
// 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
|
|
}
|