Commit 7665dcc8 by David Committed by GitHub

Loki: Fix datasource config page test run (#20971)

- since the API update, the URL fallback was working, but the response
format also needed adapting: `data` (v1) vs `values` (pre-v1)
- this change looks for either data or values in the response for test
and metadata requests
parent 36ff6d86
...@@ -261,7 +261,7 @@ describe('LokiDatasource', () => { ...@@ -261,7 +261,7 @@ describe('LokiDatasource', () => {
return Promise.resolve({ return Promise.resolve({
status: 200, status: 200,
data: { data: {
values: ['avalue'], data: ['avalue'],
}, },
}); });
}, },
......
...@@ -373,7 +373,7 @@ export class LokiDatasource extends DataSourceApi<LokiQuery, LokiOptions> { ...@@ -373,7 +373,7 @@ export class LokiDatasource extends DataSourceApi<LokiQuery, LokiOptions> {
async metadataRequest(url: string, params?: Record<string, string>) { async metadataRequest(url: string, params?: Record<string, string>) {
const res = await this._request(url, params, { silent: true }).toPromise(); const res = await this._request(url, params, { silent: true }).toPromise();
return { return {
data: { data: res.data.values || [] }, data: { data: res.data.data || res.data.values || [] },
}; };
} }
...@@ -559,21 +559,24 @@ export class LokiDatasource extends DataSourceApi<LokiQuery, LokiOptions> { ...@@ -559,21 +559,24 @@ export class LokiDatasource extends DataSourceApi<LokiQuery, LokiOptions> {
throw err; throw err;
}), }),
switchMap((response: { data: { values: string[] }; status: number }) => switchMap((response: { data: { values: string[] }; status: number }) =>
iif<DataQueryResponse, DataQueryResponse>( iif<DataQueryResponse, any>(
() => response.status === 404, () => response.status === 404,
defer(() => this._request('/api/prom/label', { start })), defer(() => this._request('/api/prom/label', { start })),
defer(() => of(response)) defer(() => of(response))
) )
), ),
map(res => map(res => {
res && res.data && res.data.values && res.data.values.length const values: any[] = res?.data?.data || res?.data?.values || [];
const testResult =
values.length > 0
? { status: 'success', message: 'Data source connected and labels found.' } ? { status: 'success', message: 'Data source connected and labels found.' }
: { : {
status: 'error', status: 'error',
message: message:
'Data source connected, but no labels received. Verify that Loki and Promtail is configured properly.', 'Data source connected, but no labels received. Verify that Loki and Promtail is configured properly.',
} };
), return testResult;
}),
catchError((err: any) => { catchError((err: any) => {
let message = 'Loki: '; let message = 'Loki: ';
if (err.statusText) { if (err.statusText) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment