Skip to content

Commit f1bd3bd

Browse files
committed
Revert "[Monitoring] Cluster state watch to Kibana alerting (#61685)"
This reverts commit ab0cc88.
1 parent 29c1aad commit f1bd3bd

30 files changed

+756
-1570
lines changed

x-pack/legacy/plugins/monitoring/common/constants.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -239,15 +239,11 @@ export const ALERT_TYPE_PREFIX = 'monitoring_';
239239
* This is the alert type id for the license expiration alert
240240
*/
241241
export const ALERT_TYPE_LICENSE_EXPIRATION = `${ALERT_TYPE_PREFIX}alert_type_license_expiration`;
242-
/**
243-
* This is the alert type id for the cluster state alert
244-
*/
245-
export const ALERT_TYPE_CLUSTER_STATE = `${ALERT_TYPE_PREFIX}alert_type_cluster_state`;
246242

247243
/**
248244
* A listing of all alert types
249245
*/
250-
export const ALERT_TYPES = [ALERT_TYPE_LICENSE_EXPIRATION, ALERT_TYPE_CLUSTER_STATE];
246+
export const ALERT_TYPES = [ALERT_TYPE_LICENSE_EXPIRATION];
251247

252248
/**
253249
* Matches the id for the built-in in email action type
@@ -258,7 +254,7 @@ export const ALERT_ACTION_TYPE_EMAIL = '.email';
258254
/**
259255
* The number of alerts that have been migrated
260256
*/
261-
export const NUMBER_OF_MIGRATED_ALERTS = 2;
257+
export const NUMBER_OF_MIGRATED_ALERTS = 1;
262258

263259
/**
264260
* The advanced settings config name for the email address

x-pack/legacy/plugins/monitoring/public/components/alerts/alerts.js

Lines changed: 17 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,10 @@
66

77
import React from 'react';
88
import chrome from '../../np_imports/ui/chrome';
9-
import { capitalize, get } from 'lodash';
9+
import { capitalize } from 'lodash';
1010
import { formatDateTimeLocal } from '../../../common/formatting';
1111
import { formatTimestampToDuration } from '../../../common';
12-
import {
13-
CALCULATE_DURATION_SINCE,
14-
EUI_SORT_DESCENDING,
15-
ALERT_TYPE_LICENSE_EXPIRATION,
16-
ALERT_TYPE_CLUSTER_STATE,
17-
} from '../../../common/constants';
12+
import { CALCULATE_DURATION_SINCE, EUI_SORT_DESCENDING } from '../../../common/constants';
1813
import { mapSeverity } from './map_severity';
1914
import { FormattedAlert } from 'plugins/monitoring/components/alerts/formatted_alert';
2015
import { EuiMonitoringTable } from 'plugins/monitoring/components/table';
@@ -26,8 +21,6 @@ const linkToCategories = {
2621
'elasticsearch/indices': 'Elasticsearch Indices',
2722
'kibana/instances': 'Kibana Instances',
2823
'logstash/instances': 'Logstash Nodes',
29-
[ALERT_TYPE_LICENSE_EXPIRATION]: 'License expiration',
30-
[ALERT_TYPE_CLUSTER_STATE]: 'Cluster state',
3124
};
3225
const getColumns = (kbnUrl, scope, timezone) => [
3326
{
@@ -101,22 +94,19 @@ const getColumns = (kbnUrl, scope, timezone) => [
10194
}),
10295
field: 'message',
10396
sortable: true,
104-
render: (_message, alert) => {
105-
const message = get(alert, 'message.text', get(alert, 'message', ''));
106-
return (
107-
<FormattedAlert
108-
prefix={alert.prefix}
109-
suffix={alert.suffix}
110-
message={message}
111-
metadata={alert.metadata}
112-
changeUrl={target => {
113-
scope.$evalAsync(() => {
114-
kbnUrl.changePath(target);
115-
});
116-
}}
117-
/>
118-
);
119-
},
97+
render: (message, alert) => (
98+
<FormattedAlert
99+
prefix={alert.prefix}
100+
suffix={alert.suffix}
101+
message={message}
102+
metadata={alert.metadata}
103+
changeUrl={target => {
104+
scope.$evalAsync(() => {
105+
kbnUrl.changePath(target);
106+
});
107+
}}
108+
/>
109+
),
120110
},
121111
{
122112
name: i18n.translate('xpack.monitoring.alerts.categoryColumnTitle', {
@@ -158,8 +148,8 @@ const getColumns = (kbnUrl, scope, timezone) => [
158148
export const Alerts = ({ alerts, angular, sorting, pagination, onTableChange }) => {
159149
const alertsFlattened = alerts.map(alert => ({
160150
...alert,
161-
status: get(alert, 'metadata.severity', get(alert, 'severity', 0)),
162-
category: get(alert, 'metadata.link', get(alert, 'type', null)),
151+
status: alert.metadata.severity,
152+
category: alert.metadata.link,
163153
}));
164154

165155
const injector = chrome.dangerouslyGetActiveInjector();

x-pack/legacy/plugins/monitoring/public/components/alerts/status.test.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import React from 'react';
88
import { shallow } from 'enzyme';
99
import { kfetch } from 'ui/kfetch';
1010
import { AlertsStatus, AlertsStatusProps } from './status';
11-
import { ALERT_TYPES } from '../../../common/constants';
11+
import { ALERT_TYPE_PREFIX } from '../../../common/constants';
1212
import { getSetupModeState } from '../../lib/setup_mode';
1313
import { mockUseEffects } from '../../jest.helpers';
1414

@@ -63,7 +63,11 @@ describe('Status', () => {
6363

6464
it('should render a success message if all alerts have been migrated and in setup mode', async () => {
6565
(kfetch as jest.Mock).mockReturnValue({
66-
data: ALERT_TYPES.map(type => ({ alertTypeId: type })),
66+
data: [
67+
{
68+
alertTypeId: ALERT_TYPE_PREFIX,
69+
},
70+
],
6771
});
6872

6973
(getSetupModeState as jest.Mock).mockReturnValue({

x-pack/legacy/plugins/monitoring/public/components/alerts/status.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ export const AlertsStatus: React.FC<AlertsStatusProps> = (props: AlertsStatusPro
142142
);
143143
}
144144

145-
const allMigrated = kibanaAlerts.length >= NUMBER_OF_MIGRATED_ALERTS;
145+
const allMigrated = kibanaAlerts.length === NUMBER_OF_MIGRATED_ALERTS;
146146
if (allMigrated) {
147147
if (setupModeEnabled) {
148148
return (

x-pack/legacy/plugins/monitoring/public/components/cluster/overview/alerts_panel.js

Lines changed: 27 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,14 @@
66

77
import React, { Fragment } from 'react';
88
import moment from 'moment-timezone';
9+
import chrome from '../../../np_imports/ui/chrome';
910
import { FormattedAlert } from 'plugins/monitoring/components/alerts/formatted_alert';
1011
import { mapSeverity } from 'plugins/monitoring/components/alerts/map_severity';
1112
import { formatTimestampToDuration } from '../../../../common/format_timestamp_to_duration';
1213
import {
1314
CALCULATE_DURATION_SINCE,
1415
KIBANA_ALERTING_ENABLED,
16+
ALERT_TYPE_LICENSE_EXPIRATION,
1517
CALCULATE_DURATION_UNTIL,
1618
} from '../../../../common/constants';
1719
import { formatDateTimeLocal } from '../../../../common/formatting';
@@ -29,37 +31,6 @@ import {
2931
EuiLink,
3032
} from '@elastic/eui';
3133

32-
function replaceTokens(alert) {
33-
if (!alert.message.tokens) {
34-
return alert.message.text;
35-
}
36-
37-
let text = alert.message.text;
38-
39-
for (const token of alert.message.tokens) {
40-
if (token.type === 'time') {
41-
text = text.replace(
42-
token.startToken,
43-
token.isRelative
44-
? formatTimestampToDuration(alert.expirationTime, CALCULATE_DURATION_UNTIL)
45-
: moment.tz(alert.expirationTime, moment.tz.guess()).format('LLL z')
46-
);
47-
} else if (token.type === 'link') {
48-
const linkPart = new RegExp(`${token.startToken}(.+?)${token.endToken}`).exec(text);
49-
// TODO: we assume this is at the end, which works for now but will not always work
50-
const nonLinkText = text.replace(linkPart[0], '');
51-
text = (
52-
<Fragment>
53-
{nonLinkText}
54-
<EuiLink href={`#${token.url}`}>{linkPart[1]}</EuiLink>
55-
</Fragment>
56-
);
57-
}
58-
}
59-
60-
return text;
61-
}
62-
6334
export function AlertsPanel({ alerts, changeUrl }) {
6435
const goToAlerts = () => changeUrl('/alerts');
6536

@@ -87,6 +58,9 @@ export function AlertsPanel({ alerts, changeUrl }) {
8758
severityIcon.iconType = 'check';
8859
}
8960

61+
const injector = chrome.dangerouslyGetActiveInjector();
62+
const timezone = injector.get('config').get('dateFormat:tz');
63+
9064
return (
9165
<EuiCallOut
9266
key={`alert-item-${index}`}
@@ -109,7 +83,7 @@ export function AlertsPanel({ alerts, changeUrl }) {
10983
id="xpack.monitoring.cluster.overview.alertsPanel.lastCheckedTimeText"
11084
defaultMessage="Last checked {updateDateTime} (triggered {duration} ago)"
11185
values={{
112-
updateDateTime: formatDateTimeLocal(item.update_timestamp),
86+
updateDateTime: formatDateTimeLocal(item.update_timestamp, timezone),
11387
duration: formatTimestampToDuration(item.timestamp, CALCULATE_DURATION_SINCE),
11488
}}
11589
/>
@@ -122,7 +96,14 @@ export function AlertsPanel({ alerts, changeUrl }) {
12296
const alertsList = KIBANA_ALERTING_ENABLED
12397
? alerts.map((alert, idx) => {
12498
const callOutProps = mapSeverity(alert.severity);
125-
const message = replaceTokens(alert);
99+
let message = alert.message
100+
// scan message prefix and replace relative times
101+
// \w: Matches any alphanumeric character from the basic Latin alphabet, including the underscore. Equivalent to [A-Za-z0-9_].
102+
.replace(
103+
'#relative',
104+
formatTimestampToDuration(alert.expirationTime, CALCULATE_DURATION_UNTIL)
105+
)
106+
.replace('#absolute', moment.tz(alert.expirationTime, moment.tz.guess()).format('LLL z'));
126107

127108
if (!alert.isFiring) {
128109
callOutProps.title = i18n.translate(
@@ -137,30 +118,22 @@ export function AlertsPanel({ alerts, changeUrl }) {
137118
);
138119
callOutProps.color = 'success';
139120
callOutProps.iconType = 'check';
121+
} else {
122+
if (alert.type === ALERT_TYPE_LICENSE_EXPIRATION) {
123+
message = (
124+
<Fragment>
125+
{message}
126+
&nbsp;
127+
<EuiLink href="#license">Please update your license</EuiLink>
128+
</Fragment>
129+
);
130+
}
140131
}
141132

142133
return (
143-
<Fragment key={idx}>
144-
<EuiCallOut {...callOutProps}>
145-
<p>{message}</p>
146-
<EuiText size="xs">
147-
<p data-test-subj="alertMeta" className="monCallout--meta">
148-
<FormattedMessage
149-
id="xpack.monitoring.cluster.overview.alertsPanel.lastCheckedTimeText"
150-
defaultMessage="Last checked {updateDateTime} (triggered {duration} ago)"
151-
values={{
152-
updateDateTime: formatDateTimeLocal(alert.lastCheckedMS),
153-
duration: formatTimestampToDuration(
154-
alert.triggeredMS,
155-
CALCULATE_DURATION_SINCE
156-
),
157-
}}
158-
/>
159-
</p>
160-
</EuiText>
161-
</EuiCallOut>
162-
<EuiSpacer />
163-
</Fragment>
134+
<EuiCallOut key={idx} {...callOutProps}>
135+
<p>{message}</p>
136+
</EuiCallOut>
164137
);
165138
})
166139
: alerts.map((item, index) => (

x-pack/legacy/plugins/monitoring/public/views/alerts/index.js

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -18,37 +18,25 @@ import { Alerts } from '../../components/alerts';
1818
import { MonitoringViewBaseEuiTableController } from '../base_eui_table_controller';
1919
import { FormattedMessage } from '@kbn/i18n/react';
2020
import { EuiPage, EuiPageBody, EuiPageContent, EuiSpacer, EuiLink } from '@elastic/eui';
21-
import { CODE_PATH_ALERTS, KIBANA_ALERTING_ENABLED } from '../../../common/constants';
21+
import { CODE_PATH_ALERTS } from '../../../common/constants';
2222

2323
function getPageData($injector) {
2424
const globalState = $injector.get('globalState');
2525
const $http = $injector.get('$http');
2626
const Private = $injector.get('Private');
27-
const url = KIBANA_ALERTING_ENABLED
28-
? `../api/monitoring/v1/alert_status`
29-
: `../api/monitoring/v1/clusters/${globalState.cluster_uuid}/legacy_alerts`;
27+
const url = `../api/monitoring/v1/clusters/${globalState.cluster_uuid}/legacy_alerts`;
3028

3129
const timeBounds = timefilter.getBounds();
32-
const data = {
33-
timeRange: {
34-
min: timeBounds.min.toISOString(),
35-
max: timeBounds.max.toISOString(),
36-
},
37-
};
38-
39-
if (!KIBANA_ALERTING_ENABLED) {
40-
data.ccs = globalState.ccs;
41-
}
4230

4331
return $http
44-
.post(url, data)
45-
.then(response => {
46-
const result = get(response, 'data', []);
47-
if (KIBANA_ALERTING_ENABLED) {
48-
return result.alerts;
49-
}
50-
return result;
32+
.post(url, {
33+
ccs: globalState.ccs,
34+
timeRange: {
35+
min: timeBounds.min.toISOString(),
36+
max: timeBounds.max.toISOString(),
37+
},
5138
})
39+
.then(response => get(response, 'data', []))
5240
.catch(err => {
5341
const ajaxErrorHandlers = Private(ajaxErrorHandlersProvider);
5442
return ajaxErrorHandlers(err);

x-pack/plugins/monitoring/common/constants.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -239,15 +239,11 @@ export const ALERT_TYPE_PREFIX = 'monitoring_';
239239
* This is the alert type id for the license expiration alert
240240
*/
241241
export const ALERT_TYPE_LICENSE_EXPIRATION = `${ALERT_TYPE_PREFIX}alert_type_license_expiration`;
242-
/**
243-
* This is the alert type id for the cluster state alert
244-
*/
245-
export const ALERT_TYPE_CLUSTER_STATE = `${ALERT_TYPE_PREFIX}alert_type_cluster_state`;
246242

247243
/**
248244
* A listing of all alert types
249245
*/
250-
export const ALERT_TYPES = [ALERT_TYPE_LICENSE_EXPIRATION, ALERT_TYPE_CLUSTER_STATE];
246+
export const ALERT_TYPES = [ALERT_TYPE_LICENSE_EXPIRATION];
251247

252248
/**
253249
* Matches the id for the built-in in email action type
@@ -258,7 +254,7 @@ export const ALERT_ACTION_TYPE_EMAIL = '.email';
258254
/**
259255
* The number of alerts that have been migrated
260256
*/
261-
export const NUMBER_OF_MIGRATED_ALERTS = 2;
257+
export const NUMBER_OF_MIGRATED_ALERTS = 1;
262258

263259
/**
264260
* The advanced settings config name for the email address

0 commit comments

Comments
 (0)