Loki: Fix error handling, remove legacy condition (#38633)

* Fix error handling, remove legacy condition

* Fix strict errors in Loki and lower error count

* Update
pull/38886/head
Ivana Huckova 4 years ago committed by GitHub
parent d2f3bb6491
commit d5956ce4b7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 33
      public/app/plugins/datasource/loki/datasource.ts
  2. 2
      scripts/ci-check-strict.sh

@ -42,9 +42,9 @@ import {
LokiOptions,
LokiQuery,
LokiRangeQueryRequest,
LokiResponse,
LokiResultType,
LokiStreamResponse,
LokiStreamResult,
} from './types';
import { LiveStreams, LokiLiveTarget } from './live_streams';
import LanguageProvider from './language_provider';
@ -156,7 +156,7 @@ export class LokiDatasource extends DataSourceApi<LokiQuery, LokiOptions> {
};
return this._request(INSTANT_QUERY_ENDPOINT, query).pipe(
map((response: { data: LokiResponse }) => {
map((response) => {
if (response.data.data.resultType === LokiResultType.Stream) {
return {
data: response.data
@ -176,7 +176,7 @@ export class LokiDatasource extends DataSourceApi<LokiQuery, LokiOptions> {
key: `${target.refId}_instant`,
};
}),
catchError((err: any) => this.throwUnless(err, err.status === 404, target))
catchError((err) => throwError(() => this.processError(err, target)))
);
};
@ -236,8 +236,8 @@ export class LokiDatasource extends DataSourceApi<LokiQuery, LokiOptions> {
const query = this.createRangeQuery(target, options, maxDataPoints);
return this._request(RANGE_QUERY_ENDPOINT, query).pipe(
catchError((err: any) => this.throwUnless(err, err.status === 404, target)),
switchMap((response: { data: LokiResponse; status: number }) =>
catchError((err) => throwError(() => this.processError(err, target))),
switchMap((response) =>
processRangeQueryResponse(
response.data,
target,
@ -281,7 +281,7 @@ export class LokiDatasource extends DataSourceApi<LokiQuery, LokiOptions> {
state: LoadingState.Streaming,
})),
catchError((err: any) => {
return throwError(`Live tailing was stopped due to following error: ${err.reason}`);
return throwError(() => `Live tailing was stopped due to following error: ${err.reason}`);
})
);
};
@ -451,11 +451,7 @@ export class LokiDatasource extends DataSourceApi<LokiQuery, LokiOptions> {
const reverse = options && options.direction === 'FORWARD';
return lastValueFrom(
this._request(RANGE_QUERY_ENDPOINT, target).pipe(
catchError((err: any) => {
if (err.status === 404) {
return of(err);
}
catchError((err) => {
const error: DataQueryError = {
message: 'Error during context query. Please check JS console logs.',
status: err.status,
@ -463,9 +459,11 @@ export class LokiDatasource extends DataSourceApi<LokiQuery, LokiOptions> {
};
throw error;
}),
switchMap((res: { data: LokiStreamResponse; status: number }) =>
switchMap((res) =>
of({
data: res.data ? res.data.data.result.map((stream) => lokiStreamResultToDataFrame(stream, reverse)) : [],
data: res.data
? res.data.data.result.map((stream: LokiStreamResult) => lokiStreamResultToDataFrame(stream, reverse))
: [],
})
)
)
@ -625,15 +623,6 @@ export class LokiDatasource extends DataSourceApi<LokiQuery, LokiOptions> {
return (row && row.searchWords && row.searchWords.length > 0) === true;
}
throwUnless(err: FetchError, condition: boolean, target: LokiQuery) {
if (condition) {
return of(err);
}
const error = this.processError(err, target);
throw error;
}
processError(err: FetchError, target: LokiQuery) {
let error = cloneDeep(err);
if (err.data.message.includes('escape') && target.expr.includes('\\')) {

@ -3,7 +3,7 @@ set -e
echo -e "Collecting code stats (typescript errors & more)"
ERROR_COUNT_LIMIT=49
ERROR_COUNT_LIMIT=47
ERROR_COUNT="$(./node_modules/.bin/tsc --project tsconfig.json --noEmit --strict true | grep -oP 'Found \K(\d+)')"
if [ "$ERROR_COUNT" -gt $ERROR_COUNT_LIMIT ]; then

Loading…
Cancel
Save