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

[APM] Services inventory: add time comparisons to match service overview design #107094

Merged
Merged
Show file tree
Hide file tree
Changes from 13 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 @@ -8,6 +8,7 @@
import { EuiFlexGroup, EuiFlexItem, EuiLink } from '@elastic/eui';
import { i18n } from '@kbn/i18n';
import React, { useEffect } from 'react';
import uuid from 'uuid';
import { toMountPoint } from '../../../../../../../src/plugins/kibana_react/public';
import { useAnomalyDetectionJobsContext } from '../../../context/anomaly_detection_jobs/use_anomaly_detection_jobs_context';
import { useApmPluginContext } from '../../../context/apm_plugin/use_apm_plugin_context';
Expand All @@ -16,25 +17,39 @@ import { useLocalStorage } from '../../../hooks/useLocalStorage';
import { FETCH_STATUS, useFetcher } from '../../../hooks/use_fetcher';
import { useUpgradeAssistantHref } from '../../shared/Links/kibana';
import { SearchBar } from '../../shared/search_bar';
import { getTimeRangeComparison } from '../../shared/time_comparison/get_time_range_comparison';
import { NoServicesMessage } from './no_services_message';
import { ServiceList } from './service_list';
import { MLCallout } from './service_list/MLCallout';

const initialData = {
items: [],
hasHistoricalData: true,
hasLegacyData: false,
requestId: '',
mainStatistics: { items: [], hasHistoricalData: true, hasLegacyData: false },
cauemarcondes marked this conversation as resolved.
Show resolved Hide resolved
};

let hasDisplayedToast = false;

function useServicesFetcher() {
const {
urlParams: { environment, kuery, start, end },
urlParams: {
environment,
kuery,
start,
end,
comparisonEnabled,
comparisonType,
},
} = useUrlParams();
const { core } = useApmPluginContext();
const upgradeAssistantHref = useUpgradeAssistantHref();

const { offset } = getTimeRangeComparison({
start,
end,
comparisonEnabled,
comparisonType,
});

const { data = initialData, status } = useFetcher(
cauemarcondes marked this conversation as resolved.
Show resolved Hide resolved
(callApmApi) => {
if (start && end) {
Expand All @@ -48,14 +63,49 @@ function useServicesFetcher() {
end,
},
},
}).then((response) => {
return {
requestId: uuid(),
mainStatistics: response,
};
});
}
},
[environment, kuery, start, end]
);

const { mainStatistics, requestId } = data;

const { data: comparisonData, status: comparisonStatus } = useFetcher(
(callApmApi) => {
if (start && end && mainStatistics.items.length) {
return callApmApi({
endpoint: 'GET /api/apm/services/detailed_statistics',
params: {
query: {
environment,
kuery,
start,
end,
serviceNames: JSON.stringify(
mainStatistics.items
.map(({ serviceName }) => serviceName)
.sort()
cauemarcondes marked this conversation as resolved.
Show resolved Hide resolved
),
offset,
},
},
});
}
},
// only fetches detailed statistics when requestId is invalidated by main statistics api call or offset is changed
// eslint-disable-next-line react-hooks/exhaustive-deps
[requestId, offset],
{ preservePreviousData: false }
);

useEffect(() => {
if (data.hasLegacyData && !hasDisplayedToast) {
if (mainStatistics.hasLegacyData && !hasDisplayedToast) {
hasDisplayedToast = true;

core.notifications.toasts.addWarning({
Expand All @@ -82,14 +132,30 @@ function useServicesFetcher() {
),
});
}
}, [data.hasLegacyData, upgradeAssistantHref, core.notifications.toasts]);
}, [
mainStatistics.hasLegacyData,
upgradeAssistantHref,
core.notifications.toasts,
]);

return { servicesData: data, servicesStatus: status };
return {
servicesData: mainStatistics,
servicesStatus: status,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we only interested in the mainStatistics status, and not also the comparison status?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, the status from the mainStatistics is going to be used to show an error message if that was the case. And if any happened while fetching the comparison statistics it just wouldn't show the sparklines.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But the comparison statistics is used to define if the loading spinner should be visible or not. https://github.com/elastic/kibana/pull/107094/files#diff-1f8752bfc4d79520010b5d507b96176f454830da1dc8e2091578f66e42007d02R145-R148

comparisonData,
isLoading:
status === FETCH_STATUS.LOADING ||
comparisonStatus === FETCH_STATUS.LOADING,
};
}

export function ServiceInventory() {
const { core } = useApmPluginContext();
const { servicesData, servicesStatus } = useServicesFetcher();
const {
servicesData,
servicesStatus,
comparisonData,
isLoading,
} = useServicesFetcher();

const {
anomalyDetectionJobsData,
Expand All @@ -111,7 +177,7 @@ export function ServiceInventory() {

return (
<>
<SearchBar />
<SearchBar showTimeComparison />
<EuiFlexGroup direction="column" gutterSize="s">
{displayMlCallout && (
<EuiFlexItem>
Expand All @@ -120,12 +186,16 @@ export function ServiceInventory() {
)}
<EuiFlexItem>
<ServiceList
isLoading={isLoading}
items={servicesData.items}
comparisonData={comparisonData}
noItemsMessage={
<NoServicesMessage
historicalDataFound={servicesData.hasHistoricalData}
status={servicesStatus}
/>
!isLoading && (
<NoServicesMessage
historicalDataFound={servicesData.hasHistoricalData}
status={servicesStatus}
/>
)
}
/>
</EuiFlexItem>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@
import { EuiEmptyPrompt, EuiLink } from '@elastic/eui';
import { i18n } from '@kbn/i18n';
import React from 'react';
import { SetupInstructionsLink } from '../../shared/Links/SetupInstructionsLink';
import { LoadingStatePrompt } from '../../shared/LoadingStatePrompt';
import { FETCH_STATUS } from '../../../hooks/use_fetcher';
import { ErrorStatePrompt } from '../../shared/ErrorStatePrompt';
import { useUpgradeAssistantHref } from '../../shared/Links/kibana';
import { SetupInstructionsLink } from '../../shared/Links/SetupInstructionsLink';

interface Props {
// any data submitted from APM agents found (not just in the given time range)
Expand All @@ -23,10 +22,6 @@ interface Props {
export function NoServicesMessage({ historicalDataFound, status }: Props) {
const upgradeAssistantHref = useUpgradeAssistantHref();

if (status === 'loading') {
return <LoadingStatePrompt />;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this no longer needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


if (status === 'failure') {
return <ErrorStatePrompt />;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,26 @@
*/

import React from 'react';
import { Coordinate } from '../../../../../typings/timeseries';
import { SparkPlot } from '../../../shared/charts/spark_plot';

export function ServiceListMetric({
color,
series,
valueLabel,
comparisonSeries,
}: {
color: 'euiColorVis1' | 'euiColorVis0' | 'euiColorVis7';
series?: Array<{ x: number; y: number | null }>;
series?: Coordinate[];
comparisonSeries?: Coordinate[];
valueLabel: React.ReactNode;
}) {
return <SparkPlot valueLabel={valueLabel} series={series} color={color} />;
return (
<SparkPlot
valueLabel={valueLabel}
series={series}
color={color}
comparisonSeries={comparisonSeries}
/>
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,18 @@ export const items: ServiceListAPIResponse['items'] = [
serviceName: 'opbeans-node',
transactionType: 'request',
agentName: 'nodejs',
transactionsPerMinute: { value: 0, timeseries: [] },
transactionErrorRate: { value: 46.06666666666667, timeseries: [] },
avgResponseTime: { value: null, timeseries: [] },
throughput: 0,
transactionErrorRate: 46.06666666666667,
latency: null,
environments: ['test'],
},
{
serviceName: 'opbeans-python',
transactionType: 'page-load',
agentName: 'python',
transactionsPerMinute: { value: 86.93333333333334, timeseries: [] },
transactionErrorRate: { value: 12.6, timeseries: [] },
avgResponseTime: { value: 91535.42944785276, timeseries: [] },
throughput: 86.93333333333334,
transactionErrorRate: 12.6,
latency: 91535.42944785276,
environments: [],
},
];
Loading