{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "$id": "https://json.schemastore.org/prometheus.rules.json",
  "additionalProperties": false,
  "definitions": {
    "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"],
      "patternProperties": {
        "^[a-zA-Z_][a-zA-Z0-9_]*$": {
          "$ref": "#/definitions/label_value"
        }
      },
      "additionalProperties": false
    },
    "tmpl_string": {
      "description": "A string which is template-expanded before usage.",
      "type": "string"
    },
    "annotations": {
      "type": ["object", "null"],
      "patternProperties": {
        "^[a-zA-Z_][a-zA-Z0-9_]*$": {
          "$ref": "#/definitions/tmpl_string"
        }
      },
      "additionalProperties": false
    },
    "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": "#/definitions/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": "#/definitions/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": "#/definitions/duration",
          "description": "How long an alert will continue firing after the condition that triggered it has cleared."
        },
        "labels": {
          "$ref": "#/definitions/labels",
          "description": "Labels to add or overwrite for each alert."
        },
        "annotations": {
          "$ref": "#/definitions/annotations",
          "description": "Annotations to add to each alert."
        }
      },
      "required": ["alert", "expr"],
      "additionalProperties": false
    }
  },
  "description": "Prometheus rules file",
  "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": "#/definitions/duration",
            "description": "How often rules in the group are evaluated."
          },
          "labels": {
            "$ref": "#/definitions/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": "#/definitions/recording_rule"
                },
                {
                  "$ref": "#/definitions/alerting_rule"
                }
              ]
            }
          }
        },
        "required": ["name"],
        "additionalProperties": false
      }
    }
  },
  "title": "Prometheus Rules",
  "type": ["object", "null"]
}
