Jaeger: Show a better error msg if no service is selected when using search (#54172)

This commit is contained in:
Hamas Shafiq 2022-08-26 17:09:18 +01:00 committed by GitHub
parent 9d2f5ef62f
commit 93c5c175fe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 0 deletions

View File

@ -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);

View File

@ -48,14 +48,23 @@ export class JaegerDatasource extends DataSourceApi<JaegerQuery, JaegerJsonData>
return res.data.data;
}
isSearchFormValid(query: JaegerQuery): boolean {
return !!query.service;
}
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
// 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))}`