(null);
const { data, status } = useFetcher(
(callApmApi) => {
@@ -30,9 +30,9 @@ export function PageViewsTrend() {
start,
end,
uiFilters: JSON.stringify(uiFilters),
- ...(breakdowns.length > 0
+ ...(breakdown
? {
- breakdowns: JSON.stringify(breakdowns),
+ breakdowns: JSON.stringify(breakdown),
}
: {}),
},
@@ -41,13 +41,9 @@ export function PageViewsTrend() {
}
return Promise.resolve(undefined);
},
- [end, start, serviceName, uiFilters, breakdowns]
+ [end, start, serviceName, uiFilters, breakdown]
);
- const onBreakdownChange = (values: BreakdownItem[]) => {
- setBreakdowns(values);
- };
-
return (
@@ -56,11 +52,10 @@ export function PageViewsTrend() {
{I18LABELS.pageViews}
-
+
diff --git a/x-pack/plugins/apm/server/lib/rum_client/__snapshots__/queries.test.ts.snap b/x-pack/plugins/apm/server/lib/rum_client/__snapshots__/queries.test.ts.snap
index 22b8c226e9026..2cb28d378e8fd 100644
--- a/x-pack/plugins/apm/server/lib/rum_client/__snapshots__/queries.test.ts.snap
+++ b/x-pack/plugins/apm/server/lib/rum_client/__snapshots__/queries.test.ts.snap
@@ -148,7 +148,7 @@ Object {
"body": Object {
"aggs": Object {
"pageViews": Object {
- "aggs": Object {},
+ "aggs": undefined,
"auto_date_histogram": Object {
"buckets": 50,
"field": "@timestamp",
diff --git a/x-pack/plugins/apm/server/lib/rum_client/get_page_view_trends.ts b/x-pack/plugins/apm/server/lib/rum_client/get_page_view_trends.ts
index 23169ddaca534..114137e9fad17 100644
--- a/x-pack/plugins/apm/server/lib/rum_client/get_page_view_trends.ts
+++ b/x-pack/plugins/apm/server/lib/rum_client/get_page_view_trends.ts
@@ -11,7 +11,6 @@ import {
SetupTimeRange,
SetupUIFilters,
} from '../helpers/setup_request';
-import { AggregationInputMap } from '../../../typings/elasticsearch/aggregations';
import { BreakdownItem } from '../../../typings/ui_filters';
export async function getPageViewTrends({
@@ -24,18 +23,9 @@ export async function getPageViewTrends({
const projection = getRumOverviewProjection({
setup,
});
- const breakdownAggs: AggregationInputMap = {};
+ let breakdownItem: BreakdownItem | null = null;
if (breakdowns) {
- const breakdownList: BreakdownItem[] = JSON.parse(breakdowns);
- breakdownList.forEach(({ name, type, fieldName }) => {
- breakdownAggs[name] = {
- terms: {
- field: fieldName,
- size: 9,
- missing: 'Other',
- },
- };
- });
+ breakdownItem = JSON.parse(breakdowns);
}
const params = mergeProjection(projection, {
@@ -50,7 +40,17 @@ export async function getPageViewTrends({
field: '@timestamp',
buckets: 50,
},
- aggs: breakdownAggs,
+ aggs: breakdownItem
+ ? {
+ breakdown: {
+ terms: {
+ field: breakdownItem.fieldName,
+ size: 9,
+ missing: 'Other',
+ },
+ },
+ }
+ : undefined,
},
},
},
@@ -68,19 +68,18 @@ export async function getPageViewTrends({
x: xVal,
y: bCount,
};
-
- Object.keys(breakdownAggs).forEach((bKey) => {
- const categoryBuckets = (bucket[bKey] as any).buckets;
+ if (breakdownItem) {
+ const categoryBuckets = (bucket.breakdown as any).buckets;
categoryBuckets.forEach(
({ key, doc_count: docCount }: { key: string; doc_count: number }) => {
if (key === 'Other') {
- res[key + `(${bKey})`] = docCount;
+ res[key + `(${breakdownItem?.name})`] = docCount;
} else {
res[key] = docCount;
}
}
);
- });
+ }
return res;
});
diff --git a/x-pack/plugins/apm/typings/ui_filters.ts b/x-pack/plugins/apm/typings/ui_filters.ts
index 2a727dda7241d..efba6919778bb 100644
--- a/x-pack/plugins/apm/typings/ui_filters.ts
+++ b/x-pack/plugins/apm/typings/ui_filters.ts
@@ -14,7 +14,6 @@ export type UIFilters = {
export interface BreakdownItem {
name: string;
- count: number;
type: string;
fieldName: string;
selected?: boolean;