{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://catalog.lintel.tools/schemas/schemastore/prometheus-rules-test-json/latest.json",
  "title": "Prometheus Rules Test File",
  "description": "Prometheus rules test file. See <https://prometheus.io/docs/prometheus/latest/configuration/unit_testing_rules/> for details.",
  "x-lintel": {
    "source": "https://www.schemastore.org/prometheus.rules.test.json",
    "sourceSha256": "02db40c6b6ac3b77107e778dfaf1c35a919c5a2c0f0438193a42b5d34b1f7b8d",
    "fileMatch": [
      "*.prometheus.tests.yml",
      "*.prometheus.tests.yaml",
      "*.prometheus.test.yml",
      "*.prometheus.test.yaml"
    ],
    "parsers": [
      "yaml"
    ]
  },
  "type": "object",
  "properties": {
    "evaluation_interval": {
      "default": "1m",
      "description": "The evaluation interval for the tests. [duration] format.",
      "type": [
        "string",
        "null"
      ]
    },
    "group_eval_order": {
      "description": "The order in which group names are listed below will be the order of evaluation of rule groups (at a given evaluation time).",
      "items": {
        "type": "string"
      },
      "type": [
        "array",
        "null"
      ]
    },
    "rule_files": {
      "description": "List of rule files to consider for testing. Globs are supported.",
      "items": {
        "type": "string"
      },
      "type": "array"
    },
    "tests": {
      "items": {
        "$ref": "#/$defs/test_group",
        "description": "All the tests are listed here."
      },
      "type": "array"
    }
  },
  "$defs": {
    "alert": {
      "properties": {
        "exp_annotations": {
          "$ref": "#/$defs/labels",
          "description": "Expanded annotations of the expected alert"
        },
        "exp_labels": {
          "$ref": "#/$defs/labels",
          "description": "Expanded labels and annotations of the expected alert. This also include the labels of the sample associated with the alert (same as what you see in `/alerts`, without series `__name__` and `alertname`)."
        }
      },
      "required": [
        "exp_labels"
      ],
      "type": "object"
    },
    "alert_test_case": {
      "type": "object",
      "properties": {
        "alertname": {
          "description": "Name of the alert to be tested.",
          "type": "string"
        },
        "eval_time": {
          "$ref": "#/$defs/duration",
          "description": "The time elapsed from time=0s when the alerts have to be checked."
        },
        "exp_alerts": {
          "description": "List of expected alerts firing under the given alertname at the given evaluation time",
          "items": {
            "$ref": "#/$defs/alert"
          },
          "type": "array"
        }
      },
      "required": [
        "eval_time",
        "alertname"
      ],
      "additionalProperties": false
    },
    "duration": {
      "minLength": 1,
      "pattern": "^([0-9]+y)?([0-9]+w)?([0-9]+d)?([0-9]+h)?([0-9]+m)?([0-9]+s)?([0-9]+ms)?$",
      "type": [
        "string",
        "null"
      ]
    },
    "label_value": {
      "type": "string"
    },
    "labels": {
      "type": [
        "object",
        "null"
      ],
      "additionalProperties": false,
      "patternProperties": {
        "^[a-zA-Z_][a-zA-Z0-9_]*$": {
          "$ref": "#/$defs/label_value"
        }
      }
    },
    "promql_test_case": {
      "type": "object",
      "properties": {
        "eval_time": {
          "$ref": "#/$defs/duration",
          "description": "The time elapsed from time=0s when the expression has to be evaluated."
        },
        "exp_samples": {
          "description": "Expected samples at the given evaluation time.",
          "items": {
            "$ref": "#/$defs/sample"
          },
          "type": "array"
        },
        "expr": {
          "description": "PromQL expression to evaluate",
          "anyOf": [
            {
              "type": "string"
            },
            {
              "type": "integer"
            }
          ]
        }
      },
      "required": [
        "expr",
        "eval_time"
      ],
      "additionalProperties": false
    },
    "sample": {
      "properties": {
        "labels": {
          "description": "Labels of the sample in the usual series notation '<metric name>{<label name>=<label value>, ...}'",
          "type": "string"
        },
        "value": {
          "description": "Expected value of the PromQL expression.",
          "type": "number"
        }
      },
      "required": [
        "labels",
        "value"
      ],
      "type": "object"
    },
    "series": {
      "type": "object",
      "properties": {
        "series": {
          "description": "This follows the usual series notation '<metric name>{<label name>=<label value>, ...}'.",
          "type": "string"
        },
        "values": {
          "description": "This uses expanded notation to project time series. There are also the special `_` and `stale` values to indicate missing or stale samples",
          "type": "string"
        }
      },
      "required": [
        "series",
        "values"
      ],
      "additionalProperties": false
    },
    "test_group": {
      "type": "object",
      "properties": {
        "alert_rule_test": {
          "description": "Unit tests for alerting rules. We only consider the alerting rules from the input files.",
          "items": {
            "$ref": "#/$defs/alert_test_case"
          },
          "type": "array"
        },
        "external_labels": {
          "$ref": "#/$defs/labels",
          "description": "External labels accessible to the alert template."
        },
        "external_url": {
          "description": "External URL accessible to the alert template. Usually set using --web.external-url.",
          "type": "string"
        },
        "input_series": {
          "description": "A list of time series",
          "items": {
            "$ref": "#/$defs/series"
          },
          "type": "array"
        },
        "interval": {
          "$ref": "#/$defs/duration",
          "description": "The time elapsed from time=0s when the alerts have to be checked."
        },
        "name": {
          "description": "Name of the test group",
          "type": "string"
        },
        "promql_expr_test": {
          "description": "Unit tests for PromQL expressions",
          "items": {
            "$ref": "#/$defs/promql_test_case"
          },
          "type": "array"
        }
      },
      "required": [
        "interval",
        "input_series"
      ],
      "additionalProperties": false
    }
  },
  "additionalProperties": false
}
