Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed a bug where mixed datasource with variable ref were not working #1909

Merged
merged 1 commit into from
Nov 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 20 additions & 6 deletions src/datasource/datasource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,13 @@ import { ZabbixAPIError } from './zabbix/connectors/zabbix_api/zabbixAPIConnecto
import { ProblemDTO, VariableQueryTypes } from './types';
import { ZabbixMetricsQuery, ShowProblemTypes } from './types/query';
import { ZabbixDSOptions } from './types/config';
import { BackendSrvRequest, getBackendSrv, getTemplateSrv, toDataQueryResponse } from '@grafana/runtime';
import {
BackendSrvRequest,
getBackendSrv,
getTemplateSrv,
toDataQueryResponse,
getDataSourceSrv,
} from '@grafana/runtime';
import {
DataFrame,
dataFrameFromJSON,
Expand Down Expand Up @@ -119,11 +125,19 @@ export class ZabbixDatasource extends DataSourceApi<ZabbixMetricsQuery, ZabbixDS
trackRequest(request);

// Migrate old targets
const requestTargets = request.targets.map((t) => {
// Prevent changes of original object
const target = _.cloneDeep(t);
return migrations.migrate(target);
});
const requestTargets = request.targets
.map((t) => {
// Prevent changes of original object
const target = _.cloneDeep(t);
return migrations.migrate(target);
})
.map((target) => {
let ds = getDataSourceSrv().getInstanceSettings(target?.datasource);
if (ds?.rawRef?.uid) {
return { ...target, datasource: { ...target?.datasource, uid: ds.rawRef?.uid } };
}
return target;
});

const backendResponsePromise = this.backendQuery({ ...request, targets: requestTargets });
const dbConnectionResponsePromise = this.dbConnectionQuery({ ...request, targets: requestTargets });
Expand Down
3 changes: 3 additions & 0 deletions src/datasource/specs/datasource.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ jest.mock(
toPromise: () => jest.fn().mockResolvedValue({ data: { result: '' } }),
}),
}),
getDataSourceSrv: () => ({
getInstanceSettings: jest.fn().mockResolvedValue({}),
}),
getTemplateSrv: () => ({
replace: jest.fn().mockImplementation((query) => query),
}),
Expand Down
Loading