mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
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
This commit is contained in:
parent
36ff6d8635
commit
7665dcc867
@ -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
|
||||
? { 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.',
|
||||
}
|
||||
),
|
||||
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) {
|
||||
|
Loading…
Reference in New Issue
Block a user