Skip to content

Commit f15098c

Browse files
author
Adam Tackett
committed
remove aggregation from service name validation
Signed-off-by: Adam Tackett <[email protected]>
1 parent 0a112c0 commit f15098c

File tree

3 files changed

+37
-27
lines changed

3 files changed

+37
-27
lines changed

public/components/trace_analytics/components/services/service_view.tsx

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ import { coreRefs } from '../../../../framework/core_refs';
3535
import { HeaderControlledComponentsWrapper } from '../../../../plugin_helpers/plugin_headerControl';
3636
import { TraceAnalyticsComponentDeps } from '../../home';
3737
import {
38-
fetchValidServiceNames,
38+
checkValidServiceName,
3939
handleServiceViewRequest,
4040
} from '../../requests/services_request_handler';
4141
import { TraceFilter } from '../common/constants';
@@ -125,9 +125,14 @@ export function ServiceView(props: ServiceViewProps) {
125125
setIsServiceOverviewLoading(true);
126126
setIsServicesDataLoading(true);
127127

128-
const validNames = await fetchValidServiceNames(props.http, mode, props.dataSourceMDSId[0].id);
128+
const validService = await checkValidServiceName(
129+
props.http,
130+
mode,
131+
props.serviceName,
132+
props.dataSourceMDSId[0].id
133+
);
129134

130-
if (!validNames.includes(props.serviceName)) {
135+
if (!validService) {
131136
setServiceIdError(true);
132137
setFields({});
133138
setServiceMap({});

public/components/trace_analytics/requests/queries/services_queries.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -161,26 +161,26 @@ export const getServiceMapQuery = (mode: TraceAnalyticsMode) => {
161161
};
162162
};
163163

164-
export const getServiceValidQuery = (mode: TraceAnalyticsMode) => {
164+
export const getServiceValidQuery = (mode: TraceAnalyticsMode, serviceName: string) => {
165165
return {
166166
index: getServiceIndices(mode),
167167
size: 0,
168168
query: {
169169
bool: {
170-
must: [],
170+
must: [
171+
{
172+
term: {
173+
serviceName: {
174+
value: serviceName,
175+
},
176+
},
177+
},
178+
],
171179
filter: [],
172180
should: [],
173181
must_not: [],
174182
},
175183
},
176-
aggs: {
177-
service_name: {
178-
terms: {
179-
field: 'serviceName',
180-
size: SERVICE_MAP_MAX_NODES,
181-
},
182-
},
183-
},
184184
};
185185
};
186186

public/components/trace_analytics/requests/services_request_handler.ts

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -23,24 +23,29 @@ import {
2323
} from './queries/services_queries';
2424
import { handleDslRequest } from './request_handler';
2525

26-
export const fetchValidServiceNames = async (
26+
export const checkValidServiceName = async (
2727
http: HttpSetup,
2828
mode: TraceAnalyticsMode,
29+
serviceName: string,
2930
dataSourceMDSId?: string
30-
): Promise<string[]> => {
31-
return handleDslRequest(http, null, getServiceValidQuery(mode), mode, dataSourceMDSId)
32-
.then((response) => {
33-
const buckets = response.aggregations?.service_name?.buckets ?? [];
34-
return buckets.map((bucket: any) => bucket.key);
35-
})
36-
.catch((error) => {
37-
console.error('Error fetching valid service names:', error);
38-
coreRefs.core?.notifications.toasts.addError(error, {
39-
title: 'Failed to fetch valid services',
40-
toastLifeTimeMs: 10000,
41-
});
42-
return [];
31+
): Promise<boolean> => {
32+
try {
33+
const response = await handleDslRequest(
34+
http,
35+
null,
36+
getServiceValidQuery(mode, serviceName),
37+
mode,
38+
dataSourceMDSId
39+
);
40+
return response?.hits?.total?.value > 0;
41+
} catch (error) {
42+
console.error('Error checking service name:', error);
43+
coreRefs.core?.notifications.toasts.addError(error, {
44+
title: 'Failed to verify service name',
45+
toastLifeTimeMs: 10000,
4346
});
47+
return false;
48+
}
4449
};
4550

4651
export const handleServicesRequest = async (

0 commit comments

Comments
 (0)