fully bring in the type for target
This commit is contained in:
@@ -1,10 +1,18 @@
|
||||
include ../sdk.mk
|
||||
|
||||
.PHONY: generate # Run Grafana App SDK code generation
|
||||
generate: install-app-sdk update-app-sdk
|
||||
generate: do-generate post-generate-cleanup
|
||||
|
||||
.PHONY: do-generate
|
||||
do-generate: install-app-sdk update-app-sdk
|
||||
@$(APP_SDK_BIN) generate \
|
||||
--source=./kinds/ \
|
||||
--gogenpath=./pkg/apis \
|
||||
--grouping=group \
|
||||
--genoperatorstate=false \
|
||||
--defencoding=none
|
||||
--defencoding=none
|
||||
|
||||
.PHONY: post-generate-cleanup
|
||||
post-generate-cleanup: ## Fix TargetSpec OpenAPI schema
|
||||
# Fix the TargetSpec schema in manifest - remove nested additionalProperties
|
||||
@sed -i.bak 's|"TargetSpec":{"additionalProperties":{"additionalProperties":{},"type":"object"},"type":"object"}|"TargetSpec":{"additionalProperties":{},"type":"object"}|g' ./pkg/apis/correlation_manifest.go && rm ./pkg/apis/correlation_manifest.go.bak
|
||||
@@ -32,10 +32,9 @@ ConfigSpec: {
|
||||
}
|
||||
|
||||
TargetSpec: {
|
||||
test: string
|
||||
...
|
||||
}
|
||||
|
||||
|
||||
TransformationSpec: {
|
||||
type: "regex" | "logfmt"
|
||||
expression: string
|
||||
|
||||
@@ -33,20 +33,11 @@ type CorrelationConfigSpec struct {
|
||||
|
||||
// NewCorrelationConfigSpec creates a new CorrelationConfigSpec object.
|
||||
func NewCorrelationConfigSpec() *CorrelationConfigSpec {
|
||||
return &CorrelationConfigSpec{
|
||||
Target: *NewCorrelationTargetSpec(),
|
||||
}
|
||||
return &CorrelationConfigSpec{}
|
||||
}
|
||||
|
||||
// +k8s:openapi-gen=true
|
||||
type CorrelationTargetSpec struct {
|
||||
Test string `json:"test"`
|
||||
}
|
||||
|
||||
// NewCorrelationTargetSpec creates a new CorrelationTargetSpec object.
|
||||
func NewCorrelationTargetSpec() *CorrelationTargetSpec {
|
||||
return &CorrelationTargetSpec{}
|
||||
}
|
||||
type CorrelationTargetSpec map[string]interface{}
|
||||
|
||||
// +k8s:openapi-gen=true
|
||||
type CorrelationTransformationSpec struct {
|
||||
|
||||
+1
-1
@@ -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":false,"properties":{"test":{"type":"string"}},"required":["test"],"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"}}`)
|
||||
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":{},"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)
|
||||
)
|
||||
|
||||
+2
-6
@@ -31,13 +31,9 @@ export const defaultConfigSpec = (): ConfigSpec => ({
|
||||
target: defaultTargetSpec(),
|
||||
});
|
||||
|
||||
export interface TargetSpec {
|
||||
test: string;
|
||||
}
|
||||
export type TargetSpec = Record<string, any>;
|
||||
|
||||
export const defaultTargetSpec = (): TargetSpec => ({
|
||||
test: "",
|
||||
});
|
||||
export const defaultTargetSpec = (): TargetSpec => ({});
|
||||
|
||||
export interface TransformationSpec {
|
||||
type: "regex" | "logfmt";
|
||||
|
||||
+1
-3
@@ -408,9 +408,7 @@ export type ObjectMeta = {
|
||||
uid?: string;
|
||||
};
|
||||
export type CorrelationTargetSpec = {
|
||||
[key: string]: {
|
||||
[key: string]: any;
|
||||
};
|
||||
[key: string]: any;
|
||||
};
|
||||
export type CorrelationTransformationSpec = {
|
||||
expression: string;
|
||||
|
||||
@@ -88,8 +88,8 @@ func ToSpecConfig(orig CorrelationConfig) (*correlationsV0.CorrelationConfigSpec
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(out.Target.Test) == 0 {
|
||||
out.Target.Test = "hi"
|
||||
if len(out.Target) == 0 {
|
||||
out.Target = map[string]any{}
|
||||
}
|
||||
return out, err
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -100,7 +100,7 @@ const toEnrichedCorrelationDataK8s = (item: CorrelationK8s): CorrelationData | u
|
||||
sourceUID: item.spec.source.name, //todo
|
||||
label: item.spec.label,
|
||||
description: item.spec.description,
|
||||
provisioned: false, // todo
|
||||
provisioned: false, // todo,
|
||||
};
|
||||
|
||||
if (item.spec.type === 'external') {
|
||||
@@ -110,7 +110,7 @@ const toEnrichedCorrelationDataK8s = (item: CorrelationK8s): CorrelationData | u
|
||||
config: {
|
||||
field: item.spec.config.field,
|
||||
target: {
|
||||
url: item.spec.config.target.url.url || '', // todo this is wrong, fix in spec
|
||||
url: item.spec.config.target.url || '',
|
||||
},
|
||||
transformations: [], // todo fix
|
||||
},
|
||||
@@ -123,7 +123,7 @@ const toEnrichedCorrelationDataK8s = (item: CorrelationK8s): CorrelationData | u
|
||||
targetUID: item.spec.target?.name || '', // todo
|
||||
config: {
|
||||
field: item.spec.config.field,
|
||||
target: item.spec.config.target, // todo
|
||||
target: item.spec.config.target,
|
||||
transformations: [], // todo fix
|
||||
},
|
||||
};
|
||||
@@ -187,14 +187,6 @@ export const useCorrelations = () => {
|
||||
const [createInfo, create] = useAsyncFn<(params: CreateCorrelationParams) => Promise<CorrelationData>>(
|
||||
async ({ sourceUID, ...correlation }) => {
|
||||
if (config.featureToggles.kubernetesCorrelations) {
|
||||
// todo, fix once target is fixed
|
||||
let target;
|
||||
if (correlation.type === 'external') {
|
||||
target = { url: { url: correlation.config.target.url } };
|
||||
} else {
|
||||
target = { target: { ...correlation.config.target } };
|
||||
}
|
||||
|
||||
const result = await dispatch(
|
||||
correlationAPIv0alpha1.endpoints.createCorrelation.initiate({
|
||||
correlation: {
|
||||
@@ -205,7 +197,7 @@ export const useCorrelations = () => {
|
||||
...correlation,
|
||||
label: correlation.label ?? '',
|
||||
source: { name: sourceUID, group: '' },
|
||||
config: { ...correlation.config, target: target, transformations: [] },
|
||||
config: { ...correlation.config, transformations: [] },
|
||||
},
|
||||
},
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user