Skip to content

Commit

Permalink
[Monitoring] Fix UI error when alerting is not available (#77179)
Browse files Browse the repository at this point in the history
* Ensure we always pass this structure down to avoid any errors in the UI

* Fix tests and also fix inaccurate boolean states

* Fix fixture
  • Loading branch information
chrisronline committed Sep 11, 2020
1 parent 4c23669 commit d01598d
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 56 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -119,67 +119,75 @@ export async function getClustersFromRequest(
// add alerts data
if (isInCodePath(codePaths, [CODE_PATH_ALERTS])) {
const alertsClient = req.getAlertsClient();
if (alertsClient) {
for (const cluster of clusters) {
const verification = verifyMonitoringLicense(req.server);
if (!verification.enabled) {
// return metadata detailing that alerts is disabled because of the monitoring cluster license
cluster.alerts = {
alertsMeta: {
enabled: verification.enabled,
message: verification.message, // NOTE: this is only defined when the alert feature is disabled
},
list: {},
};
continue;
}

// check the license type of the production cluster for alerts feature support
const license = cluster.license || {};
const prodLicenseInfo = checkLicenseForAlerts(
license.type,
license.status === 'active',
'production'
);
if (prodLicenseInfo.clusterAlerts.enabled) {
cluster.alerts = {
list: await fetchStatus(
alertsClient,
req.server.plugins.monitoring.info,
undefined,
cluster.cluster_uuid,
start,
end,
[]
),
alertsMeta: {
enabled: true,
},
};
continue;
}
for (const cluster of clusters) {
const verification = verifyMonitoringLicense(req.server);
if (!verification.enabled) {
// return metadata detailing that alerts is disabled because of the monitoring cluster license
cluster.alerts = {
alertsMeta: {
enabled: verification.enabled,
message: verification.message, // NOTE: this is only defined when the alert feature is disabled
},
list: {},
};
continue;
}

if (!alertsClient) {
cluster.alerts = {
list: {},
alertsMeta: {
enabled: true,
},
clusterMeta: {
enabled: false,
message: i18n.translate(
'xpack.monitoring.clusterAlerts.unsupportedClusterAlertsDescription',
{
defaultMessage:
'Cluster [{clusterName}] license type [{licenseType}] does not support Cluster Alerts',
values: {
clusterName: cluster.cluster_name,
licenseType: `${license.type}`,
},
}
),
},
};
continue;
}

// check the license type of the production cluster for alerts feature support
const license = cluster.license || {};
const prodLicenseInfo = checkLicenseForAlerts(
license.type,
license.status === 'active',
'production'
);
if (prodLicenseInfo.clusterAlerts.enabled) {
cluster.alerts = {
list: await fetchStatus(
alertsClient,
req.server.plugins.monitoring.info,
undefined,
cluster.cluster_uuid,
start,
end,
[]
),
alertsMeta: {
enabled: true,
},
};
continue;
}

cluster.alerts = {
list: {},
alertsMeta: {
enabled: false,
},
clusterMeta: {
enabled: false,
message: i18n.translate(
'xpack.monitoring.clusterAlerts.unsupportedClusterAlertsDescription',
{
defaultMessage:
'Cluster [{clusterName}] license type [{licenseType}] does not support Cluster Alerts',
values: {
clusterName: cluster.cluster_name,
licenseType: `${license.type}`,
},
}
),
},
};
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@
},
"alerts": {
"alertsMeta": {
"enabled": true
"enabled": false
},
"clusterMeta": {
"enabled": false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@
},
"alerts": {
"alertsMeta": {
"enabled": true
"enabled": false
},
"clusterMeta": {
"enabled": false,
Expand Down Expand Up @@ -170,7 +170,7 @@
},
"alerts": {
"alertsMeta": {
"enabled": true
"enabled": false
},
"clusterMeta": {
"enabled": false,
Expand Down

0 comments on commit d01598d

Please sign in to comment.