{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "$id": "https://json.schemastore.org/prometheus.rules.json",
  "definitions": {
    "duration": {
      "anyOf": [
        {
          "type": "string",
          "minLength": 1,
          "pattern": "^((([0-9]+)y)?(([0-9]+)w)?(([0-9]+)d)?(([0-9]+)h)?(([0-9]+)m)?(([0-9]+)s)?(([0-9]+)ms)?|0)$"
        },
        {
          "type": "null"
        }
      ]
    },
    "label_name": {
      "type": "string",
      "pattern": "^[a-zA-Z_][a-zA-Z0-9_]*$"
    },
    "label_value": {
      "type": "string"
    },
    "labels": {
      "anyOf": [
        {
          "type": "object",
          "patternProperties": {
            "^[a-zA-Z_][a-zA-Z0-9_]*$": {
              "$ref": "#/definitions/label_value"
            }
          },
          "additionalProperties": false
        },
        {
          "type": "null"
        }
      ]
    },
    "tmpl_string": {
      "description": "A string which is template-expanded before usage.",
      "type": "string"
    },
    "annotations": {
      "anyOf": [
        {
          "type": "object",
          "patternProperties": {
            "^[a-zA-Z_][a-zA-Z0-9_]*$": {
              "$ref": "#/definitions/tmpl_string"
            }
          },
          "additionalProperties": false
        },
        {
          "type": "null"
        }
      ]
    },
    "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",
  "title": "Prometheus Rules",
  "anyOf": [
    {
      "type": "object",
      "properties": {
        "groups": {
          "anyOf": [
            {
              "type": "array",
              "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."
                  },
                  "query_offset": {
                    "$ref": "#/definitions/duration",
                    "description": "Offset the rule evaluation timestamp of this particular group by the specified duration into the past."
                  },
                  "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.",
                    "default": 0,
                    "anyOf": [
                      {
                        "type": "integer"
                      },
                      {
                        "type": "null"
                      }
                    ]
                  },
                  "rules": {
                    "anyOf": [
                      {
                        "type": "array",
                        "items": {
                          "oneOf": [
                            {
                              "$ref": "#/definitions/recording_rule"
                            },
                            {
                              "$ref": "#/definitions/alerting_rule"
                            }
                          ]
                        }
                      },
                      {
                        "type": "null"
                      }
                    ]
                  }
                },
                "required": ["name"],
                "additionalProperties": false
              }
            },
            {
              "type": "null"
            }
          ]
        }
      },
      "additionalProperties": false
    },
    {
      "type": "null"
    }
  ]
}
