Skip to content

Commit

Permalink
Code clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisronline committed Dec 11, 2020
1 parent e4f7d04 commit d0c2369
Show file tree
Hide file tree
Showing 10 changed files with 14 additions and 41 deletions.
4 changes: 0 additions & 4 deletions x-pack/plugins/monitoring/common/formatting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
4 changes: 2 additions & 2 deletions x-pack/plugins/monitoring/public/alerts/badge.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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: 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<AlertSeverity | boolean | null>(null);
const inSetupMode = isInSetupMode(React.useContext(SetupModeContext));
const alertsContext = React.useContext(AlertsContext);
Expand Down
23 changes: 0 additions & 23 deletions x-pack/plugins/monitoring/public/alerts/lib/filter_alert_states.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/monitoring/public/alerts/status.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export const AlertsStatus: React.FC<Props> = (props: Props) => {
}

if (showBadge || inSetupMode) {
return <AlertsBadge alerts={Object.values(alerts)} stateFilter={stateFilter} />;
return <AlertsBadge alerts={alerts} stateFilter={stateFilter} />;
}

const severity = atLeastOneDanger ? AlertSeverity.Danger : AlertSeverity.Warning;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -54,7 +54,7 @@ export const AdvancedNode = ({ nodeSummary, metrics, alerts, ...props }) => {
<NodeDetailStatus stats={nodeSummary} alerts={alerts} />
</EuiPanel>
<EuiSpacer size="m" />
<AlertsCallout alerts={alerts} />
<AlertsCallout alerts={alerts} stateFilter={(state) => state.nodeId === nodeId} />
<EuiPageContent>
<EuiFlexGrid columns={2} gutterSize="s">
{metricsToShow.map((metric, index) => (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,7 @@ const getColumns = (setupMode, alerts) => {
field: 'isOnline',
width: '175px',
sortable: true,
render: () => {
return <AlertsStatus showBadge={true} alerts={alerts} />;
},
render: () => <AlertsStatus showBadge={true} alerts={alerts} />,
},
{
name: i18n.translate('xpack.monitoring.kibana.listing.statusColumnTitle', {
Expand Down
1 change: 0 additions & 1 deletion x-pack/plugins/monitoring/public/views/base_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
6 changes: 2 additions & 4 deletions x-pack/plugins/monitoring/server/lib/kibana/get_kibanas.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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) => {
Expand All @@ -73,6 +73,4 @@ export async function getKibanas(req, kbnIndexPattern, { clusterUuid }) {
};
});
});

return instances;
}

0 comments on commit d0c2369

Please sign in to comment.