Skip to content

Commit

Permalink
[APM][ECO] Fallback to APM overview when datastream type is not prese…
Browse files Browse the repository at this point in the history
…nt (#192263)

closes #192071 

1. Gracefully handle the case when datastream is not present by showing
the APM overview
2. Remove `start` and `end` from `GET
/internal/apm/entities/services/{serviceName}/summary'` endpoint




https://github.com/user-attachments/assets/2c2d53fe-42cf-435a-a131-410d1252ba55
  • Loading branch information
kpatticha authored Sep 10, 2024
1 parent 77e4728 commit c308afd
Show file tree
Hide file tree
Showing 8 changed files with 32 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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.
Expand All @@ -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;

Expand All @@ -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 (
<div style={{ textAlign: 'center' }}>
<EuiLoadingLogo logo="logoObservability" size="l" />
</div>
);
}

return (
<AnnotationsContextProvider
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,6 @@ export function ApmServiceContextProvider({ children }: { children: ReactNode })

const { serviceEntitySummary, serviceEntitySummaryStatus } = useServiceEntitySummaryFetcher({
serviceName,
start,
end,
environment,
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@ export type ServiceEntitySummary =

export function useServiceEntitySummaryFetcher({
serviceName,
start,
end,
environment,
}: {
serviceName?: string;
Expand All @@ -27,13 +25,13 @@ export function useServiceEntitySummaryFetcher({

const { data, status } = useFetcher(
(callAPI) => {
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 };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -319,8 +319,6 @@ const serviceAgentRoute = createApmServerRoute({
end,
}),
getServiceEntitySummary({
end,
start,
serviceName,
entitiesESClient,
environment: ENVIRONMENT_ALL.value,
Expand Down

0 comments on commit c308afd

Please sign in to comment.