Correlations: Add error logging (#78272)

* Add error logging when parsing correlations

* Make orgId optional

* Add module property and move source and target to context for better readability
This commit is contained in:
Piotr Jamróz 2023-12-01 20:26:05 +01:00 committed by GitHub
parent 58d0c51cf4
commit b64802ed3b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 1 deletions

View File

@ -42,6 +42,7 @@ export interface Correlation {
label?: string;
description?: string;
provisioned: boolean;
orgId?: number;
config: CorrelationConfig;
}

View File

@ -2,7 +2,7 @@ import { useAsyncFn } from 'react-use';
import { lastValueFrom } from 'rxjs';
import { DataSourceInstanceSettings } from '@grafana/data';
import { getDataSourceSrv, FetchResponse } from '@grafana/runtime';
import { getDataSourceSrv, FetchResponse, logWarning } from '@grafana/runtime';
import { useGrafana } from 'app/core/context/GrafanaContext';
import {
@ -43,6 +43,13 @@ const toEnrichedCorrelationData = ({
const sourceDatasource = getDataSourceSrv().getInstanceSettings(sourceUID);
const targetDatasource = getDataSourceSrv().getInstanceSettings(targetUID);
// According to #72258 we will remove logic to handle orgId=0/null as global correlations.
// This logging is to check if there are any customers who did not migrate existing correlations.
// See Deprecation Notice in https://github.com/grafana/grafana/pull/72258 for more details
if (correlation?.orgId === undefined || correlation?.orgId === null || correlation?.orgId === 0) {
logWarning('Invalid correlation config: Missing org id.', { module: 'Explore' });
}
if (
sourceDatasource &&
sourceDatasource?.uid !== undefined &&
@ -55,6 +62,11 @@ const toEnrichedCorrelationData = ({
target: targetDatasource,
};
} else {
logWarning(`Invalid correlation config: Missing source or target.`, {
module: 'Explore',
source: JSON.stringify(sourceDatasource),
target: JSON.stringify(targetDatasource),
});
return undefined;
}
};