define a custom route for receiver testing

This commit is contained in:
Yuri Tseretyan
2026-01-05 12:47:21 -05:00
parent c723526f4e
commit d4e94cef50
6 changed files with 440 additions and 6 deletions
@@ -430,4 +430,100 @@ spec:
type: object
scope: Namespaced
name: v0alpha1
routes:
namespaced:
/testing/integration:
get:
operationId: getIntegrationTest
requestBody:
content:
application/json:
schema:
additionalProperties: false
properties:
alert:
$ref: '#/components/schemas/getIntegrationTestAlert'
integration:
$ref: '#/components/schemas/getIntegrationTestIntegration'
receiver_ref:
type: string
required:
- alert
- integration
type: object
required: true
responses:
default:
content:
application/json:
schema:
additionalProperties: false
properties:
apiVersion:
description: 'APIVersion defines the versioned schema of
this representation of an object. Servers should convert
recognized schemas to the latest internal value, and may
reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources'
type: string
duration:
type: string
error:
type: string
kind:
description: 'Kind is a string value representing the REST
resource this object represents. Servers may infer this
from the endpoint the client submits requests to. Cannot
be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds'
type: string
timestamp:
format: date-time
type: string
required:
- timestamp
- duration
- apiVersion
- kind
type: object
description: Default OK response
schemas:
getIntegrationTestAlert:
additionalProperties: false
properties:
annotations:
additionalProperties:
type: string
type: object
labels:
additionalProperties:
type: string
type: object
required:
- labels
- annotations
type: object
getIntegrationTestIntegration:
additionalProperties: false
properties:
disableResolveMessage:
type: boolean
secureFields:
additionalProperties:
type: boolean
type: object
settings:
additionalProperties:
additionalProperties: {}
type: object
type: object
type:
type: string
uid:
type: string
version:
type: string
required:
- type
- version
- settings
type: object
served: true
+36 -1
View File
@@ -1,5 +1,19 @@
package kinds
import (
"time",
"github.com/grafana/grafana/apps/alerting/notifications/kinds/v0alpha1"
)
#Alert: {
labels: {
[string]: string
}
annotations: {
[string]: string
}
}
manifest: {
appName: "alerting-notifications"
groupOverride: "notifications.alerting.grafana.app"
@@ -14,7 +28,28 @@ manifest: {
routeTreev0alpha1,
templatev0alpha1,
timeIntervalv0alpha1,
]
],
routes: {
namespaced: {
"/testing/integration" : {
"GET": {
name: "getIntegrationTest"
request: {
body: {
alert: #Alert
receiver_ref?: string
integration: v0alpha1.#Integration
}
}
response: {
timestamp: time.Time
duration: string
error?: string
}
}
}
}
},
}
}
}
@@ -0,0 +1,46 @@
// Code generated - EDITING IS FUTILE. DO NOT EDIT.
package v0alpha1
type GetIntegrationTestRequestAlert struct {
Labels map[string]string `json:"labels"`
Annotations map[string]string `json:"annotations"`
}
// NewGetIntegrationTestRequestAlert creates a new GetIntegrationTestRequestAlert object.
func NewGetIntegrationTestRequestAlert() *GetIntegrationTestRequestAlert {
return &GetIntegrationTestRequestAlert{
Labels: map[string]string{},
Annotations: map[string]string{},
}
}
type GetIntegrationTestRequestIntegration struct {
Uid *string `json:"uid,omitempty"`
Type string `json:"type"`
Version string `json:"version"`
DisableResolveMessage *bool `json:"disableResolveMessage,omitempty"`
Settings map[string]any `json:"settings"`
SecureFields map[string]bool `json:"secureFields,omitempty"`
}
// NewGetIntegrationTestRequestIntegration creates a new GetIntegrationTestRequestIntegration object.
func NewGetIntegrationTestRequestIntegration() *GetIntegrationTestRequestIntegration {
return &GetIntegrationTestRequestIntegration{
Settings: map[string]any{},
}
}
type GetIntegrationTestRequestBody struct {
Alert GetIntegrationTestRequestAlert `json:"alert"`
ReceiverRef *string `json:"receiver_ref,omitempty"`
Integration GetIntegrationTestRequestIntegration `json:"integration"`
}
// NewGetIntegrationTestRequestBody creates a new GetIntegrationTestRequestBody object.
func NewGetIntegrationTestRequestBody() *GetIntegrationTestRequestBody {
return &GetIntegrationTestRequestBody{
Alert: *NewGetIntegrationTestRequestAlert(),
Integration: *NewGetIntegrationTestRequestIntegration(),
}
}
@@ -0,0 +1,19 @@
// Code generated - EDITING IS FUTILE. DO NOT EDIT.
package v0alpha1
import (
time "time"
)
// +k8s:openapi-gen=true
type GetIntegrationTestBody struct {
Timestamp time.Time `json:"timestamp"`
Duration string `json:"duration"`
Error *string `json:"error,omitempty"`
}
// NewGetIntegrationTestBody creates a new GetIntegrationTestBody object.
func NewGetIntegrationTestBody() *GetIntegrationTestBody {
return &GetIntegrationTestBody{}
}
@@ -0,0 +1,37 @@
// Code generated - EDITING IS FUTILE. DO NOT EDIT.
package v0alpha1
import (
"github.com/grafana/grafana-app-sdk/resource"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
)
// +k8s:openapi-gen=true
type GetIntegrationTest struct {
metav1.TypeMeta `json:",inline"`
GetIntegrationTestBody `json:",inline"`
}
func NewGetIntegrationTest() *GetIntegrationTest {
return &GetIntegrationTest{}
}
func (t *GetIntegrationTestBody) DeepCopyInto(dst *GetIntegrationTestBody) {
_ = resource.CopyObjectInto(dst, t)
}
func (o *GetIntegrationTest) DeepCopyObject() runtime.Object {
dst := NewGetIntegrationTest()
o.DeepCopyInto(dst)
return dst
}
func (o *GetIntegrationTest) DeepCopyInto(dst *GetIntegrationTest) {
dst.TypeMeta.APIVersion = o.TypeMeta.APIVersion
dst.TypeMeta.Kind = o.TypeMeta.Kind
o.GetIntegrationTestBody.DeepCopyInto(&dst.GetIntegrationTestBody)
}
var _ runtime.Object = NewGetIntegrationTest()
@@ -79,9 +79,206 @@ var appManifestData = app.ManifestData{
},
},
Routes: app.ManifestVersionRoutes{
Namespaced: map[string]spec3.PathProps{},
Cluster: map[string]spec3.PathProps{},
Schemas: map[string]spec.Schema{},
Namespaced: map[string]spec3.PathProps{
"/testing/integration": {
Get: &spec3.Operation{
OperationProps: spec3.OperationProps{
OperationId: "getIntegrationTest",
RequestBody: &spec3.RequestBody{
RequestBodyProps: spec3.RequestBodyProps{
Required: true,
Content: map[string]*spec3.MediaType{
"application/json": {
MediaTypeProps: spec3.MediaTypeProps{
Schema: &spec.Schema{
SchemaProps: spec.SchemaProps{
Type: []string{"object"},
Properties: map[string]spec.Schema{
"alert": {
SchemaProps: spec.SchemaProps{
Ref: spec.MustCreateRef("#/components/schemas/getIntegrationTestAlert"),
},
},
"integration": {
SchemaProps: spec.SchemaProps{
Ref: spec.MustCreateRef("#/components/schemas/getIntegrationTestIntegration"),
},
},
"receiver_ref": {
SchemaProps: spec.SchemaProps{
Type: []string{"string"},
},
},
},
Required: []string{
"alert",
"integration",
},
}},
}},
},
}},
Responses: &spec3.Responses{
ResponsesProps: spec3.ResponsesProps{
Default: &spec3.Response{
ResponseProps: spec3.ResponseProps{
Description: "Default OK response",
Content: map[string]*spec3.MediaType{
"application/json": {
MediaTypeProps: spec3.MediaTypeProps{
Schema: &spec.Schema{
SchemaProps: spec.SchemaProps{
Type: []string{"object"},
Properties: map[string]spec.Schema{
"apiVersion": {
SchemaProps: spec.SchemaProps{
Type: []string{"string"},
Description: "APIVersion defines the versioned schema of this representation of an object. Servers should convert recognized schemas to the latest internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources",
},
},
"duration": {
SchemaProps: spec.SchemaProps{
Type: []string{"string"},
},
},
"error": {
SchemaProps: spec.SchemaProps{
Type: []string{"string"},
},
},
"kind": {
SchemaProps: spec.SchemaProps{
Type: []string{"string"},
Description: "Kind is a string value representing the REST resource this object represents. Servers may infer this from the endpoint the client submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds",
},
},
"timestamp": {
SchemaProps: spec.SchemaProps{
Type: []string{"string"},
Format: "date-time",
},
},
},
Required: []string{
"timestamp",
"duration",
"apiVersion",
"kind",
},
}},
}},
},
},
},
}},
},
},
},
},
Cluster: map[string]spec3.PathProps{},
Schemas: map[string]spec.Schema{
"getIntegrationTestAlert": {
SchemaProps: spec.SchemaProps{
Type: []string{"object"},
Properties: map[string]spec.Schema{
"annotations": {
SchemaProps: spec.SchemaProps{
Type: []string{"object"},
AdditionalProperties: &spec.SchemaOrBool{
Schema: &spec.Schema{
SchemaProps: spec.SchemaProps{
Type: []string{"string"},
},
},
},
},
},
"labels": {
SchemaProps: spec.SchemaProps{
Type: []string{"object"},
AdditionalProperties: &spec.SchemaOrBool{
Schema: &spec.Schema{
SchemaProps: spec.SchemaProps{
Type: []string{"string"},
},
},
},
},
},
},
Required: []string{
"labels",
"annotations",
},
},
},
"getIntegrationTestIntegration": {
SchemaProps: spec.SchemaProps{
Type: []string{"object"},
Properties: map[string]spec.Schema{
"disableResolveMessage": {
SchemaProps: spec.SchemaProps{
Type: []string{"boolean"},
},
},
"secureFields": {
SchemaProps: spec.SchemaProps{
Type: []string{"object"},
AdditionalProperties: &spec.SchemaOrBool{
Schema: &spec.Schema{
SchemaProps: spec.SchemaProps{
Type: []string{"boolean"},
},
},
},
},
},
"settings": {
SchemaProps: spec.SchemaProps{
Type: []string{"object"},
AdditionalProperties: &spec.SchemaOrBool{
Schema: &spec.Schema{
SchemaProps: spec.SchemaProps{
Type: []string{"object"},
AdditionalProperties: &spec.SchemaOrBool{
Schema: &spec.Schema{
SchemaProps: spec.SchemaProps{},
},
},
},
},
},
},
},
"type": {
SchemaProps: spec.SchemaProps{
Type: []string{"string"},
},
},
"uid": {
SchemaProps: spec.SchemaProps{
Type: []string{"string"},
},
},
"version": {
SchemaProps: spec.SchemaProps{
Type: []string{"string"},
},
},
},
Required: []string{
"type",
"version",
"settings",
},
},
},
},
},
},
},
@@ -109,7 +306,9 @@ func ManifestGoTypeAssociator(kind, version string) (goType resource.Kind, exist
return goType, exists
}
var customRouteToGoResponseType = map[string]any{}
var customRouteToGoResponseType = map[string]any{
"v0alpha1||<namespace>/testing/integration|GET": v0alpha1.GetIntegrationTest{},
}
// ManifestCustomRouteResponsesAssociator returns the associated response go type for a given kind, version, custom route path, and method, if one exists.
// kind may be empty for custom routes which are not kind subroutes. Leading slashes are removed from subroute paths.
@@ -133,7 +332,9 @@ func ManifestCustomRouteQueryAssociator(kind, version, path, verb string) (goTyp
return goType, exists
}
var customRouteToGoRequestBodyType = map[string]any{}
var customRouteToGoRequestBodyType = map[string]any{
"v0alpha1||<namespace>/testing/integration|GET": v0alpha1.GetIntegrationTestRequestBody{},
}
func ManifestCustomRouteRequestBodyAssociator(kind, version, path, verb string) (goType any, exists bool) {
if len(path) > 0 && path[0] == '/' {