From b727586dd76132998b97689b5953555b17dcc1ab Mon Sep 17 00:00:00 2001 From: Kristina Durivage Date: Tue, 13 Jan 2026 21:07:17 -0600 Subject: [PATCH] do ds lookup instead of trusting the uid --- .../correlations/useCorrelationsK8s.ts | 85 +++++++++++-------- 1 file changed, 48 insertions(+), 37 deletions(-) diff --git a/public/app/features/correlations/useCorrelationsK8s.ts b/public/app/features/correlations/useCorrelationsK8s.ts index f78a972ba0e..452b54c3078 100644 --- a/public/app/features/correlations/useCorrelationsK8s.ts +++ b/public/app/features/correlations/useCorrelationsK8s.ts @@ -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; } };