do ds lookup instead of trusting the uid
This commit is contained in:
@@ -4,51 +4,62 @@ import {
|
||||
useListCorrelationQuery,
|
||||
} from '@grafana/api-clients/rtkq/correlations/v0alpha1';
|
||||
import { SupportedTransformationType } from '@grafana/data';
|
||||
import { CorrelationData, CorrelationExternal, CorrelationQuery } from '@grafana/runtime';
|
||||
import { CorrelationData, CorrelationExternal, CorrelationQuery, getDataSourceSrv } from '@grafana/runtime';
|
||||
|
||||
import { toEnrichedCorrelationData } from './useCorrelations';
|
||||
|
||||
export const toEnrichedCorrelationDataK8s = (item: CorrelationK8s): CorrelationData | undefined => {
|
||||
const baseCor = {
|
||||
uid: item.metadata.name!,
|
||||
sourceUID: item.spec.source.name, //todo
|
||||
label: item.spec.label,
|
||||
description: item.spec.description,
|
||||
provisioned: false, // todo
|
||||
};
|
||||
|
||||
const transformationsFmt = item.spec.config.transformations?.map((trans) => {
|
||||
return {
|
||||
...trans,
|
||||
type: trans.type === 'regex' ? SupportedTransformationType.Regex : SupportedTransformationType.Logfmt,
|
||||
const dsSrv = getDataSourceSrv();
|
||||
const sourceDS = dsSrv.getInstanceSettings({ type: item.spec.source.group, uid: item.spec.source.name });
|
||||
if (sourceDS !== undefined) {
|
||||
const baseCor = {
|
||||
uid: item.metadata.name!,
|
||||
sourceUID: sourceDS.uid,
|
||||
label: item.spec.label,
|
||||
description: item.spec.description,
|
||||
provisioned: false, // todo
|
||||
};
|
||||
});
|
||||
|
||||
if (item.spec.type === 'external') {
|
||||
const extCorr: CorrelationExternal = {
|
||||
...baseCor,
|
||||
type: 'external',
|
||||
config: {
|
||||
field: item.spec.config.field,
|
||||
target: {
|
||||
url: item.spec.config?.target?.url || '',
|
||||
const transformationsFmt = item.spec.config.transformations?.map((trans) => {
|
||||
return {
|
||||
...trans,
|
||||
type: trans.type === 'regex' ? SupportedTransformationType.Regex : SupportedTransformationType.Logfmt,
|
||||
};
|
||||
});
|
||||
|
||||
if (item.spec.type === 'external') {
|
||||
const extCorr: CorrelationExternal = {
|
||||
...baseCor,
|
||||
type: 'external',
|
||||
config: {
|
||||
field: item.spec.config.field,
|
||||
target: {
|
||||
url: item.spec.config?.target?.url || '',
|
||||
},
|
||||
transformations: transformationsFmt,
|
||||
},
|
||||
transformations: transformationsFmt,
|
||||
},
|
||||
};
|
||||
return toEnrichedCorrelationData(extCorr);
|
||||
};
|
||||
return toEnrichedCorrelationData(extCorr);
|
||||
} else {
|
||||
const targetDs = dsSrv.getInstanceSettings({ type: item.spec.target?.group, uid: item.spec.target?.name });
|
||||
if (targetDs !== undefined) {
|
||||
const queryCorr: CorrelationQuery = {
|
||||
...baseCor,
|
||||
type: 'query',
|
||||
targetUID: targetDs.uid,
|
||||
config: {
|
||||
field: item.spec.config.field,
|
||||
target: item.spec.config.target,
|
||||
transformations: transformationsFmt,
|
||||
},
|
||||
};
|
||||
return toEnrichedCorrelationData(queryCorr);
|
||||
} else {
|
||||
return undefined;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
const queryCorr: CorrelationQuery = {
|
||||
...baseCor,
|
||||
type: 'query',
|
||||
targetUID: item.spec.target?.name || '', // todo
|
||||
config: {
|
||||
field: item.spec.config.field,
|
||||
target: item.spec.config.target,
|
||||
transformations: transformationsFmt,
|
||||
},
|
||||
};
|
||||
return toEnrichedCorrelationData(queryCorr);
|
||||
return undefined;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user