mirror of
https://github.com/grafana/grafana.git
synced 2024-12-30 10:47:30 -06:00
Jaeger: Fix calling of search query with the correct time range (#90320)
* Jaeger: call search query with query range (#88156) * Update test --------- Co-authored-by: Ivana Huckova <ivana.huckova@gmail.com>
This commit is contained in:
parent
6fcf594b32
commit
ad770cf1e5
@ -38,7 +38,31 @@ jest.mock('@grafana/runtime', () => ({
|
||||
}),
|
||||
}));
|
||||
|
||||
const defaultQuery: DataQueryRequest<JaegerQuery> = {
|
||||
requestId: '1',
|
||||
interval: '0',
|
||||
intervalMs: 10,
|
||||
panelId: 0,
|
||||
scopedVars: {},
|
||||
range: {
|
||||
from: dateTime().subtract(1, 'h'),
|
||||
to: dateTime(),
|
||||
raw: { from: '1h', to: 'now' },
|
||||
},
|
||||
timezone: 'browser',
|
||||
app: 'explore',
|
||||
startTime: 0,
|
||||
targets: [
|
||||
{
|
||||
query: '12345',
|
||||
refId: '1',
|
||||
},
|
||||
],
|
||||
};
|
||||
|
||||
describe('JaegerDatasource', () => {
|
||||
const defaultSearchRangeParams = `start=${Number(defaultQuery.range.from) * 1000}&end=${Number(defaultQuery.range.to) * 1000}`;
|
||||
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
|
||||
@ -128,7 +152,7 @@ describe('JaegerDatasource', () => {
|
||||
})
|
||||
);
|
||||
expect(mock).toHaveBeenCalledWith({
|
||||
url: `${defaultSettings.url}/api/traces?service=jaeger-query&operation=%2Fapi%2Fservices&start=1704085200000000&end=1704106800000000&lookback=custom`,
|
||||
url: `${defaultSettings.url}/api/traces?service=jaeger-query&operation=%2Fapi%2Fservices&${defaultSearchRangeParams}&lookback=custom`,
|
||||
});
|
||||
expect(response.data[0].meta.preferredVisualisationType).toBe('table');
|
||||
// Make sure that traceID field has data link configured
|
||||
@ -136,6 +160,23 @@ describe('JaegerDatasource', () => {
|
||||
expect(response.data[0].fields[0].name).toBe('traceID');
|
||||
});
|
||||
|
||||
it('uses default range when no range is provided for search query,', async () => {
|
||||
const mock = setupFetchMock({ data: [testResponse] });
|
||||
const ds = new JaegerDatasource(defaultSettings);
|
||||
const query = {
|
||||
...defaultQuery,
|
||||
targets: [{ queryType: 'search', refId: 'a', service: 'jaeger-query', operation: ALL_OPERATIONS_KEY }],
|
||||
// set range to undefined to test default range
|
||||
range: undefined,
|
||||
} as unknown as DataQueryRequest<JaegerQuery>;
|
||||
|
||||
ds.query(query);
|
||||
expect(mock).toHaveBeenCalledWith({
|
||||
// Check that query has time range from 6 hours ago to now (default range)
|
||||
url: `${defaultSettings.url}/api/traces?service=jaeger-query&start=1704085200000000&end=1704106800000000&lookback=custom`,
|
||||
});
|
||||
});
|
||||
|
||||
it('should show the correct error message if no service name is selected', async () => {
|
||||
const ds = new JaegerDatasource(defaultSettings);
|
||||
const response = await lastValueFrom(
|
||||
@ -157,7 +198,7 @@ describe('JaegerDatasource', () => {
|
||||
})
|
||||
);
|
||||
expect(mock).toHaveBeenCalledWith({
|
||||
url: `${defaultSettings.url}/api/traces?service=jaeger-query&start=1704085200000000&end=1704106800000000&lookback=custom`,
|
||||
url: `${defaultSettings.url}/api/traces?service=jaeger-query&${defaultSearchRangeParams}&lookback=custom`,
|
||||
});
|
||||
});
|
||||
|
||||
@ -171,7 +212,7 @@ describe('JaegerDatasource', () => {
|
||||
})
|
||||
);
|
||||
expect(mock).toHaveBeenCalledWith({
|
||||
url: `${defaultSettings.url}/api/traces?service=jaeger-query&tags=%7B%22error%22%3A%22true%22%7D&start=1704085200000000&end=1704106800000000&lookback=custom`,
|
||||
url: `${defaultSettings.url}/api/traces?service=jaeger-query&tags=%7B%22error%22%3A%22true%22%7D&${defaultSearchRangeParams}&lookback=custom`,
|
||||
});
|
||||
});
|
||||
|
||||
@ -217,7 +258,7 @@ describe('JaegerDatasource', () => {
|
||||
})
|
||||
);
|
||||
expect(mock).toHaveBeenCalledWith({
|
||||
url: `${defaultSettings.url}/api/traces?service=jaeger-query&tags=%7B%22error%22%3A%22true%22%7D&start=1704085200000000&end=1704106800000000&lookback=custom`,
|
||||
url: `${defaultSettings.url}/api/traces?service=jaeger-query&tags=%7B%22error%22%3A%22true%22%7D&${defaultSearchRangeParams}&lookback=custom`,
|
||||
});
|
||||
});
|
||||
|
||||
@ -247,7 +288,7 @@ describe('JaegerDatasource', () => {
|
||||
})
|
||||
);
|
||||
expect(mock).toHaveBeenCalledWith({
|
||||
url: `${defaultSettings.url}/api/traces?service=interpolationText&operation=interpolationText&minDuration=interpolationText&maxDuration=interpolationText&start=1704085200000000&end=1704106800000000&lookback=custom`,
|
||||
url: `${defaultSettings.url}/api/traces?service=interpolationText&operation=interpolationText&minDuration=interpolationText&maxDuration=interpolationText&${defaultSearchRangeParams}&lookback=custom`,
|
||||
});
|
||||
});
|
||||
});
|
||||
@ -407,25 +448,3 @@ const defaultSettings: DataSourceInstanceSettings<JaegerJsonData> = {
|
||||
},
|
||||
readOnly: false,
|
||||
};
|
||||
|
||||
const defaultQuery: DataQueryRequest<JaegerQuery> = {
|
||||
requestId: '1',
|
||||
interval: '0',
|
||||
intervalMs: 10,
|
||||
panelId: 0,
|
||||
scopedVars: {},
|
||||
range: {
|
||||
from: dateTime().subtract(1, 'h'),
|
||||
to: dateTime(),
|
||||
raw: { from: '1h', to: 'now' },
|
||||
},
|
||||
timezone: 'browser',
|
||||
app: 'explore',
|
||||
startTime: 0,
|
||||
targets: [
|
||||
{
|
||||
query: '12345',
|
||||
refId: '1',
|
||||
},
|
||||
],
|
||||
};
|
||||
|
@ -76,7 +76,7 @@ export class JaegerDatasource extends DataSourceApi<JaegerQuery, JaegerJsonData>
|
||||
return of({ error: { message: 'You must select a service.' }, data: [] });
|
||||
}
|
||||
|
||||
let { start, end } = this.getTimeRange();
|
||||
let { start, end } = this.getTimeRange(options.range);
|
||||
|
||||
if (target.queryType !== 'search' && target.query) {
|
||||
let url = `/api/traces/${encodeURIComponent(this.templateSrv.replace(target.query, options.scopedVars))}`;
|
||||
@ -143,7 +143,7 @@ export class JaegerDatasource extends DataSourceApi<JaegerQuery, JaegerJsonData>
|
||||
// TODO: this api is internal, used in jaeger ui. Officially they have gRPC api that should be used.
|
||||
return this._request(`/api/traces`, {
|
||||
...jaegerQuery,
|
||||
...this.getTimeRange(),
|
||||
...this.getTimeRange(options.range),
|
||||
lookback: 'custom',
|
||||
}).pipe(
|
||||
map((response) => {
|
||||
@ -225,8 +225,7 @@ export class JaegerDatasource extends DataSourceApi<JaegerQuery, JaegerJsonData>
|
||||
);
|
||||
}
|
||||
|
||||
getTimeRange(): { start: number; end: number } {
|
||||
const range = getDefaultTimeRange();
|
||||
getTimeRange(range = getDefaultTimeRange()): { start: number; end: number } {
|
||||
return {
|
||||
start: getTime(range.from, false),
|
||||
end: getTime(range.to, true),
|
||||
|
Loading…
Reference in New Issue
Block a user