Correlations: Add legacy storage (#112038)

This commit is contained in:
Ryan McKinley
2025-10-16 21:13:39 +03:00
committed by GitHub
parent bb08b2deea
commit bea45a94f0
17 changed files with 738 additions and 77 deletions
+9 -7
View File
@@ -5,15 +5,17 @@ correlationsv0alpha1: {
pluralName: "Correlations"
schema: {
spec: {
source_ds_ref: DataSourceRef
target_ds_ref?: DataSourceRef
label: string
type: CorrelationType
source: DataSourceRef
target?: DataSourceRef
description?: string
config: ConfigSpec
provisioned: bool
type: CorrelationType
label: string
config: ConfigSpec
}
}
selectableFields: [
"spec.datasource.name"
]
}
DataSourceRef: {
@@ -32,7 +34,7 @@ ConfigSpec: {
TargetSpec: [string]: _
TransformationSpec: {
type: string
type: "regex" | "logfmt"
expression: string
field: string
mapValue: string
@@ -2,6 +2,14 @@
package v0alpha1
// +k8s:openapi-gen=true
type CorrelationCorrelationType string
const (
CorrelationCorrelationTypeQuery CorrelationCorrelationType = "query"
CorrelationCorrelationTypeExternal CorrelationCorrelationType = "external"
)
// +k8s:openapi-gen=true
type CorrelationDataSourceRef struct {
// same as pluginId
@@ -33,10 +41,10 @@ type CorrelationTargetSpec map[string]interface{}
// +k8s:openapi-gen=true
type CorrelationTransformationSpec struct {
Type string `json:"type"`
Expression string `json:"expression"`
Field string `json:"field"`
MapValue string `json:"mapValue"`
Type CorrelationTransformationSpecType `json:"type"`
Expression string `json:"expression"`
Field string `json:"field"`
MapValue string `json:"mapValue"`
}
// NewCorrelationTransformationSpec creates a new CorrelationTransformationSpec object.
@@ -44,29 +52,28 @@ func NewCorrelationTransformationSpec() *CorrelationTransformationSpec {
return &CorrelationTransformationSpec{}
}
// +k8s:openapi-gen=true
type CorrelationCorrelationType string
const (
CorrelationCorrelationTypeQuery CorrelationCorrelationType = "query"
CorrelationCorrelationTypeExternal CorrelationCorrelationType = "external"
)
// +k8s:openapi-gen=true
type CorrelationSpec struct {
SourceDsRef CorrelationDataSourceRef `json:"source_ds_ref"`
TargetDsRef *CorrelationDataSourceRef `json:"target_ds_ref,omitempty"`
Label string `json:"label"`
Description *string `json:"description,omitempty"`
Config CorrelationConfigSpec `json:"config"`
Provisioned bool `json:"provisioned"`
Type CorrelationCorrelationType `json:"type"`
Source CorrelationDataSourceRef `json:"source"`
Target *CorrelationDataSourceRef `json:"target,omitempty"`
Description *string `json:"description,omitempty"`
Label string `json:"label"`
Config CorrelationConfigSpec `json:"config"`
}
// NewCorrelationSpec creates a new CorrelationSpec object.
func NewCorrelationSpec() *CorrelationSpec {
return &CorrelationSpec{
SourceDsRef: *NewCorrelationDataSourceRef(),
Config: *NewCorrelationConfigSpec(),
Source: *NewCorrelationDataSourceRef(),
Config: *NewCorrelationConfigSpec(),
}
}
// +k8s:openapi-gen=true
type CorrelationTransformationSpecType string
const (
CorrelationTransformationSpecTypeRegex CorrelationTransformationSpecType = "regex"
CorrelationTransformationSpecTypeLogfmt CorrelationTransformationSpecType = "logfmt"
)
@@ -20,7 +20,7 @@ import (
)
var (
rawSchemaCorrelationv0alpha1 = []byte(`{"ConfigSpec":{"additionalProperties":false,"description":"there was a deprecated field here called type, we will need to move that for conversion and provisioning","properties":{"field":{"type":"string"},"target":{"$ref":"#/components/schemas/TargetSpec"},"transformations":{"items":{"$ref":"#/components/schemas/TransformationSpec"},"type":"array"}},"required":["field","target"],"type":"object"},"Correlation":{"properties":{"spec":{"$ref":"#/components/schemas/spec"}},"required":["spec"]},"CorrelationType":{"enum":["query","external"],"type":"string"},"DataSourceRef":{"additionalProperties":false,"properties":{"group":{"description":"same as pluginId","type":"string"},"name":{"description":"same as grafana uid","type":"string"}},"required":["group","name"],"type":"object"},"TargetSpec":{"additionalProperties":{"additionalProperties":{},"type":"object"},"type":"object"},"TransformationSpec":{"additionalProperties":false,"properties":{"expression":{"type":"string"},"field":{"type":"string"},"mapValue":{"type":"string"},"type":{"type":"string"}},"required":["type","expression","field","mapValue"],"type":"object"},"spec":{"additionalProperties":false,"properties":{"config":{"$ref":"#/components/schemas/ConfigSpec"},"description":{"type":"string"},"label":{"type":"string"},"provisioned":{"type":"boolean"},"source_ds_ref":{"$ref":"#/components/schemas/DataSourceRef"},"target_ds_ref":{"$ref":"#/components/schemas/DataSourceRef"},"type":{"$ref":"#/components/schemas/CorrelationType"}},"required":["source_ds_ref","label","config","provisioned","type"],"type":"object"}}`)
rawSchemaCorrelationv0alpha1 = []byte(`{"ConfigSpec":{"additionalProperties":false,"description":"there was a deprecated field here called type, we will need to move that for conversion and provisioning","properties":{"field":{"type":"string"},"target":{"$ref":"#/components/schemas/TargetSpec"},"transformations":{"items":{"$ref":"#/components/schemas/TransformationSpec"},"type":"array"}},"required":["field","target"],"type":"object"},"Correlation":{"properties":{"spec":{"$ref":"#/components/schemas/spec"}},"required":["spec"]},"CorrelationType":{"enum":["query","external"],"type":"string"},"DataSourceRef":{"additionalProperties":false,"properties":{"group":{"description":"same as pluginId","type":"string"},"name":{"description":"same as grafana uid","type":"string"}},"required":["group","name"],"type":"object"},"TargetSpec":{"additionalProperties":{"additionalProperties":{},"type":"object"},"type":"object"},"TransformationSpec":{"additionalProperties":false,"properties":{"expression":{"type":"string"},"field":{"type":"string"},"mapValue":{"type":"string"},"type":{"enum":["regex","logfmt"],"type":"string"}},"required":["type","expression","field","mapValue"],"type":"object"},"spec":{"additionalProperties":false,"properties":{"config":{"$ref":"#/components/schemas/ConfigSpec"},"description":{"type":"string"},"label":{"type":"string"},"source":{"$ref":"#/components/schemas/DataSourceRef"},"target":{"$ref":"#/components/schemas/DataSourceRef"},"type":{"$ref":"#/components/schemas/CorrelationType"}},"required":["type","source","label","config"],"type":"object"}}`)
versionSchemaCorrelationv0alpha1 app.VersionSchema
_ = json.Unmarshal(rawSchemaCorrelationv0alpha1, &versionSchemaCorrelationv0alpha1)
)
@@ -40,6 +40,9 @@ var appManifestData = app.ManifestData{
Scope: "Namespaced",
Conversion: false,
Schema: &versionSchemaCorrelationv0alpha1,
SelectableFields: []string{
"spec.datasource.name",
},
},
},
Routes: app.ManifestVersionRoutes{
@@ -1,5 +1,12 @@
// Code generated - EDITING IS FUTILE. DO NOT EDIT.
export enum CorrelationType {
Query = "query",
External = "external",
}
export const defaultCorrelationType = (): CorrelationType => (CorrelationType.Query);
export interface DataSourceRef {
// same as pluginId
group: string;
@@ -29,41 +36,32 @@ export type TargetSpec = Record<string, any>;
export const defaultTargetSpec = (): TargetSpec => ({});
export interface TransformationSpec {
type: string;
type: "regex" | "logfmt";
expression: string;
field: string;
mapValue: string;
}
export const defaultTransformationSpec = (): TransformationSpec => ({
type: "",
type: "regex",
expression: "",
field: "",
mapValue: "",
});
export enum CorrelationType {
Query = "query",
External = "external",
}
export const defaultCorrelationType = (): CorrelationType => (CorrelationType.Query);
export interface Spec {
source_ds_ref: DataSourceRef;
target_ds_ref?: DataSourceRef;
label: string;
description?: string;
config: ConfigSpec;
provisioned: boolean;
type: CorrelationType;
source: DataSourceRef;
target?: DataSourceRef;
description?: string;
label: string;
config: ConfigSpec;
}
export const defaultSpec = (): Spec => ({
source_ds_ref: defaultDataSourceRef(),
type: CorrelationType.Query,
source: defaultDataSourceRef(),
label: "",
config: defaultConfigSpec(),
provisioned: false,
type: CorrelationType.Query,
});