Skip to content

Commit d01598d

Browse files
authored
[Monitoring] Fix UI error when alerting is not available (#77179)
* Ensure we always pass this structure down to avoid any errors in the UI * Fix tests and also fix inaccurate boolean states * Fix fixture
1 parent 4c23669 commit d01598d

File tree

3 files changed

+64
-56
lines changed

3 files changed

+64
-56
lines changed

x-pack/plugins/monitoring/server/lib/cluster/get_clusters_from_request.js

Lines changed: 61 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -119,67 +119,75 @@ export async function getClustersFromRequest(
119119
// add alerts data
120120
if (isInCodePath(codePaths, [CODE_PATH_ALERTS])) {
121121
const alertsClient = req.getAlertsClient();
122-
if (alertsClient) {
123-
for (const cluster of clusters) {
124-
const verification = verifyMonitoringLicense(req.server);
125-
if (!verification.enabled) {
126-
// return metadata detailing that alerts is disabled because of the monitoring cluster license
127-
cluster.alerts = {
128-
alertsMeta: {
129-
enabled: verification.enabled,
130-
message: verification.message, // NOTE: this is only defined when the alert feature is disabled
131-
},
132-
list: {},
133-
};
134-
continue;
135-
}
136-
137-
// check the license type of the production cluster for alerts feature support
138-
const license = cluster.license || {};
139-
const prodLicenseInfo = checkLicenseForAlerts(
140-
license.type,
141-
license.status === 'active',
142-
'production'
143-
);
144-
if (prodLicenseInfo.clusterAlerts.enabled) {
145-
cluster.alerts = {
146-
list: await fetchStatus(
147-
alertsClient,
148-
req.server.plugins.monitoring.info,
149-
undefined,
150-
cluster.cluster_uuid,
151-
start,
152-
end,
153-
[]
154-
),
155-
alertsMeta: {
156-
enabled: true,
157-
},
158-
};
159-
continue;
160-
}
122+
for (const cluster of clusters) {
123+
const verification = verifyMonitoringLicense(req.server);
124+
if (!verification.enabled) {
125+
// return metadata detailing that alerts is disabled because of the monitoring cluster license
126+
cluster.alerts = {
127+
alertsMeta: {
128+
enabled: verification.enabled,
129+
message: verification.message, // NOTE: this is only defined when the alert feature is disabled
130+
},
131+
list: {},
132+
};
133+
continue;
134+
}
161135

136+
if (!alertsClient) {
162137
cluster.alerts = {
163138
list: {},
164139
alertsMeta: {
165-
enabled: true,
166-
},
167-
clusterMeta: {
168140
enabled: false,
169-
message: i18n.translate(
170-
'xpack.monitoring.clusterAlerts.unsupportedClusterAlertsDescription',
171-
{
172-
defaultMessage:
173-
'Cluster [{clusterName}] license type [{licenseType}] does not support Cluster Alerts',
174-
values: {
175-
clusterName: cluster.cluster_name,
176-
licenseType: `${license.type}`,
177-
},
178-
}
179-
),
180141
},
181142
};
143+
continue;
144+
}
145+
146+
// check the license type of the production cluster for alerts feature support
147+
const license = cluster.license || {};
148+
const prodLicenseInfo = checkLicenseForAlerts(
149+
license.type,
150+
license.status === 'active',
151+
'production'
152+
);
153+
if (prodLicenseInfo.clusterAlerts.enabled) {
154+
cluster.alerts = {
155+
list: await fetchStatus(
156+
alertsClient,
157+
req.server.plugins.monitoring.info,
158+
undefined,
159+
cluster.cluster_uuid,
160+
start,
161+
end,
162+
[]
163+
),
164+
alertsMeta: {
165+
enabled: true,
166+
},
167+
};
168+
continue;
182169
}
170+
171+
cluster.alerts = {
172+
list: {},
173+
alertsMeta: {
174+
enabled: false,
175+
},
176+
clusterMeta: {
177+
enabled: false,
178+
message: i18n.translate(
179+
'xpack.monitoring.clusterAlerts.unsupportedClusterAlertsDescription',
180+
{
181+
defaultMessage:
182+
'Cluster [{clusterName}] license type [{licenseType}] does not support Cluster Alerts',
183+
values: {
184+
clusterName: cluster.cluster_name,
185+
licenseType: `${license.type}`,
186+
},
187+
}
188+
),
189+
},
190+
};
183191
}
184192
}
185193
}

x-pack/test/api_integration/apis/monitoring/cluster/fixtures/multicluster.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@
102102
},
103103
"alerts": {
104104
"alertsMeta": {
105-
"enabled": true
105+
"enabled": false
106106
},
107107
"clusterMeta": {
108108
"enabled": false,

x-pack/test/api_integration/apis/monitoring/standalone_cluster/fixtures/clusters.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@
102102
},
103103
"alerts": {
104104
"alertsMeta": {
105-
"enabled": true
105+
"enabled": false
106106
},
107107
"clusterMeta": {
108108
"enabled": false,
@@ -170,7 +170,7 @@
170170
},
171171
"alerts": {
172172
"alertsMeta": {
173-
"enabled": true
173+
"enabled": false
174174
},
175175
"clusterMeta": {
176176
"enabled": false,

0 commit comments

Comments
 (0)