Queries: Move explore state out of query targets (#26203)

* Datasource/CloudWatch: Interal vars no longer sent with query requests

Closes #26202
This commit is contained in:
kay delaney
2020-07-16 14:00:28 +01:00
committed by GitHub
parent d4e4cb4c71
commit 1124da56d6
7 changed files with 41 additions and 27 deletions

View File

@@ -1,4 +1,4 @@
import LokiDatasource, { RangeQueryOptions } from './datasource';
import LokiDatasource from './datasource';
import { LokiQuery, LokiResponse, LokiResultType } from './types';
import { getQueryOptions } from 'test/helpers/getQueryOptions';
import { AnnotationQueryRequest, DataFrame, DataSourceApi, dateTime, FieldCache, TimeRange } from '@grafana/data';
@@ -81,7 +81,7 @@ describe('LokiDatasource', () => {
intervalMs: 2000,
};
const req = ds.createRangeQuery(target, options);
const req = ds.createRangeQuery(target, options as any);
expect(req.start).toBeDefined();
expect(req.end).toBeDefined();
expect(adjustIntervalSpy).toHaveBeenCalledWith(2000, expect.anything());
@@ -345,8 +345,8 @@ describe('LokiDatasource', () => {
raw: { from: '0', to: '1000000001' },
};
// Odd timerange/interval combination that would lead to a float step
const options: RangeQueryOptions = { range, intervalMs: 2000 };
expect(Number.isInteger(ds.createRangeQuery(query, options).step!)).toBeTruthy();
const options = { range, intervalMs: 2000 };
expect(Number.isInteger(ds.createRangeQuery(query, options as any).step!)).toBeTruthy();
});
});

View File

@@ -42,7 +42,7 @@ import LanguageProvider from './language_provider';
import { serializeParams } from '../../../core/utils/fetch';
import { RowContextOptions } from '@grafana/ui/src/components/Logs/LogRowContextProvider';
export type RangeQueryOptions = Pick<DataQueryRequest<LokiQuery>, 'range' | 'intervalMs' | 'maxDataPoints' | 'reverse'>;
export type RangeQueryOptions = DataQueryRequest<LokiQuery> | AnnotationQueryRequest<LokiQuery>;
export const DEFAULT_MAX_LINES = 1000;
export const LOKI_ENDPOINT = '/loki/api/v1';
@@ -143,7 +143,9 @@ export class LokiDatasource extends DataSourceApi<LokiQuery, LokiOptions> {
const startNs = this.getTime(options.range.from, false);
const endNs = this.getTime(options.range.to, true);
const rangeMs = Math.ceil((endNs - startNs) / 1e6);
const step = Math.ceil(this.adjustInterval(options.intervalMs || 1000, rangeMs) / 1000);
const step = Math.ceil(
this.adjustInterval((options as DataQueryRequest<LokiQuery>).intervalMs || 1000, rangeMs) / 1000
);
const alignedTimes = {
start: startNs - (startNs % 1e9),
end: endNs + (1e9 - (endNs % 1e9)),
@@ -160,7 +162,7 @@ export class LokiDatasource extends DataSourceApi<LokiQuery, LokiOptions> {
...DEFAULT_QUERY_PARAMS,
...range,
query,
limit: Math.min(options.maxDataPoints || Infinity, this.maxLines),
limit: Math.min((options as DataQueryRequest<LokiQuery>).maxDataPoints || Infinity, this.maxLines),
};
}
@@ -182,7 +184,7 @@ export class LokiDatasource extends DataSourceApi<LokiQuery, LokiOptions> {
let linesLimit = 0;
if (target.maxLines === undefined) {
// no target.maxLines, using options.maxDataPoints
linesLimit = Math.min(options.maxDataPoints || Infinity, this.maxLines);
linesLimit = Math.min((options as DataQueryRequest<LokiQuery>).maxDataPoints || Infinity, this.maxLines);
} else {
// using target.maxLines
if (isNaN(target.maxLines)) {
@@ -193,7 +195,7 @@ export class LokiDatasource extends DataSourceApi<LokiQuery, LokiOptions> {
}
const queryOptions = { ...options, maxDataPoints: linesLimit };
if (target.liveStreaming) {
if ((options as DataQueryRequest<LokiQuery>).liveStreaming) {
return this.runLiveQuery(target, queryOptions);
}
const query = this.createRangeQuery(target, queryOptions);
@@ -207,7 +209,7 @@ export class LokiDatasource extends DataSourceApi<LokiQuery, LokiOptions> {
responseListLength,
linesLimit,
this.instanceSettings.jsonData,
options.reverse
(options as DataQueryRequest<LokiQuery>).reverse
)
)
);

View File

@@ -24,7 +24,6 @@ export enum LokiResultType {
export interface LokiQuery extends DataQuery {
expr: string;
liveStreaming?: boolean;
query?: string;
format?: string;
reverse?: boolean;