[Alerting]: Add alerting endpoint for Query Evaluation (#33174)
* [Alerting]: Add alerting endpoint for Query Evaluation * Fix passing down now parameter * Add validations and test * Fix eval queries and expressions test * Add eval tests
This commit is contained in:
@@ -3,6 +3,9 @@ package definitions
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/grafana/grafana-plugin-sdk-go/backend"
|
||||
|
||||
"github.com/grafana/grafana/pkg/services/ngalert/models"
|
||||
"github.com/prometheus/alertmanager/config"
|
||||
@@ -37,6 +40,19 @@ import (
|
||||
// Responses:
|
||||
// 200: TestRuleResponse
|
||||
|
||||
// swagger:route Post /api/v1/eval testing RouteEvalQueries
|
||||
//
|
||||
// Test rule
|
||||
//
|
||||
// Consumes:
|
||||
// - application/json
|
||||
//
|
||||
// Produces:
|
||||
// - application/json
|
||||
//
|
||||
// Responses:
|
||||
// 200: EvalQueriesResponse
|
||||
|
||||
// swagger:parameters RouteTestReceiverConfig
|
||||
type TestReceiverRequest struct {
|
||||
// in:body
|
||||
@@ -57,6 +73,18 @@ type TestRulePayload struct {
|
||||
GrafanaManagedCondition *models.EvalAlertConditionCommand `json:"grafana_condition,omitempty"`
|
||||
}
|
||||
|
||||
// swagger:parameters RouteEvalQueries
|
||||
type EvalQueriesRequest struct {
|
||||
// in:body
|
||||
Body EvalQueriesPayload
|
||||
}
|
||||
|
||||
// swagger:model
|
||||
type EvalQueriesPayload struct {
|
||||
Data []models.AlertQuery `json:"data"`
|
||||
Now time.Time `json:"now"`
|
||||
}
|
||||
|
||||
func (p *TestRulePayload) UnmarshalJSON(b []byte) error {
|
||||
type plain TestRulePayload
|
||||
if err := json.Unmarshal(b, (*plain)(p)); err != nil {
|
||||
@@ -96,6 +124,9 @@ type TestRuleResponse struct {
|
||||
GrafanaAlertInstances AlertInstancesResponse `json:"grafana_alert_instances"`
|
||||
}
|
||||
|
||||
// swagger:model
|
||||
type EvalQueriesResponse = backend.QueryDataResponse
|
||||
|
||||
// swagger:model
|
||||
type AlertInstancesResponse struct {
|
||||
// Instances is an array of arrow encoded dataframes
|
||||
|
||||
Reference in New Issue
Block a user