mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
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:
@@ -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();
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -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
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
@@ -24,7 +24,6 @@ export enum LokiResultType {
|
||||
|
||||
export interface LokiQuery extends DataQuery {
|
||||
expr: string;
|
||||
liveStreaming?: boolean;
|
||||
query?: string;
|
||||
format?: string;
|
||||
reverse?: boolean;
|
||||
|
||||
Reference in New Issue
Block a user