Commit 8ec2aa02 by Hugo Häggmark Committed by GitHub

Loki: Replaces dataSourceRequest with fetch (#27265)

* Loki: Replaces dataSourceRequest with fetch

* Update public/app/plugins/datasource/loki/datasource.ts

Co-authored-by: Zoltán Bedi <zoltan.bedi@gmail.com>

Co-authored-by: Zoltán Bedi <zoltan.bedi@gmail.com>
parent fb2538ce
// Libraries
import { isEmpty, map as lodashMap, cloneDeep } from 'lodash';
import { Observable, from, merge, of } from 'rxjs';
import { map, catchError, switchMap } from 'rxjs/operators';
// Services & Utils
import { DataFrame, dateMath, FieldCache, QueryResultMeta, TimeRange } from '@grafana/data';
import { getBackendSrv, BackendSrvRequest, FetchError } from '@grafana/runtime';
import { addLabelToQuery } from 'app/plugins/datasource/prometheus/add_label_to_query';
import { TemplateSrv } from 'app/features/templating/template_srv';
import { convertToWebSocketUrl } from 'app/core/utils/explore';
import { lokiResultsToTableModel, processRangeQueryResponse, lokiStreamResultToDataFrame } from './result_transformer';
import { getHighlighterExpressionsFromQuery } from './query_utils';
import { getTimeSrv } from 'app/features/dashboard/services/TimeSrv';
import { cloneDeep, isEmpty, map as lodashMap } from 'lodash';
import { merge, Observable, of } from 'rxjs';
import { catchError, map, switchMap } from 'rxjs/operators';
// Types
import {
LogRowModel,
DateTime,
LoadingState,
AnnotationEvent,
AnnotationQueryRequest,
DataFrame,
DataFrameView,
PluginMeta,
DataSourceApi,
DataSourceInstanceSettings,
DataQueryError,
DataQueryRequest,
DataQueryResponse,
AnnotationQueryRequest,
DataSourceApi,
DataSourceInstanceSettings,
dateMath,
DateTime,
FieldCache,
LoadingState,
LogRowModel,
PluginMeta,
QueryResultMeta,
ScopedVars,
TimeRange,
} from '@grafana/data';
import { BackendSrvRequest, FetchError, getBackendSrv } from '@grafana/runtime';
import { addLabelToQuery } from 'app/plugins/datasource/prometheus/add_label_to_query';
import { TemplateSrv } from 'app/features/templating/template_srv';
import { convertToWebSocketUrl } from 'app/core/utils/explore';
import { lokiResultsToTableModel, lokiStreamResultToDataFrame, processRangeQueryResponse } from './result_transformer';
import { getHighlighterExpressionsFromQuery } from './query_utils';
import { getTimeSrv } from 'app/features/dashboard/services/TimeSrv';
import {
LokiQuery,
LokiOptions,
LokiQuery,
LokiRangeQueryRequest,
LokiResponse,
LokiResultType,
LokiRangeQueryRequest,
LokiStreamResponse,
} from './types';
import { LiveStreams, LokiLiveTarget } from './live_streams';
......@@ -79,7 +81,7 @@ export class LokiDatasource extends DataSourceApi<LokiQuery, LokiOptions> {
url,
};
return from(getBackendSrv().datasourceRequest(req));
return getBackendSrv().fetch<Record<string, any>>(req);
}
query(options: DataQueryRequest<LokiQuery>): Observable<DataQueryResponse> {
......
import { Observable } from 'rxjs';
interface ObservableTester<T> {
observable: Observable<T>;
done: jest.DoneCallback;
}
interface SubscribeAndExpectOnNext<T> extends ObservableTester<T> {
expect: (value: T) => void;
}
interface SubscribeAndExpectOnComplete<T> extends ObservableTester<T> {
expect: () => void;
}
interface SubscribeAndExpectOnError<T> extends ObservableTester<T> {
expect: (err: any) => void;
}
export const observableTester = () => {
const subscribeAndExpectOnNext = <T>({ observable, expect, done }: SubscribeAndExpectOnNext<T>): void => {
observable.subscribe({
next: value => {
try {
expect(value);
} catch (err) {
done.fail(err);
}
},
error: err => done.fail(err),
complete: () => done(),
});
};
const subscribeAndExpectOnComplete = <T>({ observable, expect, done }: SubscribeAndExpectOnComplete<T>): void => {
observable.subscribe({
next: () => {},
error: err => done.fail(err),
complete: () => {
try {
expect();
done();
} catch (err) {
done.fail(err);
}
},
});
};
const subscribeAndExpectOnError = <T>({ observable, expect, done }: SubscribeAndExpectOnError<T>): void => {
observable.subscribe({
next: () => {},
error: err => {
try {
expect(err);
done();
} catch (err) {
done.fail(err);
}
},
complete: () => {
done();
},
});
};
return { subscribeAndExpectOnNext, subscribeAndExpectOnComplete, subscribeAndExpectOnError };
};
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