mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Tempo: Add time range to tempo search query behind a feature flag (#43811)
This commit is contained in:
parent
3d6e9076c9
commit
ef12028a68
@ -43,6 +43,7 @@ export interface FeatureToggles {
|
||||
accesscontrol: boolean;
|
||||
tempoServiceGraph: boolean;
|
||||
tempoSearch: boolean;
|
||||
tempoBackendSearch: boolean;
|
||||
recordedQueries: boolean;
|
||||
newNavigation: boolean;
|
||||
fullRangeLogsVolume: boolean;
|
||||
|
@ -66,6 +66,7 @@ export class GrafanaBootConfig implements GrafanaConfig {
|
||||
trimDefaults: false,
|
||||
tempoServiceGraph: false,
|
||||
tempoSearch: false,
|
||||
tempoBackendSearch: false,
|
||||
recordedQueries: false,
|
||||
newNavigation: false,
|
||||
fullRangeLogsVolume: false,
|
||||
|
@ -136,8 +136,15 @@ class TempoQueryFieldComponent extends React.PureComponent<Props, State> {
|
||||
{query.queryType === 'nativeSearch' && (
|
||||
<p style={{ maxWidth: '65ch' }}>
|
||||
<Badge icon="rocket" text="Beta" color="blue" />
|
||||
Tempo search is currently in beta and is designed to return recent traces only. It ignores the time
|
||||
range picker. We are actively working on full backend search. Look for improvements in the near future!
|
||||
{config.featureToggles.tempoBackendSearch ? (
|
||||
<> Tempo search is currently in beta.</>
|
||||
) : (
|
||||
<>
|
||||
Tempo search is currently in beta and is designed to return recent traces only. It ignores the
|
||||
time range picker. We are actively working on full backend search. Look for improvements in the near
|
||||
future!
|
||||
</>
|
||||
)}
|
||||
</p>
|
||||
)}
|
||||
{query.queryType === 'search' && (
|
||||
|
@ -178,6 +178,24 @@ describe('Tempo data source', () => {
|
||||
});
|
||||
});
|
||||
|
||||
it('should include time range if provided', () => {
|
||||
const ds = new TempoDatasource(defaultSettings);
|
||||
const tempoQuery: TempoQuery = {
|
||||
queryType: 'search',
|
||||
refId: 'A',
|
||||
query: '',
|
||||
search: '',
|
||||
};
|
||||
const timeRange = { startTime: 0, endTime: 1000 };
|
||||
const builtQuery = ds.buildSearchQuery(tempoQuery, timeRange);
|
||||
expect(builtQuery).toStrictEqual({
|
||||
tags: '',
|
||||
limit: DEFAULT_LIMIT,
|
||||
start: timeRange.startTime,
|
||||
end: timeRange.endTime,
|
||||
});
|
||||
});
|
||||
|
||||
it('formats native search query history correctly', () => {
|
||||
const ds = new TempoDatasource(defaultSettings);
|
||||
const tempoQuery: TempoQuery = {
|
||||
|
@ -11,7 +11,7 @@ import {
|
||||
LoadingState,
|
||||
} from '@grafana/data';
|
||||
import { TraceToLogsOptions } from 'app/core/components/TraceToLogsSettings';
|
||||
import { BackendSrvRequest, DataSourceWithBackend, getBackendSrv } from '@grafana/runtime';
|
||||
import { config, BackendSrvRequest, DataSourceWithBackend, getBackendSrv } from '@grafana/runtime';
|
||||
import { serializeParams } from 'app/core/utils/fetch';
|
||||
import { getDatasourceSrv } from 'app/features/plugins/datasource_srv';
|
||||
import { identity, pick, pickBy, groupBy, startCase } from 'lodash';
|
||||
@ -55,6 +55,15 @@ export interface TempoQuery extends DataQuery {
|
||||
serviceMapQuery?: string;
|
||||
}
|
||||
|
||||
interface SearchQueryParams {
|
||||
minDuration?: string;
|
||||
maxDuration?: string;
|
||||
limit?: number;
|
||||
tags: string;
|
||||
start?: number;
|
||||
end?: number;
|
||||
}
|
||||
|
||||
export const DEFAULT_LIMIT = 20;
|
||||
|
||||
export class TempoDatasource extends DataSourceWithBackend<TempoQuery, TempoJsonData> {
|
||||
@ -116,7 +125,10 @@ export class TempoDatasource extends DataSourceWithBackend<TempoQuery, TempoJson
|
||||
|
||||
if (targets.nativeSearch?.length) {
|
||||
try {
|
||||
const searchQuery = this.buildSearchQuery(targets.nativeSearch[0]);
|
||||
const timeRange = config.featureToggles.tempoBackendSearch
|
||||
? { startTime: options.range.from.unix(), endTime: options.range.to.unix() }
|
||||
: undefined;
|
||||
const searchQuery = this.buildSearchQuery(targets.nativeSearch[0], timeRange);
|
||||
subQueries.push(
|
||||
this._request('/api/search', searchQuery).pipe(
|
||||
map((response) => {
|
||||
@ -222,7 +234,7 @@ export class TempoDatasource extends DataSourceWithBackend<TempoQuery, TempoJson
|
||||
return query.query;
|
||||
}
|
||||
|
||||
buildSearchQuery(query: TempoQuery) {
|
||||
buildSearchQuery(query: TempoQuery, timeRange?: { startTime: number; endTime?: number }): SearchQueryParams {
|
||||
let tags = query.search ?? '';
|
||||
|
||||
let tempoQuery = pick(query, ['minDuration', 'maxDuration', 'limit']);
|
||||
@ -259,7 +271,14 @@ export class TempoDatasource extends DataSourceWithBackend<TempoQuery, TempoJson
|
||||
throw new Error('Please enter a valid limit.');
|
||||
}
|
||||
|
||||
return { tags, ...tempoQuery };
|
||||
let searchQuery: SearchQueryParams = { tags, ...tempoQuery };
|
||||
|
||||
if (timeRange) {
|
||||
searchQuery.start = timeRange.startTime;
|
||||
searchQuery.end = timeRange.endTime;
|
||||
}
|
||||
|
||||
return searchQuery;
|
||||
}
|
||||
|
||||
async getServiceGraphLabels() {
|
||||
|
Loading…
Reference in New Issue
Block a user