mirror of
https://github.com/grafana/grafana.git
synced 2025-01-09 23:53:25 -06:00
Tempo: Make usage of time range for TraceID query optional (#58057)
* Added switch to toggle the TraceID query time shift * Fix and improve tests
This commit is contained in:
parent
0071b949e1
commit
90ac300d10
@ -2,7 +2,7 @@ import { css } from '@emotion/css';
|
||||
import React from 'react';
|
||||
|
||||
import { DataSourcePluginOptionsEditorProps, updateDatasourcePluginJsonDataOption } from '@grafana/data';
|
||||
import { InlineField, InlineFieldRow, Input, useStyles } from '@grafana/ui';
|
||||
import { InlineField, InlineFieldRow, InlineSwitch, Input, useStyles } from '@grafana/ui';
|
||||
|
||||
import { TempoJsonData } from '../types';
|
||||
|
||||
@ -14,12 +14,29 @@ export function QuerySettings({ options, onOptionsChange }: Props) {
|
||||
return (
|
||||
<div className={styles.container}>
|
||||
<h3 className="page-heading">TraceID Query</h3>
|
||||
<InlineField
|
||||
label="Use time range in query"
|
||||
tooltip="The time range is ignored by default when querying by TraceID but can be used when there are performance issues or timeouts since it will narrow down the search to the defined range. Default is disabled."
|
||||
labelWidth={26}
|
||||
>
|
||||
<InlineSwitch
|
||||
id="enable-time-shift"
|
||||
value={options.jsonData.traceQuery?.timeShiftEnabled || false}
|
||||
onChange={(event) => {
|
||||
updateDatasourcePluginJsonDataOption({ onOptionsChange, options }, 'traceQuery', {
|
||||
...options.jsonData.traceQuery,
|
||||
timeShiftEnabled: event.currentTarget.checked,
|
||||
});
|
||||
}}
|
||||
/>
|
||||
</InlineField>
|
||||
<InlineFieldRow>
|
||||
<InlineField
|
||||
label="Time shift for start of search"
|
||||
labelWidth={26}
|
||||
disabled={!options.jsonData.traceQuery?.timeShiftEnabled}
|
||||
grow
|
||||
tooltip="Shifts the start of the time range when searching by trace ID. This is needed as searching for traces can return traces that do not fully fall into the search time range, so we recommend using higher time shifts for longer traces. Default 30m (Time units can be used here, for example: 5s, 1m, 3h)"
|
||||
tooltip="Shifts the start of the time range when searching by TraceID. This is needed as searching for traces can return traces that do not fully fall into the search time range, so we recommend using higher time shifts for longer traces. Default 30m (Time units can be used here, for example: 5s, 1m, 3h)"
|
||||
>
|
||||
<Input
|
||||
type="text"
|
||||
@ -39,8 +56,9 @@ export function QuerySettings({ options, onOptionsChange }: Props) {
|
||||
<InlineField
|
||||
label="Time shift for end of search"
|
||||
labelWidth={26}
|
||||
disabled={!options.jsonData.traceQuery?.timeShiftEnabled}
|
||||
grow
|
||||
tooltip="Shifts the end of the time range when searching by trace ID. This is needed as searching for traces can return traces that do not fully fall into the search time range, so we recommend using higher time shifts for longer traces. Default 30m (Time units can be used here, for example: 5s, 1m, 3h)"
|
||||
tooltip="Shifts the end of the time range when searching by TraceID. This is needed as searching for traces can return traces that do not fully fall into the search time range, so we recommend using higher time shifts for longer traces. Default 30m (Time units can be used here, for example: 5s, 1m, 3h)"
|
||||
>
|
||||
<Input
|
||||
type="text"
|
||||
|
@ -369,7 +369,7 @@ describe('Tempo data source', () => {
|
||||
it('should include time shift when querying for traceID', () => {
|
||||
const ds = new TempoDatasource({
|
||||
...defaultSettings,
|
||||
jsonData: { traceQuery: { spanStartTimeShift: '2m', spanEndTimeShift: '4m' } },
|
||||
jsonData: { traceQuery: { timeShiftEnabled: true, spanStartTimeShift: '2m', spanEndTimeShift: '4m' } },
|
||||
});
|
||||
|
||||
const request = ds.traceIdQueryRequest(
|
||||
@ -394,6 +394,35 @@ describe('Tempo data source', () => {
|
||||
expect(request.range.from.unix()).toBe(dateTime(new Date(2022, 8, 13, 15, 58, 0, 0)).unix());
|
||||
expect(request.range.to.unix()).toBe(dateTime(new Date(2022, 8, 13, 16, 19, 0, 0)).unix());
|
||||
});
|
||||
|
||||
it('should not include time shift when querying for traceID and time shift config is off', () => {
|
||||
const ds = new TempoDatasource({
|
||||
...defaultSettings,
|
||||
jsonData: { traceQuery: { timeShiftEnabled: false, spanStartTimeShift: '2m', spanEndTimeShift: '4m' } },
|
||||
});
|
||||
|
||||
const request = ds.traceIdQueryRequest(
|
||||
{
|
||||
requestId: 'test',
|
||||
interval: '',
|
||||
intervalMs: 5,
|
||||
scopedVars: {},
|
||||
targets: [],
|
||||
timezone: '',
|
||||
app: '',
|
||||
startTime: 0,
|
||||
range: {
|
||||
from: dateTime(new Date(2022, 8, 13, 16, 0, 0, 0)),
|
||||
to: dateTime(new Date(2022, 8, 13, 16, 15, 0, 0)),
|
||||
raw: { from: '15m', to: 'now' },
|
||||
},
|
||||
},
|
||||
[{ refId: 'refid1', queryType: 'traceId', query: '' } as TempoQuery]
|
||||
);
|
||||
|
||||
expect(request.range.from.unix()).toBe(dateTime(0).unix());
|
||||
expect(request.range.to.unix()).toBe(dateTime(0).unix());
|
||||
});
|
||||
});
|
||||
|
||||
describe('Tempo apm table', () => {
|
||||
|
@ -8,6 +8,7 @@ import {
|
||||
DataQueryResponseData,
|
||||
DataSourceApi,
|
||||
DataSourceInstanceSettings,
|
||||
dateTime,
|
||||
FieldType,
|
||||
isValidGoDuration,
|
||||
LoadingState,
|
||||
@ -69,6 +70,7 @@ export class TempoDatasource extends DataSourceWithBackend<TempoQuery, TempoJson
|
||||
datasourceUid?: string;
|
||||
};
|
||||
traceQuery?: {
|
||||
timeShiftEnabled?: boolean;
|
||||
spanStartTimeShift?: string;
|
||||
spanEndTimeShift?: string;
|
||||
};
|
||||
@ -325,18 +327,25 @@ export class TempoDatasource extends DataSourceWithBackend<TempoQuery, TempoJson
|
||||
}
|
||||
|
||||
traceIdQueryRequest(options: DataQueryRequest<TempoQuery>, targets: TempoQuery[]): DataQueryRequest<TempoQuery> {
|
||||
return {
|
||||
const request = {
|
||||
...options,
|
||||
range: options.range && {
|
||||
targets,
|
||||
};
|
||||
|
||||
if (this.traceQuery?.timeShiftEnabled) {
|
||||
request.range = options.range && {
|
||||
...options.range,
|
||||
from: options.range.from.subtract(
|
||||
rangeUtil.intervalToMs(this.traceQuery?.spanStartTimeShift || '30m'),
|
||||
'milliseconds'
|
||||
),
|
||||
to: options.range.to.add(rangeUtil.intervalToMs(this.traceQuery?.spanEndTimeShift || '30m'), 'milliseconds'),
|
||||
},
|
||||
targets,
|
||||
};
|
||||
};
|
||||
} else {
|
||||
request.range = { from: dateTime(0), to: dateTime(0), raw: { from: dateTime(0), to: dateTime(0) } };
|
||||
}
|
||||
|
||||
return request;
|
||||
}
|
||||
|
||||
async metadataRequest(url: string, params = {}) {
|
||||
|
@ -30,6 +30,7 @@ export interface TempoJsonData extends DataSourceJsonData {
|
||||
tag: string;
|
||||
};
|
||||
traceQuery?: {
|
||||
timeShiftEnabled?: boolean;
|
||||
spanStartTimeShift?: string;
|
||||
spanEndTimeShift?: string;
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user