From d0c23693a07ccd703f04a5854861272dd22aca2a Mon Sep 17 00:00:00 2001 From: chrisronline Date: Fri, 11 Dec 2020 13:45:06 -0500 Subject: [PATCH] Code clean up --- .../plugins/monitoring/common/formatting.ts | 4 ---- .../monitoring/public/alerts/badge.tsx | 4 ++-- .../public/alerts/lib/filter_alert_states.ts | 23 ------------------- .../public/alerts/lib/replace_tokens.tsx | 2 +- .../monitoring/public/alerts/status.tsx | 2 +- .../components/elasticsearch/node/advanced.js | 4 ++-- .../components/kibana/instances/instances.js | 4 +--- .../public/views/base_controller.js | 1 - .../nodes/get_nodes/get_nodes.js | 5 ++++ .../server/lib/kibana/get_kibanas.js | 6 ++--- 10 files changed, 14 insertions(+), 41 deletions(-) delete mode 100644 x-pack/plugins/monitoring/public/alerts/lib/filter_alert_states.ts diff --git a/x-pack/plugins/monitoring/common/formatting.ts b/x-pack/plugins/monitoring/common/formatting.ts index bad57da47354b..65159f532d2aa 100644 --- a/x-pack/plugins/monitoring/common/formatting.ts +++ b/x-pack/plugins/monitoring/common/formatting.ts @@ -34,16 +34,12 @@ export function shortenPipelineHash(hash: string) { } export function getDateFromNow(timestamp: string | number | Date, tz: string) { - // const timestamp = state.state.ui.triggeredMS; - // const tz = Legacy.shims.uiSettings.get('dateFormat:tz'); return moment(timestamp) .tz(tz === 'Browser' ? moment.tz.guess() : tz) .fromNow(); } export function getCalendar(timestamp: string | number | Date, tz: string) { - // const timestamp = state.state.ui.triggeredMS; - // const tz = Legacy.shims.uiSettings.get('dateFormat:tz'); return moment(timestamp) .tz(tz === 'Browser' ? moment.tz.guess() : tz) .calendar(); diff --git a/x-pack/plugins/monitoring/public/alerts/badge.tsx b/x-pack/plugins/monitoring/public/alerts/badge.tsx index 66df4012b105c..9ac5bee2f611f 100644 --- a/x-pack/plugins/monitoring/public/alerts/badge.tsx +++ b/x-pack/plugins/monitoring/public/alerts/badge.tsx @@ -44,13 +44,13 @@ const GROUP_BY_TYPE = i18n.translate('xpack.monitoring.alerts.badge.groupByType' }); interface Props { - alerts: CommonAlertStatus[]; + alerts: { [alertTypeId: string]: CommonAlertStatus }; stateFilter: (state: AlertState) => boolean; } export const AlertsBadge: React.FC = (props: Props) => { // We do not always have the alerts that each consumer wants due to licensing const { stateFilter = () => true } = props; - const alerts = props.alerts.filter(Boolean); + const alerts = Object.values(props.alerts).filter((alertItem) => Boolean(alertItem?.rawAlert)); const [showPopover, setShowPopover] = React.useState(null); const inSetupMode = isInSetupMode(React.useContext(SetupModeContext)); const alertsContext = React.useContext(AlertsContext); diff --git a/x-pack/plugins/monitoring/public/alerts/lib/filter_alert_states.ts b/x-pack/plugins/monitoring/public/alerts/lib/filter_alert_states.ts deleted file mode 100644 index 3d8071798d77d..0000000000000 --- a/x-pack/plugins/monitoring/public/alerts/lib/filter_alert_states.ts +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one - * or more contributor license agreements. Licensed under the Elastic License; - * you may not use this file except in compliance with the Elastic License. - */ - -import { CommonAlertState, CommonAlertStatus } from '../../../common/types/alerts'; - -export function filterAlertStates( - alerts: { [alertTypeId: string]: CommonAlertStatus }, - filter: (alertState: CommonAlertState) => boolean -) { - return Object.keys(alerts).reduce((accum, alertTypeId) => { - const alertStatus = alerts[alertTypeId]; - return { - ...accum, - [alertTypeId]: { - ...alertStatus, - states: alertStatus.states.filter(filter), - }, - }; - }, []); -} diff --git a/x-pack/plugins/monitoring/public/alerts/lib/replace_tokens.tsx b/x-pack/plugins/monitoring/public/alerts/lib/replace_tokens.tsx index 05bef52183590..b8ac69cbae68a 100644 --- a/x-pack/plugins/monitoring/public/alerts/lib/replace_tokens.tsx +++ b/x-pack/plugins/monitoring/public/alerts/lib/replace_tokens.tsx @@ -19,7 +19,7 @@ import { AlertMessageTokenType } from '../../../common/enums'; import { Legacy } from '../../legacy_shims'; import { getSafeForExternalLink } from '../../lib/get_safe_for_external_link'; -export function replaceTokens(alertMessage: AlertMessage | null): JSX.Element | string | null { +export function replaceTokens(alertMessage: AlertMessage): JSX.Element | string | null { if (!alertMessage) { return null; } diff --git a/x-pack/plugins/monitoring/public/alerts/status.tsx b/x-pack/plugins/monitoring/public/alerts/status.tsx index 36aa623ca415a..4d51069efb972 100644 --- a/x-pack/plugins/monitoring/public/alerts/status.tsx +++ b/x-pack/plugins/monitoring/public/alerts/status.tsx @@ -71,7 +71,7 @@ export const AlertsStatus: React.FC = (props: Props) => { } if (showBadge || inSetupMode) { - return ; + return ; } const severity = atLeastOneDanger ? AlertSeverity.Danger : AlertSeverity.Warning; diff --git a/x-pack/plugins/monitoring/public/components/elasticsearch/node/advanced.js b/x-pack/plugins/monitoring/public/components/elasticsearch/node/advanced.js index 78b5a6f58e238..86e8a7d9095f5 100644 --- a/x-pack/plugins/monitoring/public/components/elasticsearch/node/advanced.js +++ b/x-pack/plugins/monitoring/public/components/elasticsearch/node/advanced.js @@ -20,7 +20,7 @@ import { MonitoringTimeseriesContainer } from '../../chart'; import { FormattedMessage } from '@kbn/i18n/react'; import { AlertsCallout } from '../../../alerts/callout'; -export const AdvancedNode = ({ nodeSummary, metrics, alerts, ...props }) => { +export const AdvancedNode = ({ nodeSummary, metrics, alerts, nodeId, ...props }) => { const metricsToShow = [ metrics.node_gc, metrics.node_gc_time, @@ -54,7 +54,7 @@ export const AdvancedNode = ({ nodeSummary, metrics, alerts, ...props }) => { - + state.nodeId === nodeId} /> {metricsToShow.map((metric, index) => ( diff --git a/x-pack/plugins/monitoring/public/components/kibana/instances/instances.js b/x-pack/plugins/monitoring/public/components/kibana/instances/instances.js index 10ad1634eda86..cde7952aa1839 100644 --- a/x-pack/plugins/monitoring/public/components/kibana/instances/instances.js +++ b/x-pack/plugins/monitoring/public/components/kibana/instances/instances.js @@ -90,9 +90,7 @@ const getColumns = (setupMode, alerts) => { field: 'isOnline', width: '175px', sortable: true, - render: () => { - return ; - }, + render: () => , }, { name: i18n.translate('xpack.monitoring.kibana.listing.statusColumnTitle', { diff --git a/x-pack/plugins/monitoring/public/views/base_controller.js b/x-pack/plugins/monitoring/public/views/base_controller.js index afffc8639a5ac..f9c6cfb6024da 100644 --- a/x-pack/plugins/monitoring/public/views/base_controller.js +++ b/x-pack/plugins/monitoring/public/views/base_controller.js @@ -106,7 +106,6 @@ export class MonitoringViewBaseController { this._isDataInitialized = false; this.reactNodeId = reactNodeId; this.telemetryPageViewTitle = telemetryPageViewTitle || title; - this.alertConfig = alerts; let deferTimer; let zoomInLevel = 0; diff --git a/x-pack/plugins/monitoring/server/lib/elasticsearch/nodes/get_nodes/get_nodes.js b/x-pack/plugins/monitoring/server/lib/elasticsearch/nodes/get_nodes/get_nodes.js index a1e505b857016..ac4fcea6150a0 100644 --- a/x-pack/plugins/monitoring/server/lib/elasticsearch/nodes/get_nodes/get_nodes.js +++ b/x-pack/plugins/monitoring/server/lib/elasticsearch/nodes/get_nodes/get_nodes.js @@ -23,6 +23,11 @@ import { LISTING_METRICS_NAMES, LISTING_METRICS_PATHS } from './nodes_listing_me * only for determining if the node is a Master node. Time-based metric data is * included that adds information such as CPU and JVM stats. * + * @param {Object} req: server request object + * @param {String} esIndexPattern: index pattern for elasticsearch data in monitoring indices + * @param {Object} pageOfNodes: server-side paginated current page of ES nodes + * @param {Object} clusterStats: cluster stats from cluster state document + * @param {Object} nodesShardCount: per-node information about shards * @return {Array} node info combined with metrics for each node from handle_response */ export async function getNodes(req, esIndexPattern, pageOfNodes, clusterStats, nodesShardCount) { diff --git a/x-pack/plugins/monitoring/server/lib/kibana/get_kibanas.js b/x-pack/plugins/monitoring/server/lib/kibana/get_kibanas.js index 1c2246266accb..b65f7770119fc 100644 --- a/x-pack/plugins/monitoring/server/lib/kibana/get_kibanas.js +++ b/x-pack/plugins/monitoring/server/lib/kibana/get_kibanas.js @@ -22,7 +22,7 @@ import { KibanaMetric } from '../metrics'; * - requests * - response times */ -export async function getKibanas(req, kbnIndexPattern, { clusterUuid }) { +export function getKibanas(req, kbnIndexPattern, { clusterUuid }) { checkParam(kbnIndexPattern, 'kbnIndexPattern in getKibanas'); const config = req.server.config(); @@ -63,7 +63,7 @@ export async function getKibanas(req, kbnIndexPattern, { clusterUuid }) { }; const { callWithRequest } = req.server.plugins.elasticsearch.getCluster('monitoring'); - const instances = await callWithRequest(req, 'search', params).then((resp) => { + return callWithRequest(req, 'search', params).then((resp) => { const instances = get(resp, 'hits.hits', []); return instances.map((hit) => { @@ -73,6 +73,4 @@ export async function getKibanas(req, kbnIndexPattern, { clusterUuid }) { }; }); }); - - return instances; }