Datasources: Extend properties for the datasource-test tracking event (#62292)

chore: extend properties for the test datasource tracking event
This commit is contained in:
Levente Balogh
2023-01-30 08:29:13 +01:00
committed by GitHub
parent 0d2a786816
commit 9b2abe7613
4 changed files with 13 additions and 4 deletions

View File

@@ -72,7 +72,7 @@ const failDataSourceTest = async (error: object) => {
};
const dispatchedActions = await thunkTester(state)
.givenThunk(testDataSource)
.whenThunkIsDispatched('Azure Monitor', dependencies);
.whenThunkIsDispatched('Azure Monitor', DATASOURCES_ROUTES.Edit, dependencies);
return dispatchedActions;
};
@@ -234,7 +234,7 @@ describe('testDataSource', () => {
};
const dispatchedActions = await thunkTester(state)
.givenThunk(testDataSource)
.whenThunkIsDispatched('CloudWatch', dependencies);
.whenThunkIsDispatched('CloudWatch', DATASOURCES_ROUTES.Edit, dependencies);
expect(dispatchedActions).toEqual([testDataSourceStarting(), testDataSourceSucceeded(state.testingStatus)]);
expect(trackDataSourceTested).toHaveBeenCalledWith({
@@ -242,6 +242,7 @@ describe('testDataSource', () => {
datasource_uid: 'CW1234',
grafana_version: '1.0',
success: true,
editLink: '/datasources/edit/CloudWatch',
});
});
@@ -270,7 +271,7 @@ describe('testDataSource', () => {
};
const dispatchedActions = await thunkTester(state)
.givenThunk(testDataSource)
.whenThunkIsDispatched('Azure Monitor', dependencies);
.whenThunkIsDispatched('Azure Monitor', DATASOURCES_ROUTES.Edit, dependencies);
expect(dispatchedActions).toEqual([testDataSourceStarting(), testDataSourceFailed(result)]);
expect(trackDataSourceTested).toHaveBeenCalledWith({
@@ -278,6 +279,7 @@ describe('testDataSource', () => {
datasource_uid: 'azM0nit0R',
grafana_version: '1.0',
success: false,
editLink: '/datasources/edit/Azure Monitor',
});
});

View File

@@ -90,6 +90,7 @@ export const initDataSourceSettings = (
export const testDataSource = (
dataSourceName: string,
editRoute = DATASOURCES_ROUTES.Edit,
dependencies: TestDataSourceDependencies = {
getDatasourceSrv,
getBackendSrv,
@@ -97,6 +98,7 @@ export const testDataSource = (
): ThunkResult<void> => {
return async (dispatch: ThunkDispatch, getState) => {
const dsApi = await dependencies.getDatasourceSrv().get(dataSourceName);
const editLink = editRoute.replace(/:uid/gi, dataSourceName);
if (!dsApi.testDatasource) {
return;
@@ -114,6 +116,7 @@ export const testDataSource = (
plugin_id: dsApi.type,
datasource_uid: dsApi.uid,
success: true,
editLink,
});
} catch (err) {
let message: string | undefined;
@@ -134,6 +137,7 @@ export const testDataSource = (
plugin_id: dsApi.type,
datasource_uid: dsApi.uid,
success: false,
editLink,
});
}
});

View File

@@ -43,8 +43,9 @@ export const useInitDataSourceSettings = (uid: string) => {
export const useTestDataSource = (uid: string) => {
const dispatch = useDispatch();
const dataSourcesRoutes = useDataSourcesRoutes();
return () => dispatch(testDataSource(uid));
return () => dispatch(testDataSource(uid, dataSourcesRoutes.Edit));
};
export const useLoadDataSources = () => {

View File

@@ -53,4 +53,6 @@ type DataSourceTestedProps = {
plugin_version?: string;
/** Whether or not the datasource test succeeded = the datasource was successfully configured */
success: boolean;
/** The URL that points to the edit page for the datasoruce. We are using this to be able to distinguish between the performance of different datasource edit locations. */
editLink?: string;
};