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', () => {
return Promise.resolve({
status: 200,
data: {
values: ['avalue'],
data: ['avalue'],
},
});
},
......
......@@ -373,7 +373,7 @@ export class LokiDatasource extends DataSourceApi<LokiQuery, LokiOptions> {
async metadataRequest(url: string, params?: Record<string, string>) {
const res = await this._request(url, params, { silent: true }).toPromise();
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> {
throw err;
}),
switchMap((response: { data: { values: string[] }; status: number }) =>
iif<DataQueryResponse, DataQueryResponse>(
iif<DataQueryResponse, any>(
() => response.status === 404,
defer(() => this._request('/api/prom/label', { start })),
defer(() => of(response))
)
),
map(res =>
res && res.data && res.data.values && res.data.values.length
map(res => {
const values: any[] = res?.data?.data || res?.data?.values || [];
const testResult =
values.length > 0
? { status: 'success', message: 'Data source connected and labels found.' }
: {
status: 'error',
message:
'Data source connected, but no labels received. Verify that Loki and Promtail is configured properly.',
}
),
};
return testResult;
}),
catchError((err: any) => {
let message = 'Loki: ';
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