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

[Monitoring] Added ability to possibly distinguish between Agent type metrics in APM #95129

Merged
merged 19 commits into from
Apr 26, 2021
Merged
Show file tree
Hide file tree
Changes from all 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
48 changes: 36 additions & 12 deletions x-pack/plugins/monitoring/public/components/apm/apm_metrics.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,19 @@ 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;
config: {
container: boolean;
};
Expand All @@ -47,10 +53,37 @@ const createCharts = (series: unknown[], props: Partial<Props>) => {
});
};

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 = (
<FormattedMessage
id="xpack.monitoring.apm.metrics.agentHeading"
defaultMessage="APM & Fleet Server"
/>
);
}
titles.title = i18n.translate('xpack.monitoring.apm.metrics.topCharts.title', {
defaultMessage: 'APM Server - Resource Usage',
});
titles.heading = (
<FormattedMessage id="xpack.monitoring.apm.metrics.heading" defaultMessage="APM server" />
);
return titles;
};

export const ApmMetrics = ({ stats, metrics, seriesToShow, title, summary, ...props }: Props) => {
if (!metrics) {
return null;
}

const versions = summary?.version ? [summary?.version] : stats.versions;
const isFleetTypeMetric = checkAgentTypeMetric(versions);
const titles = getHeading(isFleetTypeMetric);

const topSeries = [metrics.apm_cpu, metrics.apm_os_load];
const { config } = summary || stats;
topSeries.push(config.container ? metrics.apm_memory_cgroup : metrics.apm_memory);
Expand All @@ -59,24 +92,15 @@ export const ApmMetrics = ({ stats, metrics, seriesToShow, title, summary, ...pr
<EuiPage>
<EuiPageBody>
<EuiScreenReaderOnly>
<h1>
<FormattedMessage
id="xpack.monitoring.apm.metrics.heading"
defaultMessage="APM server"
/>
</h1>
<h1>{titles.heading as FormattedMessage}</h1>
</EuiScreenReaderOnly>
<EuiPanel>
<Status stats={stats} />
</EuiPanel>
<EuiSpacer size="m" />
<EuiPanel>
<EuiTitle>
<h3>
{i18n.translate('xpack.monitoring.apm.metrics.topCharts.nonAgentTitle', {
defaultMessage: 'APM Server - Resource Usage',
})}
</h3>
<h3>{titles.title}</h3>
</EuiTitle>
<EuiSpacer size="m" />
<EuiFlexGroup wrap>{createCharts(topSeries, props)}</EuiFlexGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 = <span data-test-subj="apmsTotal">{total}</span>;
const linkLabel = {};
if (isFleetTypeMetric) {
linkLabel.link = (
<FormattedMessage
id="xpack.monitoring.cluster.overview.apmPanel.agentServersTotalLinkLabel"
defaultMessage="APM & Fleet Servers: {apmsTotal}"
values={{ apmsTotal }}
/>
);
linkLabel.aria = i18n.translate(
'xpack.monitoring.cluster.overview.apmPanel.instancesAndFleetsTotalLinkAriaLabel',
{
defaultMessage: 'APM and Fleet server instances: {apmsTotal}',
values: { apmsTotal },
}
);
}
linkLabel.link = (
<FormattedMessage
id="xpack.monitoring.cluster.overview.apmPanel.serversTotalLinkLabel"
defaultMessage="APM servers: {apmsTotal}"
values={{ apmsTotal }}
/>
);
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(
Expand All @@ -52,13 +115,7 @@ export function ApmPanel(props) {
) : null;

return (
<ClusterItemContainer
{...props}
url="apm"
title={i18n.translate('xpack.monitoring.cluster.overview.apmPanel.apmTitle', {
defaultMessage: 'APM server',
})}
>
<ClusterItemContainer {...props} url="apm" title={getHeadingTitle(isFleetTypeMetric)}>
<EuiFlexGrid columns={4}>
<EuiFlexItem>
<EuiPanel paddingSize="m">
Expand All @@ -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"
>
<FormattedMessage
id="xpack.monitoring.cluster.overview.apmPanel.overviewLinkLabel"
defaultMessage="APM server overview"
/>
{overviewTitle}
</DisabledIfNoDataAndInSetupModeLink>
</h3>
</EuiTitle>
Expand Down Expand Up @@ -121,22 +170,8 @@ export function ApmPanel(props) {
<EuiFlexItem grow={false}>
<EuiTitle size="s">
<h3>
<EuiLink
href={goToInstances()}
aria-label={i18n.translate(
'xpack.monitoring.cluster.overview.apmPanel.instancesTotalLinkAriaLabel',
{
defaultMessage: 'APM server instances: {apmsTotal}',
values: { apmsTotal },
}
)}
data-test-subj="apmListing"
>
<FormattedMessage
id="xpack.monitoring.cluster.overview.apmPanel.serversTotalLinkLabel"
defaultMessage="APM servers: {apmsTotal}"
values={{ apmsTotal }}
/>
<EuiLink href={goToInstances()} aria-label={aria} data-test-subj="apmListing">
{link}
</EuiLink>
</h3>
</EuiTitle>
Expand Down
26 changes: 26 additions & 0 deletions x-pack/plugins/monitoring/public/lib/apm_agent.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* 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('.');
const majorInt = Number(major);
if (majorInt > 7 || (majorInt === 7 && Number(minor) >= 13)) {
return true;
}
});
return false;
};
8 changes: 8 additions & 0 deletions x-pack/plugins/monitoring/server/lib/apm/_apm_stats.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => ({
Expand All @@ -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',
Expand Down Expand Up @@ -101,11 +107,13 @@ export const apmAggResponseHandler = (response) => {
const memRssMax = get(response, 'aggregations.max_mem_rss_total.value', 0);
const memRssMin = get(response, 'aggregations.min_mem_rss_total.value', 0);
const memTotal = get(response, 'aggregations.max_mem_total_total.value', 0);
const versions = get(response, 'aggregations.versions.buckets', []).map(({ key }) => key);

return {
apmTotal,
totalEvents: getDiffCalculation(eventsTotalMax, eventsTotalMin),
memRss: getDiffCalculation(memRssMax, memRssMin),
memTotal,
versions,
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,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 = {
Expand All @@ -23,6 +23,7 @@ export function handleResponse(clusterUuid, response) {
apms: {
total: apmTotal,
},
versions,
};

return {
Expand Down
1 change: 0 additions & 1 deletion x-pack/plugins/translations/translations/ja-JP.json
Original file line number Diff line number Diff line change
Expand Up @@ -15247,7 +15247,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}",
Expand Down
1 change: 0 additions & 1 deletion x-pack/plugins/translations/translations/zh-CN.json
Original file line number Diff line number Diff line change
Expand Up @@ -15472,7 +15472,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}",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@
"config": {
"container": false
},
"timeOfLastEvent": "2018-08-31T13:59:21.199Z"
"timeOfLastEvent": "2018-08-31T13:59:21.199Z",
"versions": [
"7.0.0-alpha1"
]
},
"metrics": {
"apm_cpu": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@
},
"config": {
"container": false
}
},
"versions": [ ]
},
"alerts": {
"alertsMeta": {
Expand Down Expand Up @@ -178,7 +179,8 @@
},
"config": {
"container": false
}
},
"versions": [ ]
},
"alerts": {
"alertsMeta": {
Expand Down Expand Up @@ -274,7 +276,8 @@
},
"config": {
"container": false
}
},
"versions": [ ]
},
"alerts": {
"alertsMeta": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@
},
"config": {
"container": false
}
},
"versions": [ ]
},
"isCcrEnabled": true,
"isPrimary": true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@
},
"config": {
"container": false
}
},
"versions": []
},
"isPrimary": false
}]
Loading