{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://catalog.lintel.tools/schemas/schemastore/prometheus-rules-json/latest.json",
  "title": "Prometheus Rules",
  "description": "Prometheus rules file",
  "x-lintel": {
    "source": "https://www.schemastore.org/prometheus.rules.json",
    "sourceSha256": "581dcbd460280ae0aa290a3fcde970752b4dbd5ae7530cb03792ea83ce6cdaec",
    "fileMatch": [
      "*.prometheus.rules.yml",
      "*.prometheus.rules.yaml",
      "*prometheus-rules.yml",
      "*prometheus-rules.yaml",
      "*prometheus_rules.yml",
      "*prometheus_rules.yaml",
      "prometheus.rules.yml",
      "prometheus.rules.yaml"
    ],
    "parsers": [
      "yaml"
    ]
  },
  "type": [
    "object",
    "null"
  ],
  "properties": {
    "groups": {
      "type": [
        "array",
        "null"
      ],
      "items": {
        "type": "object",
        "properties": {
          "name": {
            "description": "The name of the group. Must be unique within a file.",
            "type": "string"
          },
          "interval": {
            "$ref": "#/$defs/duration",
            "description": "How often rules in the group are evaluated."
          },
          "query_offset": {
            "$ref": "#/$defs/duration",
            "description": "Offset the rule evaluation timestamp of this particular group by the specified duration into the past."
          },
          "labels": {
            "$ref": "#/$defs/labels",
            "description": "Labels to add or overwrite before storing the result for its rules. Labels defined in <rule> will override the key if it has a collision."
          },
          "limit": {
            "description": "Limit the number of alerts an alerting rule and series a recording rule can produce. 0 is no limit.",
            "type": [
              "integer",
              "null"
            ],
            "default": 0
          },
          "rules": {
            "type": [
              "array",
              "null"
            ],
            "items": {
              "oneOf": [
                {
                  "$ref": "#/$defs/recording_rule"
                },
                {
                  "$ref": "#/$defs/alerting_rule"
                }
              ]
            }
          }
        },
        "required": [
          "name"
        ],
        "additionalProperties": false
      }
    }
  },
  "$defs": {
    "duration": {
      "type": [
        "string",
        "null"
      ],
      "pattern": "^((([0-9]+)y)?(([0-9]+)w)?(([0-9]+)d)?(([0-9]+)h)?(([0-9]+)m)?(([0-9]+)s)?(([0-9]+)ms)?|0)$",
      "minLength": 1
    },
    "label_name": {
      "type": "string",
      "pattern": "^[a-zA-Z_][a-zA-Z0-9_]*$"
    },
    "label_value": {
      "type": "string"
    },
    "labels": {
      "type": [
        "object",
        "null"
      ],
      "additionalProperties": false,
      "patternProperties": {
        "^[a-zA-Z_][a-zA-Z0-9_]*$": {
          "$ref": "#/$defs/label_value"
        }
      }
    },
    "tmpl_string": {
      "description": "A string which is template-expanded before usage.",
      "type": "string"
    },
    "annotations": {
      "type": [
        "object",
        "null"
      ],
      "additionalProperties": false,
      "patternProperties": {
        "^[a-zA-Z_][a-zA-Z0-9_]*$": {
          "$ref": "#/$defs/tmpl_string"
        }
      }
    },
    "recording_rule": {
      "type": "object",
      "properties": {
        "record": {
          "description": "The name of the time series to output to. Must be a valid metric name.",
          "type": "string"
        },
        "expr": {
          "description": "The PromQL expression to evaluate. Every evaluation cycle this is evaluated at the current time, and the result recorded as a new set of time series with the metric name as given by 'record'.",
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "integer"
            }
          ]
        },
        "labels": {
          "$ref": "#/$defs/labels",
          "description": "Labels to add or overwrite before storing the result."
        }
      },
      "required": [
        "record",
        "expr"
      ],
      "additionalProperties": false
    },
    "alerting_rule": {
      "type": "object",
      "properties": {
        "alert": {
          "description": "The name of the alert. Must be a valid metric name.",
          "type": "string"
        },
        "expr": {
          "description": "The PromQL expression to evaluate. Every evaluation cycle this is evaluated at the current time, and all resultant time series become pending/firing alerts.",
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "integer"
            }
          ]
        },
        "for": {
          "$ref": "#/$defs/duration",
          "description": "Alerts are considered firing once they have been returned for this long. Alerts which have not yet fired for long enough are considered pending."
        },
        "keep_firing_for": {
          "$ref": "#/$defs/duration",
          "description": "How long an alert will continue firing after the condition that triggered it has cleared."
        },
        "labels": {
          "$ref": "#/$defs/labels",
          "description": "Labels to add or overwrite for each alert."
        },
        "annotations": {
          "$ref": "#/$defs/annotations",
          "description": "Annotations to add to each alert."
        }
      },
      "required": [
        "alert",
        "expr"
      ],
      "additionalProperties": false
    }
  },
  "additionalProperties": false
}
