mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Loki: Return empty result if no valid targets (#19830)
This commit is contained in:
parent
09a599900c
commit
af885b2350
@ -1,5 +1,5 @@
|
|||||||
// Libraries
|
// Libraries
|
||||||
import _ from 'lodash';
|
import { isEmpty, isString } from 'lodash';
|
||||||
// Services & Utils
|
// Services & Utils
|
||||||
import {
|
import {
|
||||||
dateMath,
|
dateMath,
|
||||||
@ -30,7 +30,7 @@ import { BackendSrv } from 'app/core/services/backend_srv';
|
|||||||
import { TemplateSrv } from 'app/features/templating/template_srv';
|
import { TemplateSrv } from 'app/features/templating/template_srv';
|
||||||
import { safeStringifyValue, convertToWebSocketUrl } from 'app/core/utils/explore';
|
import { safeStringifyValue, convertToWebSocketUrl } from 'app/core/utils/explore';
|
||||||
import { LiveTarget, LiveStreams } from './live_streams';
|
import { LiveTarget, LiveStreams } from './live_streams';
|
||||||
import { Observable, from, merge } from 'rxjs';
|
import { Observable, from, merge, of } from 'rxjs';
|
||||||
import { map, filter } from 'rxjs/operators';
|
import { map, filter } from 'rxjs/operators';
|
||||||
|
|
||||||
export const DEFAULT_MAX_LINES = 1000;
|
export const DEFAULT_MAX_LINES = 1000;
|
||||||
@ -222,6 +222,14 @@ export class LokiDatasource extends DataSourceApi<LokiQuery, LokiOptions> {
|
|||||||
return this.runQuery(options, target);
|
return this.runQuery(options, target);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// No valid targets, return the empty result to save a round trip.
|
||||||
|
if (isEmpty(subQueries)) {
|
||||||
|
return of({
|
||||||
|
data: [],
|
||||||
|
state: LoadingState.Done,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
return merge(...subQueries);
|
return merge(...subQueries);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -273,7 +281,7 @@ export class LokiDatasource extends DataSourceApi<LokiQuery, LokiOptions> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
getTime(date: string | DateTime, roundUp: boolean) {
|
getTime(date: string | DateTime, roundUp: boolean) {
|
||||||
if (_.isString(date)) {
|
if (isString(date)) {
|
||||||
date = dateMath.parse(date, roundUp);
|
date = dateMath.parse(date, roundUp);
|
||||||
}
|
}
|
||||||
return Math.ceil(date.valueOf() * 1e6);
|
return Math.ceil(date.valueOf() * 1e6);
|
||||||
|
Loading…
Reference in New Issue
Block a user