|
|
@ -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('\\')) { |
|
|
|