[v9.4.x] Refactor: Use data source UID rather than ID (#62937)

Refactor: Use data source UID rather than ID (#62781)

(cherry picked from commit 9893408af9)

Co-authored-by: Andres Martinez Gotor <andres.martinez@grafana.com>
This commit is contained in:
Grot (@grafanabot)
2023-02-06 05:36:00 -05:00
committed by GitHub
co-authored by Andres Martinez Gotor
parent d9710139e1
commit 3dffe4099b
3 changed files with 55 additions and 4 deletions
@@ -182,6 +182,57 @@ describe('DataSourceWithBackend', () => {
obs = toStreamingDataResponse(rsp, request, standardStreamOptionsProvider);
expect(obs).toBeDefined();
});
test('check that getResource uses the data source UID', () => {
const { mock, ds } = createMockDatasource();
ds.getResource('foo');
const args = mock.calls[0][0];
expect(mock.calls.length).toBe(1);
expect(args).toMatchObject({
headers: {
'X-Datasource-Uid': 'abc',
'X-Plugin-Id': 'dummy',
},
method: 'GET',
url: '/api/datasources/uid/abc/resources/foo',
});
});
test('check that postResource uses the data source UID', () => {
const { mock, ds } = createMockDatasource();
ds.postResource('foo');
const args = mock.calls[0][0];
expect(mock.calls.length).toBe(1);
expect(args).toMatchObject({
headers: {
'X-Datasource-Uid': 'abc',
'X-Plugin-Id': 'dummy',
},
method: 'POST',
url: '/api/datasources/uid/abc/resources/foo',
});
});
test('check that callHealthCheck uses the data source UID', () => {
const { mock, ds } = createMockDatasource();
ds.callHealthCheck();
const args = mock.calls[0][0];
expect(mock.calls.length).toBe(1);
expect(args).toMatchObject({
headers: {
'X-Datasource-Uid': 'abc',
'X-Plugin-Id': 'dummy',
},
method: 'GET',
url: '/api/datasources/uid/abc/health',
});
});
});
function createMockDatasource() {
@@ -281,7 +281,7 @@ class DataSourceWithBackend<
method: 'GET',
headers: options?.headers ? { ...options.headers, ...headers } : headers,
params: params ?? options?.params,
url: `/api/datasources/${this.id}/resources/${path}`,
url: `/api/datasources/uid/${this.uid}/resources/${path}`,
})
);
return result.data;
@@ -302,7 +302,7 @@ class DataSourceWithBackend<
method: 'POST',
headers: options?.headers ? { ...options.headers, ...headers } : headers,
data: data ?? { ...data },
url: `/api/datasources/${this.id}/resources/${path}`,
url: `/api/datasources/uid/${this.uid}/resources/${path}`,
})
);
return result.data;
@@ -315,7 +315,7 @@ class DataSourceWithBackend<
return lastValueFrom(
getBackendSrv().fetch<HealthCheckResult>({
method: 'GET',
url: `/api/datasources/${this.id}/health`,
url: `/api/datasources/uid/${this.uid}/health`,
showErrorAlert: false,
headers: this.getRequestHeaders(),
})
@@ -133,7 +133,7 @@ export class DashboardLoaderSrv {
});
return getBackendSrv()
.get(`/api/datasources/${ds.id}/resources/${path}`, queryParams)
.get(`/api/datasources/uid/${ds.uid}/resources/${path}`, queryParams)
.then((data) => {
return {
meta: {