0a85a30642
The first version of the app platform apis for alerting rules, including AlertRule and RecordingRule definitions. Co-authored-by: William Wernert <william.wernert@grafana.com>
99 lines
9.1 KiB
Go
99 lines
9.1 KiB
Go
//
|
|
// This file is generated by grafana-app-sdk
|
|
// DO NOT EDIT
|
|
//
|
|
|
|
package apis
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
"strings"
|
|
|
|
"github.com/grafana/grafana-app-sdk/app"
|
|
"github.com/grafana/grafana-app-sdk/resource"
|
|
|
|
v0alpha1 "github.com/grafana/grafana/apps/alerting/rules/pkg/apis/alerting/v0alpha1"
|
|
)
|
|
|
|
var (
|
|
rawSchemaAlertRulev0alpha1 = []byte(`{"spec":{"properties":{"annotations":{"additionalProperties":{"type":"string"},"type":"object"},"data":{"additionalProperties":{"properties":{"datasourceUID":{"pattern":"^[a-zA-Z0-9_-]+$","type":"string"},"model":{},"queryType":{"type":"string"},"relativeTimeRange":{"properties":{"from":{"pattern":"^((([0-9]+)y)?(([0-9]+)w)?(([0-9]+)d)?(([0-9]+)h)?(([0-9]+)m)?(([0-9]+)s)?(([0-9]+)ms)?|0)$","type":"string"},"to":{"pattern":"^((([0-9]+)y)?(([0-9]+)w)?(([0-9]+)d)?(([0-9]+)h)?(([0-9]+)m)?(([0-9]+)s)?(([0-9]+)ms)?|0)$","type":"string"}},"required":["from","to"],"type":"object"},"source":{"type":"boolean"}},"required":["queryType","datasourceUID","model"],"type":"object"},"type":"object"},"execErrState":{"default":"Error","enum":["Error","Ok","Alerting","KeepLast"],"type":"string"},"for":{"allOf":[{"pattern":"^((([0-9]+)y)?(([0-9]+)w)?(([0-9]+)d)?(([0-9]+)h)?(([0-9]+)m)?(([0-9]+)s)?|0)$"},{"not":{"pattern":"hmuµn"}}],"type":"string"},"keepFiringFor":{"allOf":[{"pattern":"^((([0-9]+)y)?(([0-9]+)w)?(([0-9]+)d)?(([0-9]+)h)?(([0-9]+)m)?(([0-9]+)s)?|0)$"},{"not":{"pattern":"hmuµn"}}],"type":"string"},"labels":{"additionalProperties":{"type":"string"},"type":"object"},"missingSeriesEvalsToResolve":{"minimum":0,"type":"integer"},"noDataState":{"default":"NoData","enum":["NoData","Ok","Alerting","KeepLast"],"type":"string"},"notificationSettings":{"properties":{"activeTimeIntervals":{"items":{"type":"string"},"type":"array"},"groupBy":{"items":{"type":"string"},"type":"array"},"groupInterval":{"allOf":[{"pattern":"^((([0-9]+)y)?(([0-9]+)w)?(([0-9]+)d)?(([0-9]+)h)?(([0-9]+)m)?(([0-9]+)s)?|0)$"},{"not":{"pattern":"hmuµn"}}],"type":"string"},"groupWait":{"allOf":[{"pattern":"^((([0-9]+)y)?(([0-9]+)w)?(([0-9]+)d)?(([0-9]+)h)?(([0-9]+)m)?(([0-9]+)s)?|0)$"},{"not":{"pattern":"hmuµn"}}],"type":"string"},"muteTimeIntervals":{"items":{"type":"string"},"type":"array"},"receiver":{"type":"string"},"repeatInterval":{"allOf":[{"pattern":"^((([0-9]+)y)?(([0-9]+)w)?(([0-9]+)d)?(([0-9]+)h)?(([0-9]+)m)?(([0-9]+)s)?|0)$"},{"not":{"pattern":"hmuµn"}}],"type":"string"}},"required":["receiver"],"type":"object"},"panelRef":{"properties":{"dashboardUID":{"minLength":1,"pattern":"^[a-zA-Z0-9_-]+$","type":"string"},"panelID":{"exclusiveMinimum":true,"minimum":0,"type":"integer"}},"required":["dashboardUID","panelID"],"type":"object"},"paused":{"type":"boolean"},"title":{"type":"string"},"trigger":{"properties":{"interval":{"allOf":[{"pattern":"^((([0-9]+)y)?(([0-9]+)w)?(([0-9]+)d)?(([0-9]+)h)?(([0-9]+)m)?(([0-9]+)s)?|0)$"},{"not":{"pattern":"hmuµn"}}],"type":"string"}},"required":["interval"],"type":"object"}},"required":["title","data","trigger","noDataState","execErrState"],"type":"object","x-kubernetes-preserve-unknown-fields":true},"status":{"properties":{"additionalFields":{"description":"additionalFields is reserved for future use","type":"object","x-kubernetes-preserve-unknown-fields":true},"operatorStates":{"additionalProperties":{"properties":{"descriptiveState":{"description":"descriptiveState is an optional more descriptive state field which has no requirements on format","type":"string"},"details":{"description":"details contains any extra information that is operator-specific","type":"object","x-kubernetes-preserve-unknown-fields":true},"lastEvaluation":{"description":"lastEvaluation is the ResourceVersion last evaluated","type":"string"},"state":{"description":"state describes the state of the lastEvaluation.\nIt is limited to three possible states for machine evaluation.","enum":["success","in_progress","failed"],"type":"string"}},"required":["lastEvaluation","state"],"type":"object"},"description":"operatorStates is a map of operator ID to operator state evaluations.\nAny operator which consumes this kind SHOULD add its state evaluation information to this field.","type":"object"}},"type":"object"}}`)
|
|
versionSchemaAlertRulev0alpha1 app.VersionSchema
|
|
_ = json.Unmarshal(rawSchemaAlertRulev0alpha1, &versionSchemaAlertRulev0alpha1)
|
|
rawSchemaRecordingRulev0alpha1 = []byte(`{"spec":{"properties":{"data":{"additionalProperties":{"properties":{"datasourceUID":{"pattern":"^[a-zA-Z0-9_-]+$","type":"string"},"model":{},"queryType":{"type":"string"},"relativeTimeRange":{"properties":{"from":{"pattern":"^((([0-9]+)y)?(([0-9]+)w)?(([0-9]+)d)?(([0-9]+)h)?(([0-9]+)m)?(([0-9]+)s)?(([0-9]+)ms)?|0)$","type":"string"},"to":{"pattern":"^((([0-9]+)y)?(([0-9]+)w)?(([0-9]+)d)?(([0-9]+)h)?(([0-9]+)m)?(([0-9]+)s)?(([0-9]+)ms)?|0)$","type":"string"}},"required":["from","to"],"type":"object"},"source":{"type":"boolean"}},"required":["queryType","datasourceUID","model"],"type":"object"},"type":"object"},"labels":{"additionalProperties":{"type":"string"},"type":"object"},"metric":{"pattern":"^[a-zA-Z_:][a-zA-Z0-9_:]*$","type":"string"},"paused":{"type":"boolean"},"targetDatasourceUID":{"pattern":"^[a-zA-Z0-9_-]+$","type":"string"},"title":{"type":"string"},"trigger":{"properties":{"interval":{"allOf":[{"pattern":"^((([0-9]+)y)?(([0-9]+)w)?(([0-9]+)d)?(([0-9]+)h)?(([0-9]+)m)?(([0-9]+)s)?|0)$"},{"not":{"pattern":"hmuµn"}}],"type":"string"}},"required":["interval"],"type":"object"}},"required":["title","data","trigger","metric","targetDatasourceUID"],"type":"object","x-kubernetes-preserve-unknown-fields":true},"status":{"properties":{"additionalFields":{"description":"additionalFields is reserved for future use","type":"object","x-kubernetes-preserve-unknown-fields":true},"operatorStates":{"additionalProperties":{"properties":{"descriptiveState":{"description":"descriptiveState is an optional more descriptive state field which has no requirements on format","type":"string"},"details":{"description":"details contains any extra information that is operator-specific","type":"object","x-kubernetes-preserve-unknown-fields":true},"lastEvaluation":{"description":"lastEvaluation is the ResourceVersion last evaluated","type":"string"},"state":{"description":"state describes the state of the lastEvaluation.\nIt is limited to three possible states for machine evaluation.","enum":["success","in_progress","failed"],"type":"string"}},"required":["lastEvaluation","state"],"type":"object"},"description":"operatorStates is a map of operator ID to operator state evaluations.\nAny operator which consumes this kind SHOULD add its state evaluation information to this field.","type":"object"}},"type":"object"}}`)
|
|
versionSchemaRecordingRulev0alpha1 app.VersionSchema
|
|
_ = json.Unmarshal(rawSchemaRecordingRulev0alpha1, &versionSchemaRecordingRulev0alpha1)
|
|
)
|
|
|
|
var appManifestData = app.ManifestData{
|
|
AppName: "alerting",
|
|
Group: "rules.alerting.grafana.app",
|
|
Versions: []app.ManifestVersion{
|
|
{
|
|
Name: "v0alpha1",
|
|
Served: true,
|
|
Kinds: []app.ManifestVersionKind{
|
|
{
|
|
Kind: "AlertRule",
|
|
Plural: "AlertRules",
|
|
Scope: "Namespaced",
|
|
Conversion: false,
|
|
Schema: &versionSchemaAlertRulev0alpha1,
|
|
SelectableFields: []string{
|
|
"spec.title",
|
|
"spec.paused",
|
|
"spec.panelRef.dashboardUID",
|
|
"spec.panelRef.panelID",
|
|
"spec.notificationSettings.receiver",
|
|
},
|
|
},
|
|
|
|
{
|
|
Kind: "RecordingRule",
|
|
Plural: "RecordingRules",
|
|
Scope: "Namespaced",
|
|
Conversion: false,
|
|
Schema: &versionSchemaRecordingRulev0alpha1,
|
|
SelectableFields: []string{
|
|
"spec.title",
|
|
"spec.paused",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
}
|
|
|
|
func LocalManifest() app.Manifest {
|
|
return app.NewEmbeddedManifest(appManifestData)
|
|
}
|
|
|
|
func RemoteManifest() app.Manifest {
|
|
return app.NewAPIServerManifest("alerting")
|
|
}
|
|
|
|
var kindVersionToGoType = map[string]resource.Kind{
|
|
"AlertRule/v0alpha1": v0alpha1.AlertRuleKind(),
|
|
"RecordingRule/v0alpha1": v0alpha1.RecordingRuleKind(),
|
|
}
|
|
|
|
// ManifestGoTypeAssociator returns the associated resource.Kind instance for a given Kind and Version, if one exists.
|
|
// If there is no association for the provided Kind and Version, exists will return false.
|
|
func ManifestGoTypeAssociator(kind, version string) (goType resource.Kind, exists bool) {
|
|
goType, exists = kindVersionToGoType[fmt.Sprintf("%s/%s", kind, version)]
|
|
return goType, exists
|
|
}
|
|
|
|
var customRouteToGoResponseType = map[string]any{}
|
|
|
|
// 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.
|
|
// If there is no association for the provided kind, version, custom route path, and method, exists will return false.
|
|
func ManifestCustomRouteResponsesAssociator(kind, version, path, verb string) (goType any, exists bool) {
|
|
if len(path) > 0 && path[0] == '/' {
|
|
path = path[1:]
|
|
}
|
|
goType, exists = customRouteToGoResponseType[fmt.Sprintf("%s|%s|%s|%s", version, kind, path, strings.ToUpper(verb))]
|
|
return goType, exists
|
|
}
|