Skip to content

Reference: PrometheusRule CRD

A PrometheusRule holds Prometheus alerting and recording rules. Alerting rules evaluate a PromQL expression and fire an alert while the expression returns results. Recording rules evaluate an expression and store the result as a new time series, which makes expensive queries cheap to reuse in dashboards and alerts. Rules are organized in named groups, and each group is evaluated on its own interval.

  • API version: monitoring.coreos.com/v1
  • Kind: PrometheusRule
  • Scope: Namespaced
  • Short name: promrule

This page documents Prometheus Operator v0.95.1.

Example

The following example defines one recording rule and two alerting rules for the your-application service. The first alert fires when no instance has been reachable for five minutes. The second alert fires when more than 5% of HTTP requests have failed over the last ten minutes. It assumes the application exposes an http_requests_total counter with a code label.

apiVersion: monitoring.coreos.com/v1
kind: PrometheusRule
metadata:
  name: your-application
  namespace: your-application-namespace
spec:
  groups:
  - name: your-application.rules
    interval: 1m
    rules:
    - record: job:http_requests:rate5m
      expr: sum by (job) (rate(http_requests_total{job="your-application"}[5m]))
    - alert: YourApplicationDown
      expr: sum(up{job="your-application"}) == 0
      for: 5m
      labels:
        severity: critical
      annotations:
        summary: "your-application is down"
        description: "No instance of your-application has been scraped successfully for 5 minutes."
    - alert: YourApplicationHighErrorRate
      expr: |
        sum(rate(http_requests_total{job="your-application", code=~"5.."}[10m]))
          /
        sum(rate(http_requests_total{job="your-application"}[10m]))
          > 0.05
      for: 10m
      labels:
        severity: warning
      annotations:
        summary: "your-application has a high error rate"
        description: "{{ $value | humanizePercentage }} of requests failed over the last 10 minutes."

Specification (spec)

Field Type Description
groups []object Optional. The rule groups in this resource. See spec.groups[].

spec.groups[]

Field Type Description
name string Required. The name of the rule group. Must not be empty.
rules []object Optional. The alerting and recording rules in the group. See spec.groups[].rules[].
interval string Optional. How often the rules in the group are evaluated, as a duration such as 1m. Defaults to the global evaluation interval.
labels map[string]string Optional. Labels to add or overwrite on the results of every rule in the group. Labels set on a rule take precedence. Requires Prometheus 3.0 or later.
limit integer Optional. The maximum number of alerts an alerting rule, or series a recording rule, can produce.
query_offset string Optional. Shifts the evaluation timestamp of the group into the past by this duration. Requires Prometheus 2.53 or later.
partial_response_strategy string Optional. Only used by Thanos Ruler and ignored by Prometheus. Allowed values: abort, warn.

spec.groups[].rules[]

Each rule is either a recording rule or an alerting rule. Set exactly one of record and alert.

Field Type Description
expr int-or-string Required. The PromQL expression to evaluate.
record string Optional. For recording rules, the name of the time series to write. Must be a valid metric name.
alert string Optional. For alerting rules, the name of the alert. Must be a valid label value.
for string Optional. For alerting rules, how long the expression must return results before the alert fires, as a duration such as 5m. Until then the alert is pending.
keep_firing_for string Optional. For alerting rules, how long the alert keeps firing after the expression stops returning results. Must not be empty if set.
labels map[string]string Optional. Labels to add or overwrite on the result. For alerts, labels such as severity are commonly used for routing.
annotations map[string]string Optional. For alerting rules, annotations to add to each alert, such as summary and description. Values can use Prometheus template variables such as {{ $value }} and {{ $labels.<name> }}.

Durations use the Prometheus format, a sequence of number and unit pairs such as 1h30m. Valid units are ms, s, m, h, d, w and y.

Status (status)

The Prometheus Operator writes status only when it runs with the StatusForConfigurationResources feature gate enabled, which is off by default upstream. The field can be empty.

Field Type Description
bindings[].resource string The type of workload that selected this resource, for example prometheuses or thanosrulers.
bindings[].name string The name of the workload that selected this resource.
bindings[].namespace string The namespace of that workload.
bindings[].conditions[].type string The condition type. Only Accepted is supported.
bindings[].conditions[].status string The condition status, for example True or False.
bindings[].conditions[].reason string A short reason for the last transition.
bindings[].conditions[].message string A human-readable explanation, for example why the operator rejected the resource.
bindings[].conditions[].observedGeneration integer The metadata.generation the condition is based on. If it is lower than the current generation, the condition is out of date.

Platform Notes

Further Reading