From 93c5c175fe2c2e9308a3a9c6fd8ef0d6f37ad47d Mon Sep 17 00:00:00 2001 From: Hamas Shafiq Date: Fri, 26 Aug 2022 17:09:18 +0100 Subject: [PATCH] Jaeger: Show a better error msg if no service is selected when using search (#54172) --- .../app/plugins/datasource/jaeger/datasource.test.ts | 11 +++++++++++ public/app/plugins/datasource/jaeger/datasource.ts | 9 +++++++++ 2 files changed, 20 insertions(+) diff --git a/public/app/plugins/datasource/jaeger/datasource.test.ts b/public/app/plugins/datasource/jaeger/datasource.test.ts index e2a2f2be97d..b59b3a03f02 100644 --- a/public/app/plugins/datasource/jaeger/datasource.test.ts +++ b/public/app/plugins/datasource/jaeger/datasource.test.ts @@ -135,6 +135,17 @@ describe('JaegerDatasource', () => { 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 () => { const mock = setupFetchMock({ data: [testResponse] }); const ds = new JaegerDatasource(defaultSettings, timeSrvStub); diff --git a/public/app/plugins/datasource/jaeger/datasource.ts b/public/app/plugins/datasource/jaeger/datasource.ts index c73f6484a10..85e3ae1badd 100644 --- a/public/app/plugins/datasource/jaeger/datasource.ts +++ b/public/app/plugins/datasource/jaeger/datasource.ts @@ -48,14 +48,23 @@ export class JaegerDatasource extends DataSourceApi return res.data.data; } + isSearchFormValid(query: JaegerQuery): boolean { + return !!query.service; + } + query(options: DataQueryRequest): Observable { // 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. const target: JaegerQuery = options.targets[0]; + if (!target) { 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) { return this._request( `/api/traces/${encodeURIComponent(this.templateSrv.replace(target.query, options.scopedVars))}`