Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Backport 2.x] [Bug] Traces/Services remove toast message on empty data #2347

Merged
merged 1 commit into from
Feb 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@

export const handleServicesRequest = async (
http: HttpSetup,
DSL: any,

Check warning on line 28 in public/components/trace_analytics/requests/services_request_handler.ts

View workflow job for this annotation

GitHub Actions / Lint

Unexpected any. Specify a different type
setItems: any,

Check warning on line 29 in public/components/trace_analytics/requests/services_request_handler.ts

View workflow job for this annotation

GitHub Actions / Lint

Unexpected any. Specify a different type
mode: TraceAnalyticsMode,
dataSourceMDSId?: string,
setServiceMap?: any,

Check warning on line 32 in public/components/trace_analytics/requests/services_request_handler.ts

View workflow job for this annotation

GitHub Actions / Lint

Unexpected any. Specify a different type
serviceNameFilter?: string
) => {
return handleDslRequest(
Expand All @@ -47,10 +47,16 @@
dataSourceMDSId,
setServiceMap
);

if (!serviceObject || Object.keys(serviceObject).length === 0) {
setItems([]);
return [];
}

return Promise.all(
response.aggregations.service.buckets
.filter((bucket: any) => serviceObject[bucket.key])

Check warning on line 58 in public/components/trace_analytics/requests/services_request_handler.ts

View workflow job for this annotation

GitHub Actions / Lint

Unexpected any. Specify a different type
.map((bucket: any) => {

Check warning on line 59 in public/components/trace_analytics/requests/services_request_handler.ts

View workflow job for this annotation

GitHub Actions / Lint

Unexpected any. Specify a different type
const connectedServices = [
...serviceObject[bucket.key].targetServices,
...serviceObject[bucket.key].destServices,
Expand Down Expand Up @@ -82,10 +88,10 @@

export const handleServiceMapRequest = async (
http: HttpSetup,
DSL: DSLService | any,

Check warning on line 91 in public/components/trace_analytics/requests/services_request_handler.ts

View workflow job for this annotation

GitHub Actions / Lint

Unexpected any. Specify a different type
mode: TraceAnalyticsMode,
dataSourceMDSId?: string,
setItems?: any,

Check warning on line 94 in public/components/trace_analytics/requests/services_request_handler.ts

View workflow job for this annotation

GitHub Actions / Lint

Unexpected any. Specify a different type
includeMetrics = true
) => {
let minutesInDateRange: number;
Expand All @@ -103,38 +109,42 @@
getServiceNodesQuery(mode),
mode,
dataSourceMDSId
)
.then((response) => {
response.aggregations.service_name.buckets.map(
(bucket: any) =>
(map[bucket.key] = {
serviceName: bucket.key,
id: id++,
targetResources: bucket.target_resource.buckets.map((res: any) => res.key),
targetServices: [],
destServices: [],
})
);
return true;
})
.catch((error) => {
console.error('Error retrieving service nodes:', error);
coreRefs.core?.notifications.toasts.addError(error, {
title: 'Failed to retrieve service nodes',
toastLifeTimeMs: 10000,
});
return false;
).catch((error) => {
console.error('Error retrieving service nodes:', error);
coreRefs.core?.notifications.toasts.addError(error, {
title: 'Failed to retrieve service nodes',
toastLifeTimeMs: 10000,
});
return null;
});

// Early return if service node not found
if (!serviceNodesResponse) {
if (
!serviceNodesResponse ||
!serviceNodesResponse.aggregations ||
!serviceNodesResponse.aggregations.service_name ||
!serviceNodesResponse.aggregations.service_name.buckets ||
serviceNodesResponse.aggregations.service_name.buckets.length === 0
) {
if (setItems) {
setItems(map);
}
return map;
}

const targets = {};
serviceNodesResponse.aggregations.service_name.buckets.forEach((bucket: any) => {

Check warning on line 134 in public/components/trace_analytics/requests/services_request_handler.ts

View workflow job for this annotation

GitHub Actions / Lint

Unexpected any. Specify a different type
map[bucket.key] = {
serviceName: bucket.key,
id: id++,
targetResources: bucket.target_resource.buckets.map((res: any) => res.key),

Check warning on line 138 in public/components/trace_analytics/requests/services_request_handler.ts

View workflow job for this annotation

GitHub Actions / Lint

Unexpected any. Specify a different type
targetServices: [],
destServices: [],
};
});

const targets: Record<string, string> = {};
await handleDslRequest(http, null, getServiceEdgesQuery('target', mode), mode, dataSourceMDSId)
.then((response) =>
response.aggregations.service_name.buckets.map((bucket: any) => {

Check warning on line 147 in public/components/trace_analytics/requests/services_request_handler.ts

View workflow job for this annotation

GitHub Actions / Lint

Unexpected any. Specify a different type
bucket.resource.buckets.map((resource: any) => {
resource.domain.buckets.map((domain: any) => {
targets[resource.key + ':' + domain.key] = bucket.key;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,21 @@ export const handleTracesRequest = async (
percentileRangesResult.status === 'fulfilled' ? percentileRangesResult.value : {};
const response = responseResult.value;

if ((response.statusCode && response.statusCode >= 400) || response.error) {
return Promise.reject(response);
}

if (
!response ||
!response.aggregations ||
!response.aggregations.traces ||
!response.aggregations.traces.buckets ||
response.aggregations.traces.buckets.length === 0
) {
setItems([]);
return [];
}

return response.aggregations.traces.buckets.map((bucket: any) => {
if (mode === 'data_prepper' || mode === 'custom_data_prepper') {
return {
Expand Down
Loading