mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Loki: Fix error handling, remove legacy condition (#38633)
* Fix error handling, remove legacy condition * Fix strict errors in Loki and lower error count * Update
This commit is contained in:
@@ -42,9 +42,9 @@ import {
|
|||||||
LokiOptions,
|
LokiOptions,
|
||||||
LokiQuery,
|
LokiQuery,
|
||||||
LokiRangeQueryRequest,
|
LokiRangeQueryRequest,
|
||||||
LokiResponse,
|
|
||||||
LokiResultType,
|
LokiResultType,
|
||||||
LokiStreamResponse,
|
LokiStreamResponse,
|
||||||
|
LokiStreamResult,
|
||||||
} from './types';
|
} from './types';
|
||||||
import { LiveStreams, LokiLiveTarget } from './live_streams';
|
import { LiveStreams, LokiLiveTarget } from './live_streams';
|
||||||
import LanguageProvider from './language_provider';
|
import LanguageProvider from './language_provider';
|
||||||
@@ -156,7 +156,7 @@ export class LokiDatasource extends DataSourceApi<LokiQuery, LokiOptions> {
|
|||||||
};
|
};
|
||||||
|
|
||||||
return this._request(INSTANT_QUERY_ENDPOINT, query).pipe(
|
return this._request(INSTANT_QUERY_ENDPOINT, query).pipe(
|
||||||
map((response: { data: LokiResponse }) => {
|
map((response) => {
|
||||||
if (response.data.data.resultType === LokiResultType.Stream) {
|
if (response.data.data.resultType === LokiResultType.Stream) {
|
||||||
return {
|
return {
|
||||||
data: response.data
|
data: response.data
|
||||||
@@ -176,7 +176,7 @@ export class LokiDatasource extends DataSourceApi<LokiQuery, LokiOptions> {
|
|||||||
key: `${target.refId}_instant`,
|
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);
|
const query = this.createRangeQuery(target, options, maxDataPoints);
|
||||||
|
|
||||||
return this._request(RANGE_QUERY_ENDPOINT, query).pipe(
|
return this._request(RANGE_QUERY_ENDPOINT, query).pipe(
|
||||||
catchError((err: any) => this.throwUnless(err, err.status === 404, target)),
|
catchError((err) => throwError(() => this.processError(err, target))),
|
||||||
switchMap((response: { data: LokiResponse; status: number }) =>
|
switchMap((response) =>
|
||||||
processRangeQueryResponse(
|
processRangeQueryResponse(
|
||||||
response.data,
|
response.data,
|
||||||
target,
|
target,
|
||||||
@@ -281,7 +281,7 @@ export class LokiDatasource extends DataSourceApi<LokiQuery, LokiOptions> {
|
|||||||
state: LoadingState.Streaming,
|
state: LoadingState.Streaming,
|
||||||
})),
|
})),
|
||||||
catchError((err: any) => {
|
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';
|
const reverse = options && options.direction === 'FORWARD';
|
||||||
return lastValueFrom(
|
return lastValueFrom(
|
||||||
this._request(RANGE_QUERY_ENDPOINT, target).pipe(
|
this._request(RANGE_QUERY_ENDPOINT, target).pipe(
|
||||||
catchError((err: any) => {
|
catchError((err) => {
|
||||||
if (err.status === 404) {
|
|
||||||
return of(err);
|
|
||||||
}
|
|
||||||
|
|
||||||
const error: DataQueryError = {
|
const error: DataQueryError = {
|
||||||
message: 'Error during context query. Please check JS console logs.',
|
message: 'Error during context query. Please check JS console logs.',
|
||||||
status: err.status,
|
status: err.status,
|
||||||
@@ -463,9 +459,11 @@ export class LokiDatasource extends DataSourceApi<LokiQuery, LokiOptions> {
|
|||||||
};
|
};
|
||||||
throw error;
|
throw error;
|
||||||
}),
|
}),
|
||||||
switchMap((res: { data: LokiStreamResponse; status: number }) =>
|
switchMap((res) =>
|
||||||
of({
|
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;
|
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) {
|
processError(err: FetchError, target: LokiQuery) {
|
||||||
let error = cloneDeep(err);
|
let error = cloneDeep(err);
|
||||||
if (err.data.message.includes('escape') && target.expr.includes('\\')) {
|
if (err.data.message.includes('escape') && target.expr.includes('\\')) {
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ set -e
|
|||||||
|
|
||||||
echo -e "Collecting code stats (typescript errors & more)"
|
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+)')"
|
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
|
if [ "$ERROR_COUNT" -gt $ERROR_COUNT_LIMIT ]; then
|
||||||
|
|||||||
Reference in New Issue
Block a user