Tempo: Add time range to tempo search query behind a feature flag (#43811)

This commit is contained in:
Connor Lindsey
2022-01-10 07:38:40 -07:00
committed by GitHub
parent 3d6e9076c9
commit ef12028a68
5 changed files with 52 additions and 6 deletions

View File

@ -43,6 +43,7 @@ export interface FeatureToggles {
accesscontrol: boolean; accesscontrol: boolean;
tempoServiceGraph: boolean; tempoServiceGraph: boolean;
tempoSearch: boolean; tempoSearch: boolean;
tempoBackendSearch: boolean;
recordedQueries: boolean; recordedQueries: boolean;
newNavigation: boolean; newNavigation: boolean;
fullRangeLogsVolume: boolean; fullRangeLogsVolume: boolean;

View File

@ -66,6 +66,7 @@ export class GrafanaBootConfig implements GrafanaConfig {
trimDefaults: false, trimDefaults: false,
tempoServiceGraph: false, tempoServiceGraph: false,
tempoSearch: false, tempoSearch: false,
tempoBackendSearch: false,
recordedQueries: false, recordedQueries: false,
newNavigation: false, newNavigation: false,
fullRangeLogsVolume: false, fullRangeLogsVolume: false,

View File

@ -136,8 +136,15 @@ class TempoQueryFieldComponent extends React.PureComponent<Props, State> {
{query.queryType === 'nativeSearch' && ( {query.queryType === 'nativeSearch' && (
<p style={{ maxWidth: '65ch' }}> <p style={{ maxWidth: '65ch' }}>
<Badge icon="rocket" text="Beta" color="blue" /> <Badge icon="rocket" text="Beta" color="blue" />
&nbsp;Tempo search is currently in beta and is designed to return recent traces only. It ignores the time {config.featureToggles.tempoBackendSearch ? (
range picker. We are actively working on full backend search. Look for improvements in the near future! <>&nbsp;Tempo search is currently in beta.</>
) : (
<>
&nbsp;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> </p>
)} )}
{query.queryType === 'search' && ( {query.queryType === 'search' && (

View File

@ -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', () => { it('formats native search query history correctly', () => {
const ds = new TempoDatasource(defaultSettings); const ds = new TempoDatasource(defaultSettings);
const tempoQuery: TempoQuery = { const tempoQuery: TempoQuery = {

View File

@ -11,7 +11,7 @@ import {
LoadingState, LoadingState,
} from '@grafana/data'; } from '@grafana/data';
import { TraceToLogsOptions } from 'app/core/components/TraceToLogsSettings'; 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 { serializeParams } from 'app/core/utils/fetch';
import { getDatasourceSrv } from 'app/features/plugins/datasource_srv'; import { getDatasourceSrv } from 'app/features/plugins/datasource_srv';
import { identity, pick, pickBy, groupBy, startCase } from 'lodash'; import { identity, pick, pickBy, groupBy, startCase } from 'lodash';
@ -55,6 +55,15 @@ export interface TempoQuery extends DataQuery {
serviceMapQuery?: string; serviceMapQuery?: string;
} }
interface SearchQueryParams {
minDuration?: string;
maxDuration?: string;
limit?: number;
tags: string;
start?: number;
end?: number;
}
export const DEFAULT_LIMIT = 20; export const DEFAULT_LIMIT = 20;
export class TempoDatasource extends DataSourceWithBackend<TempoQuery, TempoJsonData> { export class TempoDatasource extends DataSourceWithBackend<TempoQuery, TempoJsonData> {
@ -116,7 +125,10 @@ export class TempoDatasource extends DataSourceWithBackend<TempoQuery, TempoJson
if (targets.nativeSearch?.length) { if (targets.nativeSearch?.length) {
try { 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( subQueries.push(
this._request('/api/search', searchQuery).pipe( this._request('/api/search', searchQuery).pipe(
map((response) => { map((response) => {
@ -222,7 +234,7 @@ export class TempoDatasource extends DataSourceWithBackend<TempoQuery, TempoJson
return query.query; return query.query;
} }
buildSearchQuery(query: TempoQuery) { buildSearchQuery(query: TempoQuery, timeRange?: { startTime: number; endTime?: number }): SearchQueryParams {
let tags = query.search ?? ''; let tags = query.search ?? '';
let tempoQuery = pick(query, ['minDuration', 'maxDuration', 'limit']); 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.'); 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() { async getServiceGraphLabels() {