diff --git a/x-pack/plugins/observability_solution/apm/public/components/app/service_overview/index.tsx b/x-pack/plugins/observability_solution/apm/public/components/app/service_overview/index.tsx index 4cbd45935c403..e04f90b81798d 100644 --- a/x-pack/plugins/observability_solution/apm/public/components/app/service_overview/index.tsx +++ b/x-pack/plugins/observability_solution/apm/public/components/app/service_overview/index.tsx @@ -5,7 +5,7 @@ * 2.0. */ -import { EuiFlexGroup, EuiFlexItem } from '@elastic/eui'; +import { EuiFlexGroup, EuiFlexItem, EuiLoadingLogo } from '@elastic/eui'; import React, { useEffect } from 'react'; import { AnnotationsContextProvider } from '../../../context/annotations/annotations_context'; import { useApmPluginContext } from '../../../context/apm_plugin/use_apm_plugin_context'; @@ -17,6 +17,7 @@ import { useTimeRange } from '../../../hooks/use_time_range'; import { isApmSignal, isLogsSignal } from '../../../utils/get_signal_type'; import { ApmOverview } from './apm_overview'; import { LogsOverview } from './logs_overview'; +import { FETCH_STATUS } from '../../../hooks/use_fetcher'; /** * The height a chart should be if it's next to a table with 5 rows and a title. * Add the height of the pagination row. @@ -25,7 +26,7 @@ export const chartHeight = 288; export function ServiceOverview() { const { isEntityCentricExperienceViewEnabled } = useEntityManagerEnablementContext(); - const { serviceName, serviceEntitySummary } = useApmServiceContext(); + const { serviceName, serviceEntitySummary, serviceEntitySummaryStatus } = useApmServiceContext(); const setScreenContext = useApmPluginContext().observabilityAIAssistant?.service.setScreenContext; @@ -48,14 +49,24 @@ export function ServiceOverview() { const { start, end } = useTimeRange({ rangeFrom, rangeTo }); - const hasLogsSignal = - serviceEntitySummary?.dataStreamTypes && isLogsSignal(serviceEntitySummary.dataStreamTypes); + const hasSignal = + serviceEntitySummary?.dataStreamTypes && serviceEntitySummary?.dataStreamTypes?.length > 0; - const hasApmSignal = - serviceEntitySummary?.dataStreamTypes && isApmSignal(serviceEntitySummary.dataStreamTypes); + const hasLogsSignal = hasSignal && isLogsSignal(serviceEntitySummary.dataStreamTypes); - // Shows APM overview when entity has APM signal or when Entity centric is not enabled - const showApmOverview = isEntityCentricExperienceViewEnabled === false || hasApmSignal; + const hasApmSignal = hasSignal && isApmSignal(serviceEntitySummary.dataStreamTypes); + + // Shows APM overview when entity has APM signal or when Entity centric is not enabled or when entity has no signal + const showApmOverview = + isEntityCentricExperienceViewEnabled === false || hasApmSignal || !hasSignal; + + if (serviceEntitySummaryStatus === FETCH_STATUS.LOADING) { + return ( +
+ +
+ ); + } return ( { - if (isEntityCentricExperienceViewEnabled && serviceName && start && end && environment) { + if (isEntityCentricExperienceViewEnabled && serviceName && environment) { return callAPI('GET /internal/apm/entities/services/{serviceName}/summary', { - params: { path: { serviceName }, query: { end, environment, start } }, + params: { path: { serviceName }, query: { environment } }, }); } }, - [end, environment, isEntityCentricExperienceViewEnabled, serviceName, start] + [environment, isEntityCentricExperienceViewEnabled, serviceName] ); return { serviceEntitySummary: data, serviceEntitySummaryStatus: status }; diff --git a/x-pack/plugins/observability_solution/apm/server/routes/entities/get_entities.ts b/x-pack/plugins/observability_solution/apm/server/routes/entities/get_entities.ts index 19276b25d50d5..36929cb766554 100644 --- a/x-pack/plugins/observability_solution/apm/server/routes/entities/get_entities.ts +++ b/x-pack/plugins/observability_solution/apm/server/routes/entities/get_entities.ts @@ -11,7 +11,11 @@ import { getEntityLatestServices } from './get_entity_latest_services'; import type { EntityLatestServiceRaw } from './types'; import { getEntityHistoryServicesMetrics } from './get_entity_history_services_metrics'; -export function entitiesRangeQuery(start: number, end: number): QueryDslQueryContainer[] { +export function entitiesRangeQuery(start?: number, end?: number): QueryDslQueryContainer[] { + if (!start || !end) { + return []; + } + return [ { range: { diff --git a/x-pack/plugins/observability_solution/apm/server/routes/entities/get_entity_latest_services.ts b/x-pack/plugins/observability_solution/apm/server/routes/entities/get_entity_latest_services.ts index de44ab5f13eaa..880713a75a352 100644 --- a/x-pack/plugins/observability_solution/apm/server/routes/entities/get_entity_latest_services.ts +++ b/x-pack/plugins/observability_solution/apm/server/routes/entities/get_entity_latest_services.ts @@ -28,8 +28,8 @@ export async function getEntityLatestServices({ serviceName, }: { entitiesESClient: EntitiesESClient; - start: number; - end: number; + start?: number; + end?: number; environment: string; kuery?: string; size: number; diff --git a/x-pack/plugins/observability_solution/apm/server/routes/entities/services/get_service_entity_summary.ts b/x-pack/plugins/observability_solution/apm/server/routes/entities/services/get_service_entity_summary.ts index 9e631bdaa98da..e99ecc0217ed9 100644 --- a/x-pack/plugins/observability_solution/apm/server/routes/entities/services/get_service_entity_summary.ts +++ b/x-pack/plugins/observability_solution/apm/server/routes/entities/services/get_service_entity_summary.ts @@ -16,22 +16,12 @@ interface Params { entitiesESClient: EntitiesESClient; serviceName: string; environment: string; - start: number; - end: number; } -export function getServiceEntitySummary({ - end, - entitiesESClient, - environment, - serviceName, - start, -}: Params) { +export function getServiceEntitySummary({ entitiesESClient, environment, serviceName }: Params) { return withApmSpan('get_service_entity_summary', async () => { const entityLatestServices = await getEntityLatestServices({ entitiesESClient, - start, - end, environment, size: MAX_NUMBER_OF_SERVICES, serviceName, diff --git a/x-pack/plugins/observability_solution/apm/server/routes/entities/services/routes.ts b/x-pack/plugins/observability_solution/apm/server/routes/entities/services/routes.ts index 374e39c4b1756..c3f36a6d86c52 100644 --- a/x-pack/plugins/observability_solution/apm/server/routes/entities/services/routes.ts +++ b/x-pack/plugins/observability_solution/apm/server/routes/entities/services/routes.ts @@ -19,7 +19,7 @@ const serviceEntitiesSummaryRoute = createApmServerRoute({ endpoint: 'GET /internal/apm/entities/services/{serviceName}/summary', params: t.type({ path: t.type({ serviceName: t.string }), - query: t.intersection([environmentRt, rangeRt]), + query: environmentRt, }), options: { tags: ['access:apm'] }, async handler(resources) { @@ -32,12 +32,10 @@ const serviceEntitiesSummaryRoute = createApmServerRoute({ }); const { serviceName } = params.path; - const { start, end, environment } = params.query; + const { environment } = params.query; return getServiceEntitySummary({ entitiesESClient, - start, - end, serviceName, environment, }); diff --git a/x-pack/plugins/observability_solution/apm/server/routes/services/route.ts b/x-pack/plugins/observability_solution/apm/server/routes/services/route.ts index 67c3caa03f3f0..da2a506e3ae3f 100644 --- a/x-pack/plugins/observability_solution/apm/server/routes/services/route.ts +++ b/x-pack/plugins/observability_solution/apm/server/routes/services/route.ts @@ -319,8 +319,6 @@ const serviceAgentRoute = createApmServerRoute({ end, }), getServiceEntitySummary({ - end, - start, serviceName, entitiesESClient, environment: ENVIRONMENT_ALL.value,