mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Jaeger: Show a better error msg if no service is selected when using search (#54172)
This commit is contained in:
parent
9d2f5ef62f
commit
93c5c175fe
@ -135,6 +135,17 @@ describe('JaegerDatasource', () => {
|
|||||||
expect(response.data[0].fields[0].name).toBe('traceID');
|
expect(response.data[0].fields[0].name).toBe('traceID');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should show the correct error message if no service name is selected', async () => {
|
||||||
|
const ds = new JaegerDatasource(defaultSettings, timeSrvStub);
|
||||||
|
const response = await lastValueFrom(
|
||||||
|
ds.query({
|
||||||
|
...defaultQuery,
|
||||||
|
targets: [{ queryType: 'search', refId: 'a', service: undefined, operation: '/api/services' }],
|
||||||
|
})
|
||||||
|
);
|
||||||
|
expect(response.error?.message).toBe('You must select a service.');
|
||||||
|
});
|
||||||
|
|
||||||
it('should remove operation from the query when all is selected', async () => {
|
it('should remove operation from the query when all is selected', async () => {
|
||||||
const mock = setupFetchMock({ data: [testResponse] });
|
const mock = setupFetchMock({ data: [testResponse] });
|
||||||
const ds = new JaegerDatasource(defaultSettings, timeSrvStub);
|
const ds = new JaegerDatasource(defaultSettings, timeSrvStub);
|
||||||
|
@ -48,14 +48,23 @@ export class JaegerDatasource extends DataSourceApi<JaegerQuery, JaegerJsonData>
|
|||||||
return res.data.data;
|
return res.data.data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
isSearchFormValid(query: JaegerQuery): boolean {
|
||||||
|
return !!query.service;
|
||||||
|
}
|
||||||
|
|
||||||
query(options: DataQueryRequest<JaegerQuery>): Observable<DataQueryResponse> {
|
query(options: DataQueryRequest<JaegerQuery>): Observable<DataQueryResponse> {
|
||||||
// At this moment we expect only one target. In case we somehow change the UI to be able to show multiple
|
// At this moment we expect only one target. In case we somehow change the UI to be able to show multiple
|
||||||
// traces at one we need to change this.
|
// traces at one we need to change this.
|
||||||
const target: JaegerQuery = options.targets[0];
|
const target: JaegerQuery = options.targets[0];
|
||||||
|
|
||||||
if (!target) {
|
if (!target) {
|
||||||
return of({ data: [emptyTraceDataFrame] });
|
return of({ data: [emptyTraceDataFrame] });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (target.queryType === 'search' && !this.isSearchFormValid(target)) {
|
||||||
|
return of({ error: { message: 'You must select a service.' }, data: [] });
|
||||||
|
}
|
||||||
|
|
||||||
if (target.queryType !== 'search' && target.query) {
|
if (target.queryType !== 'search' && target.query) {
|
||||||
return this._request(
|
return this._request(
|
||||||
`/api/traces/${encodeURIComponent(this.templateSrv.replace(target.query, options.scopedVars))}`
|
`/api/traces/${encodeURIComponent(this.templateSrv.replace(target.query, options.scopedVars))}`
|
||||||
|
Loading…
Reference in New Issue
Block a user