From 7a32fb360edca923c8acaf1d663963b314115574 Mon Sep 17 00:00:00 2001 From: Igor Zaytsev Date: Mon, 5 Apr 2021 20:54:58 -0400 Subject: [PATCH 01/11] Added version and cloud check --- .../public/components/apm/apm_metrics.tsx | 46 ++++++-- .../components/cluster/overview/apm_panel.js | 103 ++++++++++++------ .../monitoring/public/lib/apm_agent.ts | 25 +++++ .../monitoring/server/lib/apm/_apm_stats.js | 8 ++ .../server/lib/apm/get_apms_for_clusters.js | 3 +- 5 files changed, 138 insertions(+), 47 deletions(-) create mode 100644 x-pack/plugins/monitoring/public/lib/apm_agent.ts diff --git a/x-pack/plugins/monitoring/public/components/apm/apm_metrics.tsx b/x-pack/plugins/monitoring/public/components/apm/apm_metrics.tsx index 7efddcfe66b0b..eca58b8fc5f1e 100644 --- a/x-pack/plugins/monitoring/public/components/apm/apm_metrics.tsx +++ b/x-pack/plugins/monitoring/public/components/apm/apm_metrics.tsx @@ -24,12 +24,18 @@ import { FormattedMessage } from '@kbn/i18n/react'; import { MonitoringTimeseriesContainer } from '../chart'; // @ts-ignore could not find declaration file import { Status } from './instance/status'; +import { checkAgentTypeMetric } from '../../lib/apm_agent'; +interface TitleType { + title?: string; + heading?: unknown; +} interface Props { - stats: unknown; + stats: { versions: string[]; [key: string]: unknown }; metrics: { [key: string]: unknown }; seriesToShow: unknown[]; title: string; + summary?: { version: string }; } const createCharts = (series: unknown[], props: Partial) => { @@ -42,19 +48,39 @@ const createCharts = (series: unknown[], props: Partial) => { }); }; +const getHeading = (isFleetTypeMetric: boolean) => { + const titles: TitleType = {}; + if (isFleetTypeMetric) { + titles.title = i18n.translate('xpack.monitoring.apm.metrics.topCharts.agentTitle', { + defaultMessage: 'APM & Fleet Server - Resource Usage', + }); + titles.heading = ( + + ); + } + titles.title = i18n.translate('xpack.monitoring.apm.metrics.topCharts.title', { + defaultMessage: 'APM Server - Resource Usage', + }); + titles.heading = ( + + ); + return titles; +}; + export const ApmMetrics = ({ stats, metrics, seriesToShow, title, ...props }: Props) => { const topSeries = [metrics.apm_cpu, metrics.apm_memory, metrics.apm_os_load]; + const versions = props.summary?.version ? [props.summary?.version] : stats.versions; + const isFleetTypeMetric = checkAgentTypeMetric(versions); + const titles = getHeading(isFleetTypeMetric); return ( -

- -

+

{titles.heading as FormattedMessage}

@@ -62,11 +88,7 @@ export const ApmMetrics = ({ stats, metrics, seriesToShow, title, ...props }: Pr -

- {i18n.translate('xpack.monitoring.apm.metrics.topCharts.nonAgentTitle', { - defaultMessage: 'APM Server - Resource Usage', - })} -

+

{titles.title}

{createCharts(topSeries, props)} diff --git a/x-pack/plugins/monitoring/public/components/cluster/overview/apm_panel.js b/x-pack/plugins/monitoring/public/components/cluster/overview/apm_panel.js index a8b71bbfb234d..64afe8988e8bf 100644 --- a/x-pack/plugins/monitoring/public/components/cluster/overview/apm_panel.js +++ b/x-pack/plugins/monitoring/public/components/cluster/overview/apm_panel.js @@ -30,15 +30,78 @@ import { SetupModeTooltip } from '../../setup_mode/tooltip'; import { getSafeForExternalLink } from '../../../lib/get_safe_for_external_link'; import { isSetupModeFeatureEnabled } from '../../../lib/setup_mode'; import { SetupModeFeature } from '../../../../common/enums'; +import { checkAgentTypeMetric } from '../../../lib/apm_agent'; + +const getServerTitle = (isFleetTypeMetric, total) => { + const apmsTotal = {total}; + const linkLabel = {}; + if (isFleetTypeMetric) { + linkLabel.link = ( + + ); + linkLabel.aria = i18n.translate( + 'xpack.monitoring.cluster.overview.apmPanel.instancesAndFleetsTotalLinkAriaLabel', + { + defaultMessage: 'APM and Fleet server instances: {apmsTotal}', + values: { apmsTotal }, + } + ); + } + linkLabel.link = ( + + ); + linkLabel.aria = i18n.translate( + 'xpack.monitoring.cluster.overview.apmPanel.instancesTotalLinkAriaLabel', + { + defaultMessage: 'APM server instances: {apmsTotal}', + values: { apmsTotal }, + } + ); + + return linkLabel; +}; + +const getOverviewTitle = (isFleetTypeMetric) => { + if (isFleetTypeMetric) { + return i18n.translate('xpack.monitoring.cluster.overview.apmPanel.overviewFleetLinkLabel', { + defaultMessage: 'APM & Fleet server overview', + }); + } + return i18n.translate('xpack.monitoring.cluster.overview.apmPanel.overviewLinkLabel', { + defaultMessage: 'APM server overview', + }); +}; + +const getHeadingTitle = (isFleetTypeMetric) => { + if (isFleetTypeMetric) { + return i18n.translate('xpack.monitoring.cluster.overview.apmPanel.apmFleetTitle', { + defaultMessage: 'APM & Fleet server', + }); + } + return i18n.translate('xpack.monitoring.cluster.overview.apmPanel.apmTitle', { + defaultMessage: 'APM server', + }); +}; export function ApmPanel(props) { - const { setupMode } = props; + const { setupMode, versions } = props; const apmsTotal = get(props, 'apms.total') || 0; // Do not show if we are not in setup mode if (apmsTotal === 0 && !setupMode.enabled) { return null; } + const isFleetTypeMetric = checkAgentTypeMetric(versions); + const { link, aria } = getServerTitle(isFleetTypeMetric, apmsTotal); + const overviewTitle = getOverviewTitle(isFleetTypeMetric); const goToInstances = () => getSafeForExternalLink('#/apm/instances'); const setupModeData = get(setupMode.data, 'apm'); const setupModeMetricbeatMigrationTooltip = isSetupModeFeatureEnabled( @@ -52,13 +115,7 @@ export function ApmPanel(props) { ) : null; return ( - + @@ -68,18 +125,10 @@ export function ApmPanel(props) { setupModeEnabled={setupMode.enabled} setupModeData={setupModeData} href={getSafeForExternalLink('#/apm')} - aria-label={i18n.translate( - 'xpack.monitoring.cluster.overview.apmPanel.overviewLinkAriaLabel', - { - defaultMessage: 'APM server overview', - } - )} + aria-label={overviewTitle} data-test-subj="apmOverview" > - + {overviewTitle} @@ -121,22 +170,8 @@ export function ApmPanel(props) {

- - + + {link}

diff --git a/x-pack/plugins/monitoring/public/lib/apm_agent.ts b/x-pack/plugins/monitoring/public/lib/apm_agent.ts new file mode 100644 index 0000000000000..aeef966e8e70e --- /dev/null +++ b/x-pack/plugins/monitoring/public/lib/apm_agent.ts @@ -0,0 +1,25 @@ +/* + * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one + * or more contributor license agreements. Licensed under the Elastic License + * 2.0; you may not use this file except in compliance with the Elastic License + * 2.0. + */ + +import { Legacy } from '../legacy_shims'; + +/** + * Possible temporary work arround to establish if APM might also be monitoring fleet: + * https://github.com/elastic/kibana/pull/95129/files#r604815886 + */ +export const checkAgentTypeMetric = (versions?: string[]) => { + if (!Legacy.shims.isCloud || !versions) { + return false; + } + versions.forEach((version) => { + const [major, minor] = version.split('.'); + if (Number(major) >= 7 && Number(minor) >= 13) { + return true; + } + }); + return false; +}; diff --git a/x-pack/plugins/monitoring/server/lib/apm/_apm_stats.js b/x-pack/plugins/monitoring/server/lib/apm/_apm_stats.js index ffd4ae77fa0f2..fe17aba9304e0 100644 --- a/x-pack/plugins/monitoring/server/lib/apm/_apm_stats.js +++ b/x-pack/plugins/monitoring/server/lib/apm/_apm_stats.js @@ -24,6 +24,7 @@ export const apmAggFilterPath = [ 'aggregations.min_mem_rss_total.value', 'aggregations.max_mem_rss_total.value', 'aggregations.max_mem_total_total.value', + 'aggregations.versions.buckets', ]; export const apmUuidsAgg = (maxBucketSize) => ({ @@ -33,6 +34,11 @@ export const apmUuidsAgg = (maxBucketSize) => ({ precision_threshold: 10000, }, }, + versions: { + terms: { + field: 'beats_stats.beat.version', + }, + }, ephemeral_ids: { terms: { field: 'beats_stats.metrics.beat.info.ephemeral_id', @@ -101,11 +107,13 @@ export const apmAggResponseHandler = (response) => { const memRssMax = get(response, 'aggregations.max_mem_rss_total.value', null); const memRssMin = get(response, 'aggregations.min_mem_rss_total.value', null); const memTotal = get(response, 'aggregations.max_mem_total_total.value', null); + const versions = get(response, 'aggregations.versions.buckets', []).map(({ key }) => key); return { apmTotal, totalEvents: getDiffCalculation(eventsTotalMax, eventsTotalMin), memRss: getDiffCalculation(memRssMax, memRssMin), memTotal, + versions, }; }; diff --git a/x-pack/plugins/monitoring/server/lib/apm/get_apms_for_clusters.js b/x-pack/plugins/monitoring/server/lib/apm/get_apms_for_clusters.js index 446cf19adf2a0..f9d297a289f14 100644 --- a/x-pack/plugins/monitoring/server/lib/apm/get_apms_for_clusters.js +++ b/x-pack/plugins/monitoring/server/lib/apm/get_apms_for_clusters.js @@ -12,7 +12,7 @@ import { apmAggResponseHandler, apmUuidsAgg, apmAggFilterPath } from './_apm_sta import { getTimeOfLastEvent } from './_get_time_of_last_event'; export function handleResponse(clusterUuid, response) { - const { apmTotal, totalEvents, memRss, memTotal } = apmAggResponseHandler(response); + const { apmTotal, totalEvents, memRss, memTotal, versions } = apmAggResponseHandler(response); // combine stats const stats = { @@ -22,6 +22,7 @@ export function handleResponse(clusterUuid, response) { apms: { total: apmTotal, }, + versions, }; return { From ce1f28aab956807683e8779263f5ecea8232f72b Mon Sep 17 00:00:00 2001 From: Igor Zaytsev Date: Mon, 5 Apr 2021 21:39:42 -0400 Subject: [PATCH 02/11] Fixed tests --- x-pack/plugins/translations/translations/ja-JP.json | 1 - x-pack/plugins/translations/translations/zh-CN.json | 1 - 2 files changed, 2 deletions(-) diff --git a/x-pack/plugins/translations/translations/ja-JP.json b/x-pack/plugins/translations/translations/ja-JP.json index dc038c1a7959d..64a5290a8851a 100644 --- a/x-pack/plugins/translations/translations/ja-JP.json +++ b/x-pack/plugins/translations/translations/ja-JP.json @@ -15476,7 +15476,6 @@ "xpack.monitoring.cluster.overview.apmPanel.lastEventDescription": "{timeOfLastEvent} 前", "xpack.monitoring.cluster.overview.apmPanel.lastEventLabel": "最後のイベント", "xpack.monitoring.cluster.overview.apmPanel.memoryUsageLabel": "メモリー使用状況", - "xpack.monitoring.cluster.overview.apmPanel.overviewLinkAriaLabel": "APM Server 概要", "xpack.monitoring.cluster.overview.apmPanel.overviewLinkLabel": "APM Server 概要", "xpack.monitoring.cluster.overview.apmPanel.processedEventsLabel": "処理済みのイベント", "xpack.monitoring.cluster.overview.apmPanel.serversTotalLinkLabel": "APM Server:{apmsTotal}", diff --git a/x-pack/plugins/translations/translations/zh-CN.json b/x-pack/plugins/translations/translations/zh-CN.json index 117c33a286d88..f67c91803e018 100644 --- a/x-pack/plugins/translations/translations/zh-CN.json +++ b/x-pack/plugins/translations/translations/zh-CN.json @@ -15702,7 +15702,6 @@ "xpack.monitoring.cluster.overview.apmPanel.lastEventDescription": "{timeOfLastEvent}前", "xpack.monitoring.cluster.overview.apmPanel.lastEventLabel": "最后事件", "xpack.monitoring.cluster.overview.apmPanel.memoryUsageLabel": "内存利用率", - "xpack.monitoring.cluster.overview.apmPanel.overviewLinkAriaLabel": "APM 服务器概览", "xpack.monitoring.cluster.overview.apmPanel.overviewLinkLabel": "APM 服务器概览", "xpack.monitoring.cluster.overview.apmPanel.processedEventsLabel": "已处理事件", "xpack.monitoring.cluster.overview.apmPanel.serversTotalLinkLabel": "APM 服务器:{apmsTotal}", From 838bc6c21a4b02b7a3813228e007d69a8a9ff24d Mon Sep 17 00:00:00 2001 From: Igor Zaytsev Date: Wed, 7 Apr 2021 12:47:28 -0400 Subject: [PATCH 03/11] Code review feedback --- x-pack/plugins/monitoring/public/lib/apm_agent.ts | 3 ++- .../apis/monitoring/apm/fixtures/cluster.json | 5 ++++- .../apis/monitoring/cluster/fixtures/overview.json | 5 ++++- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/x-pack/plugins/monitoring/public/lib/apm_agent.ts b/x-pack/plugins/monitoring/public/lib/apm_agent.ts index aeef966e8e70e..8884557782126 100644 --- a/x-pack/plugins/monitoring/public/lib/apm_agent.ts +++ b/x-pack/plugins/monitoring/public/lib/apm_agent.ts @@ -17,7 +17,8 @@ export const checkAgentTypeMetric = (versions?: string[]) => { } versions.forEach((version) => { const [major, minor] = version.split('.'); - if (Number(major) >= 7 && Number(minor) >= 13) { + const majorInt = Number(major); + if (majorInt > 7 || (majorInt === 7 && Number(minor) >= 13)) { return true; } }); diff --git a/x-pack/test/api_integration/apis/monitoring/apm/fixtures/cluster.json b/x-pack/test/api_integration/apis/monitoring/apm/fixtures/cluster.json index f56440f2e4c4f..34fbe0581d8e8 100644 --- a/x-pack/test/api_integration/apis/monitoring/apm/fixtures/cluster.json +++ b/x-pack/test/api_integration/apis/monitoring/apm/fixtures/cluster.json @@ -9,7 +9,10 @@ "config": { "container": false }, - "timeOfLastEvent": "2018-08-31T13:59:21.201Z" + "timeOfLastEvent": "2018-08-31T13:59:21.201Z", + "versions": [ + "7.0.0-alpha1" + ] }, "metrics": { "apm_cpu": [ diff --git a/x-pack/test/api_integration/apis/monitoring/cluster/fixtures/overview.json b/x-pack/test/api_integration/apis/monitoring/cluster/fixtures/overview.json index 8fed03d9a8a34..5ca02bb9c20bd 100644 --- a/x-pack/test/api_integration/apis/monitoring/cluster/fixtures/overview.json +++ b/x-pack/test/api_integration/apis/monitoring/cluster/fixtures/overview.json @@ -115,7 +115,10 @@ }, "config": { "container": false - } + }, + "versions": [ + "7.0.0-alpha1" + ] }, "isCcrEnabled": true, "isPrimary": true, From e5629b244c8453695e76c73dd3376ef2b5ec8669 Mon Sep 17 00:00:00 2001 From: Igor Zaytsev Date: Mon, 19 Apr 2021 05:56:52 -0400 Subject: [PATCH 04/11] Fixed tests --- .../apis/monitoring/cluster/fixtures/multicluster.json | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/x-pack/test/api_integration/apis/monitoring/cluster/fixtures/multicluster.json b/x-pack/test/api_integration/apis/monitoring/cluster/fixtures/multicluster.json index 027dc898cacb5..55a5f526d8567 100644 --- a/x-pack/test/api_integration/apis/monitoring/cluster/fixtures/multicluster.json +++ b/x-pack/test/api_integration/apis/monitoring/cluster/fixtures/multicluster.json @@ -101,7 +101,8 @@ }, "config": { "container": false - } + }, + "versions": [] }, "alerts": { "alertsMeta": { @@ -216,7 +217,8 @@ }, "config": { "container": false - } + }, + "versions": [] }, "alerts": { "alertsMeta": { @@ -331,7 +333,8 @@ }, "config": { "container": false - } + }, + "versions": [] }, "alerts": { "alertsMeta": { From 49eb9935cc195373a0fa8fe735d0ef9a9da1c759 Mon Sep 17 00:00:00 2001 From: Igor Zaytsev Date: Mon, 19 Apr 2021 19:00:49 -0400 Subject: [PATCH 05/11] added versions --- .../apis/monitoring/cluster/fixtures/multicluster.json | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/x-pack/test/api_integration/apis/monitoring/cluster/fixtures/multicluster.json b/x-pack/test/api_integration/apis/monitoring/cluster/fixtures/multicluster.json index 55a5f526d8567..50b5ce377c208 100644 --- a/x-pack/test/api_integration/apis/monitoring/cluster/fixtures/multicluster.json +++ b/x-pack/test/api_integration/apis/monitoring/cluster/fixtures/multicluster.json @@ -334,7 +334,9 @@ "config": { "container": false }, - "versions": [] + "versions": [ + "7.0.0-alpha1" + ] }, "alerts": { "alertsMeta": { From b9b9e363bb273e2e0db169003e775f1cd6e1ec80 Mon Sep 17 00:00:00 2001 From: Igor Zaytsev Date: Tue, 20 Apr 2021 08:12:04 -0400 Subject: [PATCH 06/11] added version --- .../apis/monitoring/cluster/fixtures/multicluster.json | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/x-pack/test/api_integration/apis/monitoring/cluster/fixtures/multicluster.json b/x-pack/test/api_integration/apis/monitoring/cluster/fixtures/multicluster.json index 50b5ce377c208..742fc089be37d 100644 --- a/x-pack/test/api_integration/apis/monitoring/cluster/fixtures/multicluster.json +++ b/x-pack/test/api_integration/apis/monitoring/cluster/fixtures/multicluster.json @@ -218,7 +218,9 @@ "config": { "container": false }, - "versions": [] + "versions": [ + "7.0.0-alpha1" + ] }, "alerts": { "alertsMeta": { From 293efd8ea1b476d8f9ba4085d871465339ada948 Mon Sep 17 00:00:00 2001 From: Igor Zaytsev Date: Tue, 20 Apr 2021 09:59:30 -0400 Subject: [PATCH 07/11] ... --- .../apis/monitoring/cluster/fixtures/multicluster.json | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/x-pack/test/api_integration/apis/monitoring/cluster/fixtures/multicluster.json b/x-pack/test/api_integration/apis/monitoring/cluster/fixtures/multicluster.json index 742fc089be37d..91d6cd6496bbe 100644 --- a/x-pack/test/api_integration/apis/monitoring/cluster/fixtures/multicluster.json +++ b/x-pack/test/api_integration/apis/monitoring/cluster/fixtures/multicluster.json @@ -102,7 +102,9 @@ "config": { "container": false }, - "versions": [] + "versions": [ + "7.0.0-alpha1" + ] }, "alerts": { "alertsMeta": { From 21c32796bacf175672556e644dd87fdf15ff2673 Mon Sep 17 00:00:00 2001 From: Igor Zaytsev Date: Tue, 20 Apr 2021 11:15:45 -0400 Subject: [PATCH 08/11] Removed default version --- .../monitoring/cluster/fixtures/multicluster.json | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/x-pack/test/api_integration/apis/monitoring/cluster/fixtures/multicluster.json b/x-pack/test/api_integration/apis/monitoring/cluster/fixtures/multicluster.json index 91d6cd6496bbe..1397179b4b929 100644 --- a/x-pack/test/api_integration/apis/monitoring/cluster/fixtures/multicluster.json +++ b/x-pack/test/api_integration/apis/monitoring/cluster/fixtures/multicluster.json @@ -102,9 +102,7 @@ "config": { "container": false }, - "versions": [ - "7.0.0-alpha1" - ] + "versions": [ ] }, "alerts": { "alertsMeta": { @@ -220,9 +218,7 @@ "config": { "container": false }, - "versions": [ - "7.0.0-alpha1" - ] + "versions": [ ] }, "alerts": { "alertsMeta": { @@ -338,9 +334,7 @@ "config": { "container": false }, - "versions": [ - "7.0.0-alpha1" - ] + "versions": [ ] }, "alerts": { "alertsMeta": { From 755d346dc61a03bc3fdfd297641149700a533f76 Mon Sep 17 00:00:00 2001 From: Igor Zaytsev Date: Tue, 20 Apr 2021 13:17:03 -0400 Subject: [PATCH 09/11] .. --- .../apis/monitoring/cluster/fixtures/overview.json | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/x-pack/test/api_integration/apis/monitoring/cluster/fixtures/overview.json b/x-pack/test/api_integration/apis/monitoring/cluster/fixtures/overview.json index 5ca02bb9c20bd..57e90d79a6f8e 100644 --- a/x-pack/test/api_integration/apis/monitoring/cluster/fixtures/overview.json +++ b/x-pack/test/api_integration/apis/monitoring/cluster/fixtures/overview.json @@ -116,9 +116,7 @@ "config": { "container": false }, - "versions": [ - "7.0.0-alpha1" - ] + "versions": [ ] }, "isCcrEnabled": true, "isPrimary": true, From 866cbd36c5f16b95972ee9326c22cbc0d33d85be Mon Sep 17 00:00:00 2001 From: Igor Zaytsev Date: Mon, 26 Apr 2021 02:42:09 -0400 Subject: [PATCH 10/11] Fixed test --- .../monitoring/standalone_cluster/fixtures/clusters.json | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/x-pack/test/api_integration/apis/monitoring/standalone_cluster/fixtures/clusters.json b/x-pack/test/api_integration/apis/monitoring/standalone_cluster/fixtures/clusters.json index 0034199325e5c..8f20dce44ee8a 100644 --- a/x-pack/test/api_integration/apis/monitoring/standalone_cluster/fixtures/clusters.json +++ b/x-pack/test/api_integration/apis/monitoring/standalone_cluster/fixtures/clusters.json @@ -82,7 +82,8 @@ }, "config": { "container": false - } + }, + "versions": [] }, "alerts": { "alertsMeta": { @@ -158,7 +159,8 @@ }, "config": { "container": false - } + }, + "versions": [] }, "alerts": { "alertsMeta": { From bf6e7344913d5a21391fc21df0ed515104b8afb9 Mon Sep 17 00:00:00 2001 From: Igor Zaytsev Date: Mon, 26 Apr 2021 08:41:09 -0400 Subject: [PATCH 11/11] fixed tests --- .../apis/monitoring/standalone_cluster/fixtures/cluster.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/x-pack/test/api_integration/apis/monitoring/standalone_cluster/fixtures/cluster.json b/x-pack/test/api_integration/apis/monitoring/standalone_cluster/fixtures/cluster.json index e3ed40b197cc1..3e590656753f1 100644 --- a/x-pack/test/api_integration/apis/monitoring/standalone_cluster/fixtures/cluster.json +++ b/x-pack/test/api_integration/apis/monitoring/standalone_cluster/fixtures/cluster.json @@ -55,7 +55,8 @@ }, "config": { "container": false - } + }, + "versions": [] }, "isPrimary": false }]