Alerting: conversion API structure (#100258)

This commit is contained in:
Alexander Akhmetov
2025-02-12 08:13:21 +01:00
committed by GitHub
parent 9b37e9249a
commit 9593e51da7
18 changed files with 1333 additions and 8 deletions
+78 -1
View File
@@ -734,6 +734,20 @@
},
"type": "array"
},
"ConvertPrometheusResponse": {
"properties": {
"error": {
"type": "string"
},
"errorType": {
"type": "string"
},
"status": {
"type": "string"
}
},
"type": "object"
},
"CounterResetHint": {
"description": "or alternatively that we are dealing with a gauge histogram, where counter resets do not apply.",
"format": "uint8",
@@ -2940,6 +2954,70 @@
},
"type": "object"
},
"PrometheusNamespace": {
"properties": {
"Body": {
"additionalProperties": {
"items": {
"$ref": "#/definitions/PrometheusRuleGroup"
},
"type": "array"
},
"description": "in: body",
"type": "object"
}
},
"type": "object"
},
"PrometheusRule": {
"properties": {
"Alert": {
"type": "string"
},
"Annotations": {
"additionalProperties": {
"type": "string"
},
"type": "object"
},
"Expr": {
"type": "string"
},
"For": {
"type": "string"
},
"KeepFiringFor": {
"type": "string"
},
"Labels": {
"additionalProperties": {
"type": "string"
},
"type": "object"
},
"Record": {
"type": "string"
}
},
"type": "object"
},
"PrometheusRuleGroup": {
"properties": {
"Interval": {
"$ref": "#/definitions/Duration"
},
"Name": {
"type": "string"
},
"Rules": {
"items": {
"$ref": "#/definitions/PrometheusRule"
},
"type": "array"
}
},
"type": "object"
},
"Provenance": {
"type": "string"
},
@@ -4692,7 +4770,6 @@
"type": "object"
},
"alertGroups": {
"description": "AlertGroups alert groups",
"items": {
"$ref": "#/definitions/alertGroup",
"type": "object"
@@ -0,0 +1,139 @@
package definitions
import (
"github.com/prometheus/common/model"
)
// swagger:route GET /convert/prometheus/config/v1/rules convert_prometheus RouteConvertPrometheusGetRules
//
// Gets all namespaces with their rule groups in Prometheus format.
//
// Produces:
// - application/json
//
// Responses:
// 200: PrometheusNamespace
// 403: ForbiddenError
// 404: NotFound
// swagger:route GET /convert/prometheus/config/v1/rules/{NamespaceTitle} convert_prometheus RouteConvertPrometheusGetNamespace
//
// Gets rules in prometheus format for a given namespace.
//
// Produces:
// - application/json
//
// Responses:
// 200: PrometheusNamespace
// 403: ForbiddenError
// 404: NotFound
// swagger:route GET /convert/prometheus/config/v1/rules/{NamespaceTitle}/{Group} convert_prometheus RouteConvertPrometheusGetRuleGroup
//
// Gets a rule group in Prometheus format.
//
// Produces:
// - application/json
//
// Responses:
// 200: PrometheusRuleGroup
// 403: ForbiddenError
// 404: NotFound
// swagger:route POST /convert/prometheus/config/v1/rules/{NamespaceTitle} convert_prometheus RouteConvertPrometheusPostRuleGroup
//
// Creates or updates a rule group in Prometheus format.
//
// Consumes:
// - application/yaml
//
// Produces:
// - application/json
//
// Responses:
// 202: ConvertPrometheusResponse
// 403: ForbiddenError
//
// Extensions:
// x-raw-request: true
// swagger:route DELETE /convert/prometheus/config/v1/rules/{NamespaceTitle} convert_prometheus RouteConvertPrometheusDeleteNamespace
//
// Deletes all rule groups in the given namespace.
//
// Produces:
// - application/json
//
// Responses:
// 202: ConvertPrometheusResponse
// 403: ForbiddenError
// swagger:route DELETE /convert/prometheus/config/v1/rules/{NamespaceTitle}/{Group} convert_prometheus RouteConvertPrometheusDeleteRuleGroup
//
// Deletes a rule group in Prometheus format.
//
// Produces:
// - application/json
//
// Responses:
// 202: ConvertPrometheusResponse
// 403: ForbiddenError
// swagger:parameters RouteConvertPrometheusPostRuleGroup
type RouteConvertPrometheusPostRuleGroupParams struct {
// in: path
NamespaceTitle string
// in: header
DatasourceUID string `json:"x-datasource-uid"`
// in: header
RecordingRulesPaused bool `json:"x-recording-rules-paused"`
// in: header
AlertRulesPaused bool `json:"x-alert-rules-paused"`
// in:body
Body PrometheusRuleGroup
}
// swagger:model
type PrometheusNamespace struct {
// in: body
Body map[string][]PrometheusRuleGroup
}
// swagger:model
type PrometheusRuleGroup struct {
Name string `yaml:"name"`
Interval model.Duration `yaml:"interval"`
Rules []PrometheusRule `yaml:"rules"`
}
// swagger:model
type PrometheusRule struct {
Alert string `yaml:"alert,omitempty"`
Expr string `yaml:"expr"`
For *model.Duration `yaml:"for,omitempty"`
KeepFiringFor *model.Duration `yaml:"keep_firing_for,omitempty"`
Labels map[string]string `yaml:"labels,omitempty"`
Annotations map[string]string `yaml:"annotations,omitempty"`
Record string `yaml:"record,omitempty"`
}
// swagger:parameters RouteConvertPrometheusDeleteRuleGroup RouteConvertPrometheusGetRuleGroup
type RouteConvertPrometheusDeleteRuleGroupParams struct {
// in: path
NamespaceTitle string
// in: path
Group string
}
// swagger:parameters RouteConvertPrometheusDeleteNamespace RouteConvertPrometheusGetNamespace
type RouteConvertPrometheusDeleteNamespaceParams struct {
// in: path
NamespaceTitle string
}
// swagger:model
type ConvertPrometheusResponse struct {
Status string `json:"status"`
ErrorType string `json:"errorType"`
Error string `json:"error"`
}
+330 -2
View File
@@ -734,6 +734,20 @@
},
"type": "array"
},
"ConvertPrometheusResponse": {
"properties": {
"error": {
"type": "string"
},
"errorType": {
"type": "string"
},
"status": {
"type": "string"
}
},
"type": "object"
},
"CounterResetHint": {
"description": "or alternatively that we are dealing with a gauge histogram, where counter resets do not apply.",
"format": "uint8",
@@ -2940,6 +2954,70 @@
},
"type": "object"
},
"PrometheusNamespace": {
"properties": {
"Body": {
"additionalProperties": {
"items": {
"$ref": "#/definitions/PrometheusRuleGroup"
},
"type": "array"
},
"description": "in: body",
"type": "object"
}
},
"type": "object"
},
"PrometheusRule": {
"properties": {
"Alert": {
"type": "string"
},
"Annotations": {
"additionalProperties": {
"type": "string"
},
"type": "object"
},
"Expr": {
"type": "string"
},
"For": {
"type": "string"
},
"KeepFiringFor": {
"type": "string"
},
"Labels": {
"additionalProperties": {
"type": "string"
},
"type": "object"
},
"Record": {
"type": "string"
}
},
"type": "object"
},
"PrometheusRuleGroup": {
"properties": {
"Interval": {
"$ref": "#/definitions/Duration"
},
"Name": {
"type": "string"
},
"Rules": {
"items": {
"$ref": "#/definitions/PrometheusRule"
},
"type": "array"
}
},
"type": "object"
},
"Provenance": {
"type": "string"
},
@@ -4854,7 +4932,6 @@
"type": "object"
},
"gettableAlerts": {
"description": "GettableAlerts gettable alerts",
"items": {
"$ref": "#/definitions/gettableAlert",
"type": "object"
@@ -4979,7 +5056,6 @@
"type": "object"
},
"gettableSilences": {
"description": "GettableSilences gettable silences",
"items": {
"$ref": "#/definitions/gettableSilence",
"type": "object"
@@ -6322,6 +6398,252 @@
]
}
},
"/convert/prometheus/config/v1/rules": {
"get": {
"operationId": "RouteConvertPrometheusGetRules",
"produces": [
"application/json"
],
"responses": {
"200": {
"description": "PrometheusNamespace",
"schema": {
"$ref": "#/definitions/PrometheusNamespace"
}
},
"403": {
"description": "ForbiddenError",
"schema": {
"$ref": "#/definitions/ForbiddenError"
}
},
"404": {
"description": "NotFound",
"schema": {
"$ref": "#/definitions/NotFound"
}
}
},
"summary": "Gets all namespaces with their rule groups in Prometheus format.",
"tags": [
"convert_prometheus"
]
}
},
"/convert/prometheus/config/v1/rules/{NamespaceTitle}": {
"delete": {
"operationId": "RouteConvertPrometheusDeleteNamespace",
"parameters": [
{
"in": "path",
"name": "NamespaceTitle",
"required": true,
"type": "string"
}
],
"produces": [
"application/json"
],
"responses": {
"202": {
"description": "ConvertPrometheusResponse",
"schema": {
"$ref": "#/definitions/ConvertPrometheusResponse"
}
},
"403": {
"description": "ForbiddenError",
"schema": {
"$ref": "#/definitions/ForbiddenError"
}
}
},
"summary": "Deletes all rule groups in the given namespace.",
"tags": [
"convert_prometheus"
]
},
"get": {
"operationId": "RouteConvertPrometheusGetNamespace",
"parameters": [
{
"in": "path",
"name": "NamespaceTitle",
"required": true,
"type": "string"
}
],
"produces": [
"application/json"
],
"responses": {
"200": {
"description": "PrometheusNamespace",
"schema": {
"$ref": "#/definitions/PrometheusNamespace"
}
},
"403": {
"description": "ForbiddenError",
"schema": {
"$ref": "#/definitions/ForbiddenError"
}
},
"404": {
"description": "NotFound",
"schema": {
"$ref": "#/definitions/NotFound"
}
}
},
"summary": "Gets rules in prometheus format for a given namespace.",
"tags": [
"convert_prometheus"
]
},
"post": {
"consumes": [
"application/yaml"
],
"operationId": "RouteConvertPrometheusPostRuleGroup",
"parameters": [
{
"in": "path",
"name": "NamespaceTitle",
"required": true,
"type": "string"
},
{
"in": "header",
"name": "x-datasource-uid",
"type": "string"
},
{
"in": "header",
"name": "x-recording-rules-paused",
"type": "boolean"
},
{
"in": "header",
"name": "x-alert-rules-paused",
"type": "boolean"
},
{
"in": "body",
"name": "Body",
"schema": {
"$ref": "#/definitions/PrometheusRuleGroup"
}
}
],
"produces": [
"application/json"
],
"responses": {
"202": {
"description": "ConvertPrometheusResponse",
"schema": {
"$ref": "#/definitions/ConvertPrometheusResponse"
}
},
"403": {
"description": "ForbiddenError",
"schema": {
"$ref": "#/definitions/ForbiddenError"
}
}
},
"summary": "Creates or updates a rule group in Prometheus format.",
"tags": [
"convert_prometheus"
],
"x-raw-request": "true"
}
},
"/convert/prometheus/config/v1/rules/{NamespaceTitle}/{Group}": {
"delete": {
"operationId": "RouteConvertPrometheusDeleteRuleGroup",
"parameters": [
{
"in": "path",
"name": "NamespaceTitle",
"required": true,
"type": "string"
},
{
"in": "path",
"name": "Group",
"required": true,
"type": "string"
}
],
"produces": [
"application/json"
],
"responses": {
"202": {
"description": "ConvertPrometheusResponse",
"schema": {
"$ref": "#/definitions/ConvertPrometheusResponse"
}
},
"403": {
"description": "ForbiddenError",
"schema": {
"$ref": "#/definitions/ForbiddenError"
}
}
},
"summary": "Deletes a rule group in Prometheus format.",
"tags": [
"convert_prometheus"
]
},
"get": {
"operationId": "RouteConvertPrometheusGetRuleGroup",
"parameters": [
{
"in": "path",
"name": "NamespaceTitle",
"required": true,
"type": "string"
},
{
"in": "path",
"name": "Group",
"required": true,
"type": "string"
}
],
"produces": [
"application/json"
],
"responses": {
"200": {
"description": "PrometheusRuleGroup",
"schema": {
"$ref": "#/definitions/PrometheusRuleGroup"
}
},
"403": {
"description": "ForbiddenError",
"schema": {
"$ref": "#/definitions/ForbiddenError"
}
},
"404": {
"description": "NotFound",
"schema": {
"$ref": "#/definitions/NotFound"
}
}
},
"summary": "Gets a rule group in Prometheus format.",
"tags": [
"convert_prometheus"
]
}
},
"/prometheus/grafana/api/v1/alerts": {
"get": {
"description": "gets the current alerts",
@@ -6886,6 +7208,12 @@
"schema": {
"$ref": "#/definitions/ForbiddenError"
}
},
"404": {
"description": "NotFound",
"schema": {
"$ref": "#/definitions/NotFound"
}
}
},
"tags": [
+330 -2
View File
@@ -1102,6 +1102,252 @@
}
}
},
"/convert/prometheus/config/v1/rules": {
"get": {
"produces": [
"application/json"
],
"tags": [
"convert_prometheus"
],
"summary": "Gets all namespaces with their rule groups in Prometheus format.",
"operationId": "RouteConvertPrometheusGetRules",
"responses": {
"200": {
"description": "PrometheusNamespace",
"schema": {
"$ref": "#/definitions/PrometheusNamespace"
}
},
"403": {
"description": "ForbiddenError",
"schema": {
"$ref": "#/definitions/ForbiddenError"
}
},
"404": {
"description": "NotFound",
"schema": {
"$ref": "#/definitions/NotFound"
}
}
}
}
},
"/convert/prometheus/config/v1/rules/{NamespaceTitle}": {
"get": {
"produces": [
"application/json"
],
"tags": [
"convert_prometheus"
],
"summary": "Gets rules in prometheus format for a given namespace.",
"operationId": "RouteConvertPrometheusGetNamespace",
"parameters": [
{
"type": "string",
"name": "NamespaceTitle",
"in": "path",
"required": true
}
],
"responses": {
"200": {
"description": "PrometheusNamespace",
"schema": {
"$ref": "#/definitions/PrometheusNamespace"
}
},
"403": {
"description": "ForbiddenError",
"schema": {
"$ref": "#/definitions/ForbiddenError"
}
},
"404": {
"description": "NotFound",
"schema": {
"$ref": "#/definitions/NotFound"
}
}
}
},
"post": {
"consumes": [
"application/yaml"
],
"produces": [
"application/json"
],
"tags": [
"convert_prometheus"
],
"summary": "Creates or updates a rule group in Prometheus format.",
"operationId": "RouteConvertPrometheusPostRuleGroup",
"parameters": [
{
"type": "string",
"name": "NamespaceTitle",
"in": "path",
"required": true
},
{
"type": "string",
"name": "x-datasource-uid",
"in": "header"
},
{
"type": "boolean",
"name": "x-recording-rules-paused",
"in": "header"
},
{
"type": "boolean",
"name": "x-alert-rules-paused",
"in": "header"
},
{
"name": "Body",
"in": "body",
"schema": {
"$ref": "#/definitions/PrometheusRuleGroup"
}
}
],
"responses": {
"202": {
"description": "ConvertPrometheusResponse",
"schema": {
"$ref": "#/definitions/ConvertPrometheusResponse"
}
},
"403": {
"description": "ForbiddenError",
"schema": {
"$ref": "#/definitions/ForbiddenError"
}
}
},
"x-raw-request": "true"
},
"delete": {
"produces": [
"application/json"
],
"tags": [
"convert_prometheus"
],
"summary": "Deletes all rule groups in the given namespace.",
"operationId": "RouteConvertPrometheusDeleteNamespace",
"parameters": [
{
"type": "string",
"name": "NamespaceTitle",
"in": "path",
"required": true
}
],
"responses": {
"202": {
"description": "ConvertPrometheusResponse",
"schema": {
"$ref": "#/definitions/ConvertPrometheusResponse"
}
},
"403": {
"description": "ForbiddenError",
"schema": {
"$ref": "#/definitions/ForbiddenError"
}
}
}
}
},
"/convert/prometheus/config/v1/rules/{NamespaceTitle}/{Group}": {
"get": {
"produces": [
"application/json"
],
"tags": [
"convert_prometheus"
],
"summary": "Gets a rule group in Prometheus format.",
"operationId": "RouteConvertPrometheusGetRuleGroup",
"parameters": [
{
"type": "string",
"name": "NamespaceTitle",
"in": "path",
"required": true
},
{
"type": "string",
"name": "Group",
"in": "path",
"required": true
}
],
"responses": {
"200": {
"description": "PrometheusRuleGroup",
"schema": {
"$ref": "#/definitions/PrometheusRuleGroup"
}
},
"403": {
"description": "ForbiddenError",
"schema": {
"$ref": "#/definitions/ForbiddenError"
}
},
"404": {
"description": "NotFound",
"schema": {
"$ref": "#/definitions/NotFound"
}
}
}
},
"delete": {
"produces": [
"application/json"
],
"tags": [
"convert_prometheus"
],
"summary": "Deletes a rule group in Prometheus format.",
"operationId": "RouteConvertPrometheusDeleteRuleGroup",
"parameters": [
{
"type": "string",
"name": "NamespaceTitle",
"in": "path",
"required": true
},
{
"type": "string",
"name": "Group",
"in": "path",
"required": true
}
],
"responses": {
"202": {
"description": "ConvertPrometheusResponse",
"schema": {
"$ref": "#/definitions/ConvertPrometheusResponse"
}
},
"403": {
"description": "ForbiddenError",
"schema": {
"$ref": "#/definitions/ForbiddenError"
}
}
}
}
},
"/prometheus/grafana/api/v1/alerts": {
"get": {
"description": "gets the current alerts",
@@ -1633,6 +1879,12 @@
"schema": {
"$ref": "#/definitions/ForbiddenError"
}
},
"404": {
"description": "NotFound",
"schema": {
"$ref": "#/definitions/NotFound"
}
}
}
},
@@ -4420,6 +4672,20 @@
"$ref": "#/definitions/EmbeddedContactPoint"
}
},
"ConvertPrometheusResponse": {
"type": "object",
"properties": {
"error": {
"type": "string"
},
"errorType": {
"type": "string"
},
"status": {
"type": "string"
}
}
},
"CounterResetHint": {
"description": "or alternatively that we are dealing with a gauge histogram, where counter resets do not apply.",
"type": "integer",
@@ -6628,6 +6894,70 @@
}
}
},
"PrometheusNamespace": {
"type": "object",
"properties": {
"Body": {
"description": "in: body",
"type": "object",
"additionalProperties": {
"type": "array",
"items": {
"$ref": "#/definitions/PrometheusRuleGroup"
}
}
}
}
},
"PrometheusRule": {
"type": "object",
"properties": {
"Alert": {
"type": "string"
},
"Annotations": {
"type": "object",
"additionalProperties": {
"type": "string"
}
},
"Expr": {
"type": "string"
},
"For": {
"type": "string"
},
"KeepFiringFor": {
"type": "string"
},
"Labels": {
"type": "object",
"additionalProperties": {
"type": "string"
}
},
"Record": {
"type": "string"
}
}
},
"PrometheusRuleGroup": {
"type": "object",
"properties": {
"Interval": {
"$ref": "#/definitions/Duration"
},
"Name": {
"type": "string"
},
"Rules": {
"type": "array",
"items": {
"$ref": "#/definitions/PrometheusRule"
}
}
}
},
"Provenance": {
"type": "string"
},
@@ -8542,7 +8872,6 @@
}
},
"gettableAlerts": {
"description": "GettableAlerts gettable alerts",
"type": "array",
"items": {
"type": "object",
@@ -8667,7 +8996,6 @@
}
},
"gettableSilences": {
"description": "GettableSilences gettable silences",
"type": "array",
"items": {
"type": "object",
@@ -20,6 +20,14 @@ type {{classname}} interface { {{#operation}}
}
{{#operations}}{{#operation}}
{{#vendorExtensions.x-raw-request}}
func (f *{{classname}}Handler) {{nickname}}(ctx *contextmodel.ReqContext) response.Response { {{#hasPathParams}}
// Parse Path Parameters{{/hasPathParams}}{{#pathParams}}
{{paramName}}Param := web.Params(ctx.Req)[":{{baseName}}"]{{/pathParams}}
return f.handle{{nickname}}(ctx{{#pathParams}}, {{paramName}}Param{{/pathParams}})
}
{{/vendorExtensions.x-raw-request}}
{{^vendorExtensions.x-raw-request}}
func (f *{{classname}}Handler) {{nickname}}(ctx *contextmodel.ReqContext) response.Response { {{#hasPathParams}}
// Parse Path Parameters{{/hasPathParams}}{{#pathParams}}
{{paramName}}Param := web.Params(ctx.Req)[":{{baseName}}"]{{/pathParams}}
@@ -31,6 +39,7 @@ func (f *{{classname}}Handler) {{nickname}}(ctx *contextmodel.ReqContext) respon
}
{{/bodyParams}}return f.handle{{nickname}}(ctx{{#bodyParams}}, conf{{/bodyParams}}{{#pathParams}}, {{paramName}}Param{{/pathParams}})
}
{{/vendorExtensions.x-raw-request}}
{{/operation}}{{/operations}}
func (api *API) Register{{classname}}Endpoints(srv {{classname}}, m *metrics.API) {