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] Migrate tx latency chart and group stats to rollups/service metrics #153162

Merged
Merged
Show file tree
Hide file tree
Changes from 5 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 @@ -18,7 +18,7 @@ export function RouterProvider({
}: {
router: Router<RouteMap>;
history: History;
children: React.ReactNode;
children?: React.ReactNode;
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this intended?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, no need for it to be required.

}) {
return (
<ReactRouter history={history}>
Expand Down
4 changes: 4 additions & 0 deletions x-pack/plugins/apm/common/document_type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,7 @@ export type ApmServiceTransactionDocumentType =
| ApmDocumentType.ServiceTransactionMetric
| ApmDocumentType.TransactionMetric
| ApmDocumentType.TransactionEvent;

export type ApmTransactionDocumentType =
| ApmDocumentType.TransactionMetric
| ApmDocumentType.TransactionEvent;
Comment on lines +21 to +23
Copy link
Member

Choose a reason for hiding this comment

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

What about service transaction metric?

Suggested change
export type ApmTransactionDocumentType =
| ApmDocumentType.TransactionMetric
| ApmDocumentType.TransactionEvent;
export type ApmTransactionDocumentType =
| ApmDocumentType.ServiceTransactionMetric
| ApmDocumentType.TransactionMetric
| ApmDocumentType.TransactionEvent;

Copy link
Contributor

Choose a reason for hiding this comment

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

In case we add ApmDocumentType.ServiceTransactionMetric to this one, it becomes in ApmServiceTransactionDocumentType

Copy link
Member Author

Choose a reason for hiding this comment

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

yeah, it's about making sure that the metric contains certain data. ie, service-instance specific data (like host) will not be available on transaction metrics.

7 changes: 7 additions & 0 deletions x-pack/plugins/apm/common/latency_aggregation_types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,10 @@ export const latencyAggregationTypeRt = t.union([
t.literal(LatencyAggregationType.p95),
t.literal(LatencyAggregationType.p99),
]);

export const getLatencyAggregationType = (
latencyAggregationType: string | null | undefined
): LatencyAggregationType => {
return (latencyAggregationType ??
LatencyAggregationType.avg) as LatencyAggregationType;
};
Original file line number Diff line number Diff line change
Expand Up @@ -5,36 +5,35 @@
* 2.0.
*/

import React, { useEffect, useState } from 'react';
import { EuiFlexGroup } from '@elastic/eui';
import { EuiFlexItem } from '@elastic/eui';
import { EuiFlexGroup, EuiFlexItem } from '@elastic/eui';
import { FormattedMessage } from '@kbn/i18n-react';
import { formatAlertEvaluationValue } from '@kbn/observability-plugin/public';
import {
ALERT_DURATION,
ALERT_END,
ALERT_RULE_UUID,
ALERT_EVALUATION_THRESHOLD,
ALERT_RULE_TYPE_ID,
ALERT_EVALUATION_VALUE,
ALERT_RULE_TYPE_ID,
ALERT_RULE_UUID,
} from '@kbn/rule-data-utils';
import moment from 'moment';
import { formatAlertEvaluationValue } from '@kbn/observability-plugin/public';
import { FormattedMessage } from '@kbn/i18n-react';
import React, { useEffect, useMemo, useState } from 'react';
import { useKibana } from '@kbn/kibana-react-plugin/public';
import { SERVICE_ENVIRONMENT } from '../../../../../common/es_fields/apm';
import { ChartPointerEventContextProvider } from '../../../../context/chart_pointer_event/chart_pointer_event_context';
import { TimeRangeMetadataContextProvider } from '../../../../context/time_range_metadata/time_range_metadata_context';
import { useTimeRange } from '../../../../hooks/use_time_range';
import { getComparisonChartTheme } from '../../../shared/time_comparison/get_comparison_chart_theme';
import { ChartPointerEventContextProvider } from '../../../../context/chart_pointer_event/chart_pointer_event_context';

import FailedTransactionChart from './failed_transaction_chart';
import { getAggsTypeFromRule } from './helpers';
import { LatencyAlertsHistoryChart } from './latency_alerts_history_chart';
import LatencyChart from './latency_chart/latency_chart';
import ThroughputChart from './throughput_chart';
import {
AlertDetailsAppSectionProps,
SERVICE_NAME,
TRANSACTION_TYPE,
} from './types';
import { getAggsTypeFromRule } from './helpers';
import { LatencyAlertsHistoryChart } from './latency_alerts_history_chart';

import { SERVICE_ENVIRONMENT } from '../../../../../common/es_fields/apm';
import FailedTransactionChart from './failed_transaction_chart';
import LatencyChart from './latency_chart/latency_chart';
import ThroughputChart from './throughput_chart';

export function AlertDetailsAppSection({
rule,
Expand Down Expand Up @@ -133,61 +132,80 @@ export function AlertDetailsAppSection({
const transactionType = alert.fields[TRANSACTION_TYPE];
const comparisonChartTheme = getComparisonChartTheme();

const {
services: { uiSettings },
} = useKibana();

const historicalRange = useMemo(() => {
return {
start: moment().subtract(30, 'days').toISOString(),
end: moment().toISOString(),
};
}, []);

return (
<EuiFlexGroup direction="column" gutterSize="s">
<ChartPointerEventContextProvider>
<EuiFlexItem>
<LatencyChart
alert={alert}
transactionType={transactionType}
serviceName={serviceName}
environment={environment}
start={start}
end={end}
comparisonChartTheme={comparisonChartTheme}
timeZone={timeZone}
latencyAggregationType={latencyAggregationType}
comparisonEnabled={comparisonEnabled}
offset={offset}
setLatencyMaxY={setLatencyMaxY}
/>
<EuiFlexGroup direction="row" gutterSize="s">
<ThroughputChart
<TimeRangeMetadataContextProvider
start={start}
end={end}
kuery=""
useSpanName={false}
uiSettings={uiSettings!}
>
<ChartPointerEventContextProvider>
<EuiFlexItem>
<LatencyChart
alert={alert}
transactionType={transactionType}
serviceName={serviceName}
environment={environment}
start={start}
end={end}
comparisonChartTheme={comparisonChartTheme}
timeZone={timeZone}
latencyAggregationType={latencyAggregationType}
comparisonEnabled={comparisonEnabled}
latencyMaxY={latencyMaxY}
offset={offset}
timeZone={timeZone}
setLatencyMaxY={setLatencyMaxY}
/>
<FailedTransactionChart
transactionType={transactionType}
<EuiFlexGroup direction="row" gutterSize="s">
<ThroughputChart
transactionType={transactionType}
serviceName={serviceName}
environment={environment}
start={start}
end={end}
comparisonChartTheme={comparisonChartTheme}
comparisonEnabled={comparisonEnabled}
latencyMaxY={latencyMaxY}
offset={offset}
timeZone={timeZone}
/>
<FailedTransactionChart
transactionType={transactionType}
serviceName={serviceName}
environment={environment}
start={start}
end={end}
comparisonChartTheme={comparisonChartTheme}
timeZone={timeZone}
/>
</EuiFlexGroup>
</EuiFlexItem>
<EuiFlexItem grow={false}>
<LatencyAlertsHistoryChart
ruleId={alert.fields[ALERT_RULE_UUID]}
serviceName={serviceName}
start={historicalRange.start}
end={historicalRange.end}
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 fix related to this this PR and the move to service transaction metrics?

Copy link
Member Author

Choose a reason for hiding this comment

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

it's a cosmetic change, it doesn't change the behaviour of the component.

transactionType={transactionType}
latencyAggregationType={latencyAggregationType}
environment={environment}
start={start}
end={end}
comparisonChartTheme={comparisonChartTheme}
timeZone={timeZone}
/>
</EuiFlexGroup>
</EuiFlexItem>
<EuiFlexItem grow={false}>
<LatencyAlertsHistoryChart
ruleId={alert.fields[ALERT_RULE_UUID]}
serviceName={serviceName}
start={start}
end={end}
transactionType={transactionType}
latencyAggregationType={latencyAggregationType}
environment={environment}
timeZone={timeZone}
/>
</EuiFlexItem>
</ChartPointerEventContextProvider>
</EuiFlexItem>
</ChartPointerEventContextProvider>
</TimeRangeMetadataContextProvider>
</EuiFlexGroup>
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,34 @@
* 2.0.
*/

import React, { useMemo } from 'react';
import moment from 'moment';
import { EuiPanel, EuiSpacer } from '@elastic/eui';
import { EuiFlexGroup } from '@elastic/eui';
import { EuiFlexItem } from '@elastic/eui';
import { EuiTitle } from '@elastic/eui';
import { i18n } from '@kbn/i18n';
import { EuiText } from '@elastic/eui';
import {
AnnotationDomainType,
LineAnnotation,
Position,
} from '@elastic/charts';
import { EuiIcon } from '@elastic/eui';
import { EuiBadge } from '@elastic/eui';
import {
EuiBadge,
EuiFlexGroup,
EuiFlexItem,
EuiIcon,
EuiPanel,
EuiSpacer,
EuiText,
EuiTitle,
} from '@elastic/eui';
import { i18n } from '@kbn/i18n';
import { convertTo } from '@kbn/observability-plugin/public';
import { useFetchTriggeredAlertsHistory } from '../../../../hooks/use_fetch_triggered_alert_history';
import { getDurationFormatter } from '../../../../../common/utils/formatters';
import { getLatencyChartSelector } from '../../../../selectors/latency_chart_selectors';
import moment from 'moment';
import React, { useMemo } from 'react';
import { ApmDocumentType } from '../../../../../common/document_type';
import { LatencyAggregationType } from '../../../../../common/latency_aggregation_types';
import { getDurationFormatter } from '../../../../../common/utils/formatters';
import { useFetcher } from '../../../../hooks/use_fetcher';
import { TimeseriesChart } from '../../../shared/charts/timeseries_chart';
import { useFetchTriggeredAlertsHistory } from '../../../../hooks/use_fetch_triggered_alert_history';
import { usePreferredDataSourceAndBucketSize } from '../../../../hooks/use_preferred_data_source_and_bucket_size';
import { getLatencyChartSelector } from '../../../../selectors/latency_chart_selectors';
import { filterNil } from '../../../shared/charts/latency_chart';
import { TimeseriesChart } from '../../../shared/charts/timeseries_chart';
import {
getMaxY,
getResponseTimeTickFormatter,
Expand All @@ -54,14 +59,23 @@ export function LatencyAlertsHistoryChart({
timeZone,
ruleId,
}: LatencyAlertsHistoryChartProps) {
const preferred = usePreferredDataSourceAndBucketSize({
start,
end,
kuery: '',
numBuckets: 100,
type: ApmDocumentType.ServiceTransactionMetric,
});

const { data, status } = useFetcher(
(callApmApi) => {
if (
serviceName &&
start &&
end &&
transactionType &&
latencyAggregationType
latencyAggregationType &&
preferred
) {
return callApmApi(
`GET /internal/apm/services/{serviceName}/transactions/charts/latency`,
Expand All @@ -71,11 +85,14 @@ export function LatencyAlertsHistoryChart({
query: {
environment,
kuery: '',
start: moment().subtract(30, 'days').toISOString(),
end: moment().toISOString(),
start,
end,
transactionType,
transactionName: undefined,
latencyAggregationType,
bucketSizeInSeconds: preferred.bucketSizeInSeconds,
documentType: preferred.source.documentType,
rollupInterval: preferred.source.rollupInterval,
},
},
}
Expand All @@ -89,6 +106,7 @@ export function LatencyAlertsHistoryChart({
serviceName,
start,
transactionType,
preferred,
]
);
const memoizedData = useMemo(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ import { AlertActiveRect } from './alert_active_rect';
import { AlertAnnotation } from './alert_annotation';
import { AlertThresholdAnnotation } from './alert_threshold_annotation';
import { AlertThresholdRect } from './alert_threshold_rect';
import { ApmDocumentType } from '../../../../../../common/document_type';
import { usePreferredDataSourceAndBucketSize } from '../../../../../hooks/use_preferred_data_source_and_bucket_size';

function LatencyChart({
alert,
Expand Down Expand Up @@ -58,14 +60,23 @@ function LatencyChart({
timeZone: string;
setLatencyMaxY: React.Dispatch<React.SetStateAction<number>>;
}) {
const preferred = usePreferredDataSourceAndBucketSize({
start,
end,
kuery: '',
numBuckets: 100,
type: ApmDocumentType.ServiceTransactionMetric,
});

const { data, status } = useFetcher(
(callApmApi) => {
if (
serviceName &&
start &&
end &&
transactionType &&
latencyAggregationType
latencyAggregationType &&
preferred
) {
return callApmApi(
`GET /internal/apm/services/{serviceName}/transactions/charts/latency`,
Expand All @@ -80,6 +91,9 @@ function LatencyChart({
transactionType,
transactionName: undefined,
latencyAggregationType,
documentType: preferred.source.documentType,
rollupInterval: preferred.source.rollupInterval,
bucketSizeInSeconds: preferred.bucketSizeInSeconds,
},
},
}
Expand All @@ -93,6 +107,7 @@ function LatencyChart({
serviceName,
start,
transactionType,
preferred,
]
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export function DependencyDetailOperationsList() {
});

const { searchServiceDestinationMetrics } =
useSearchServiceDestinationMetrics({ rangeFrom, rangeTo, kuery });
useSearchServiceDestinationMetrics({ start, end, kuery });

const primaryStatsFetch = useFetcher(
(callApmApi) => {
Expand Down
Loading