{
  "$id": "https://json.schemastore.org/prometheus.rules.json",
  "$schema": "http://json-schema.org/draft-07/schema#",
  "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)?$",
      "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'.",
          "type": "string"
        },
        "labels": {
          "description": "Labels to add or overwrite before storing the result.",
          "$ref": "#/definitions/labels"
        }
      },
      "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.",
          "type": "string"
        },
        "for": {
          "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.",
          "$ref": "#/definitions/duration"
        },
        "labels": {
          "description": "Labels to add or overwrite for each alert.",
          "$ref": "#/definitions/labels"
        },
        "annotations": {
          "description": "Annotations to add to each alert.",
          "$ref": "#/definitions/annotations"
        }
      },
      "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": {
            "description": "How often rules in the group are evaluated.",
            "$ref": "#/definitions/duration"
          },
          "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"]
}