Skip to content

Commit

Permalink
Add logic to replace transaction histogram with summary (#155714)
Browse files Browse the repository at this point in the history
Closes #152694

## Summary

This PR replaces the transaction.duration.histogram with
transaction.duration.summary field and maintains backward compatibility
by switching to former when the later is no present for past data


### Checklist

Delete any items that are not applicable to this PR.
- [x] Switch for transactions table on the service overview page and
transactions overview page
- [x] Switch for Latency Charts on Transaction Details page
- [x] Add logic to switch with backward compatibility
- [x] Fix existing Unit and API tests
- [x] Add new API Tests to make sure backward compatibility works


### Risk Matrix

| Risk | Probability | Severity | Mitigation/Notes |

|---------------------------|-------------|----------|-------------------------|
| Backward compatibility to switch to histogram if summary field is not
present on the data | Low | High | Integration tests will verify that
all features are still supported in and duration switches to old field
when new field is not available. |

---------

Co-authored-by: kibanamachine <[email protected]>
  • Loading branch information
achyutjhunjhunwala and kibanamachine authored May 4, 2023
1 parent 531ed3f commit bb08db9
Show file tree
Hide file tree
Showing 22 changed files with 750 additions and 304 deletions.
7 changes: 7 additions & 0 deletions x-pack/plugins/apm/common/data_source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,10 @@ export interface ApmDataSource<
rollupInterval: RollupInterval;
documentType: TDocumentType;
}

export type ApmDataSourceWithSummary<
T extends AnyApmDocumentType = AnyApmDocumentType
> = ApmDataSource<T> & {
hasDurationSummaryField: boolean;
hasDocs: boolean;
};
4 changes: 3 additions & 1 deletion x-pack/plugins/apm/common/time_range_metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,7 @@ import { ApmDataSource } from './data_source';

export interface TimeRangeMetadata {
isUsingServiceDestinationMetrics: boolean;
sources: Array<ApmDataSource & { hasDocs: boolean }>;
sources: Array<
ApmDataSource & { hasDocs: boolean; hasDurationSummaryField: boolean }
>;
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,48 +4,62 @@
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
import { ApmDataSource } from '../data_source';
import { ApmDataSourceWithSummary } from '../data_source';
import { ApmDocumentType } from '../document_type';
import { RollupInterval } from '../rollup';
import {
getPreferredBucketSizeAndDataSource,
intervalToSeconds,
} from './get_preferred_bucket_size_and_data_source';

const serviceTransactionMetricSources: ApmDataSource[] = [
const serviceTransactionMetricSources: ApmDataSourceWithSummary[] = [
{
documentType: ApmDocumentType.ServiceTransactionMetric,
rollupInterval: RollupInterval.OneMinute,
hasDurationSummaryField: true,
hasDocs: true,
},
{
documentType: ApmDocumentType.ServiceTransactionMetric,
rollupInterval: RollupInterval.TenMinutes,
hasDurationSummaryField: true,
hasDocs: true,
},
{
documentType: ApmDocumentType.ServiceTransactionMetric,
rollupInterval: RollupInterval.SixtyMinutes,
hasDurationSummaryField: true,
hasDocs: true,
},
];

const txMetricSources: ApmDataSource[] = [
const txMetricSources: ApmDataSourceWithSummary[] = [
{
documentType: ApmDocumentType.TransactionMetric,
rollupInterval: RollupInterval.OneMinute,
hasDurationSummaryField: true,
hasDocs: true,
},
{
documentType: ApmDocumentType.TransactionMetric,
rollupInterval: RollupInterval.TenMinutes,
hasDurationSummaryField: true,
hasDocs: true,
},
{
documentType: ApmDocumentType.TransactionMetric,
rollupInterval: RollupInterval.SixtyMinutes,
hasDurationSummaryField: true,
hasDocs: true,
},
];

const txEventSources: ApmDataSource[] = [
const txEventSources: ApmDataSourceWithSummary[] = [
{
documentType: ApmDocumentType.TransactionEvent,
rollupInterval: RollupInterval.None,
hasDurationSummaryField: false,
hasDocs: false,
},
];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/
import { parseInterval } from '@kbn/data-plugin/common';
import { orderBy, last } from 'lodash';
import { ApmDataSource } from '../data_source';
import { ApmDataSourceWithSummary } from '../data_source';
import { ApmDocumentType } from '../document_type';
import { RollupInterval } from '../rollup';

Expand All @@ -28,16 +28,18 @@ export function getPreferredBucketSizeAndDataSource({
sources,
bucketSizeInSeconds,
}: {
sources: ApmDataSource[];
sources: ApmDataSourceWithSummary[];
bucketSizeInSeconds: number;
}): {
source: ApmDataSource;
source: ApmDataSourceWithSummary;
bucketSizeInSeconds: number;
} {
let preferred: ApmDataSource | undefined;
let preferred: ApmDataSourceWithSummary | undefined;

const sourcesWithDocs = sources.filter((source) => source.hasDocs);

const sourcesInPreferredOrder = orderBy(
sources,
sourcesWithDocs,
[
(source) => EVENT_PREFERENCE.indexOf(source.documentType),
(source) => intervalToSeconds(source.rollupInterval),
Expand Down Expand Up @@ -68,6 +70,8 @@ export function getPreferredBucketSizeAndDataSource({
preferred = {
documentType: ApmDocumentType.TransactionEvent,
rollupInterval: RollupInterval.None,
hasDurationSummaryField: false,
hasDocs: true,
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,10 @@ export function TransactionsTable({
type: ApmDocumentType.TransactionMetric,
});

const shouldUseDurationSummary =
latencyAggregationType === 'avg' &&
preferred?.source?.hasDurationSummaryField;

const { data = INITIAL_STATE, status } = useFetcher(
(callApmApi) => {
if (!latencyAggregationType || !transactionType || !preferred) {
Expand All @@ -157,6 +161,7 @@ export function TransactionsTable({
start,
end,
transactionType,
useDurationSummary: shouldUseDurationSummary,
latencyAggregationType:
latencyAggregationType as LatencyAggregationType,
documentType: preferred.source.documentType,
Expand Down Expand Up @@ -227,7 +232,8 @@ export function TransactionsTable({
start &&
end &&
transactionType &&
latencyAggregationType
latencyAggregationType &&
preferred
) {
return callApmApi(
'GET /internal/apm/services/{serviceName}/transactions/groups/detailed_statistics',
Expand All @@ -239,8 +245,11 @@ export function TransactionsTable({
kuery,
start,
end,
numBuckets: 20,
bucketSizeInSeconds: preferred.bucketSizeInSeconds,
transactionType,
documentType: preferred.source.documentType,
rollupInterval: preferred.source.rollupInterval,
useDurationSummary: shouldUseDurationSummary,
latencyAggregationType:
latencyAggregationType as LatencyAggregationType,
transactionNames: JSON.stringify(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,25 @@ const DEFAULTS = {
documentType: ApmDocumentType.ServiceTransactionMetric,
hasDocs: true,
rollupInterval: RollupInterval.OneMinute,
hasDurationSummaryField: true,
},
{
documentType: ApmDocumentType.TransactionMetric,
hasDocs: true,
rollupInterval: RollupInterval.OneMinute,
hasDurationSummaryField: true,
},
{
documentType: ApmDocumentType.TransactionEvent,
hasDocs: true,
rollupInterval: RollupInterval.None,
hasDurationSummaryField: false,
},
{
documentType: ApmDocumentType.ServiceDestinationMetric,
hasDocs: true,
rollupInterval: RollupInterval.None,
hasDurationSummaryField: false,
},
],
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/

import { useMemo } from 'react';
import { ApmDataSource } from '../../common/data_source';
import { ApmDataSourceWithSummary } from '../../common/data_source';
import { ApmDocumentType } from '../../common/document_type';
import { getBucketSize } from '../../common/utils/get_bucket_size';
import { getPreferredBucketSizeAndDataSource } from '../../common/utils/get_preferred_bucket_size_and_data_source';
Expand All @@ -30,7 +30,7 @@ export function usePreferredDataSourceAndBucketSize<
type: TDocumentType;
}): {
bucketSizeInSeconds: number;
source: ApmDataSource<
source: ApmDataSourceWithSummary<
TDocumentType extends ApmDocumentType.ServiceTransactionMetric
?
| ApmDocumentType.ServiceTransactionMetric
Expand Down Expand Up @@ -74,15 +74,13 @@ export function usePreferredDataSourceAndBucketSize<
start: new Date(start).getTime(),
end: new Date(end).getTime(),
}).bucketSize,
sources: sources.filter(
(s) => s.hasDocs && suitableTypes.includes(s.documentType)
),
sources: sources.filter((s) => suitableTypes.includes(s.documentType)),
}
);

return {
bucketSizeInSeconds,
source: source as ApmDataSource<any>,
source: source as ApmDataSourceWithSummary<any>,
};
}, [type, start, end, sources, numBuckets]);
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ export function useTransactionLatencyChartsFetcher({
type: ApmDocumentType.ServiceTransactionMetric,
});

const shouldUseDurationSummary =
latencyAggregationType === 'avg' &&
preferred?.source?.hasDurationSummaryField;

const { data, error, status } = useFetcher(
(callApmApi) => {
if (!transactionType && transactionTypeStatus === FETCH_STATUS.SUCCESS) {
Expand All @@ -73,6 +77,7 @@ export function useTransactionLatencyChartsFetcher({
start,
end,
transactionType,
useDurationSummary: shouldUseDurationSummary,
transactionName: transactionName || undefined,
latencyAggregationType,
offset:
Expand All @@ -89,18 +94,19 @@ export function useTransactionLatencyChartsFetcher({
}
},
[
environment,
kuery,
transactionType,
transactionTypeStatus,
serviceName,
start,
end,
transactionName,
transactionType,
transactionTypeStatus,
latencyAggregationType,
offset,
comparisonEnabled,
preferred,
environment,
kuery,
shouldUseDurationSummary,
transactionName,
comparisonEnabled,
offset,
]
);

Expand Down
Loading

0 comments on commit bb08db9

Please sign in to comment.