Skip to content

Commit

Permalink
[Monitoring] Handle getClient call throwing an exception (#74550)
Browse files Browse the repository at this point in the history
* This call can throw an exception in dist builds with ssl disabled

* Fix typo
  • Loading branch information
chrisronline authored Aug 6, 2020
1 parent ebe46c0 commit e807ddd
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -119,65 +119,67 @@ export async function getClustersFromRequest(
// add alerts data
if (isInCodePath(codePaths, [CODE_PATH_ALERTS])) {
const alertsClient = req.getAlertsClient();
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) {
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;
}

// 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,
[]
),
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;
}

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}`,
},
}
),
},
};
}
}
}
Expand Down
18 changes: 16 additions & 2 deletions x-pack/plugins/monitoring/server/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -325,8 +325,22 @@ export class Plugin {
getKibanaStatsCollector: () => this.legacyShimDependencies.kibanaStatsCollector,
getUiSettingsService: () => context.core.uiSettings.client,
getActionTypeRegistry: () => context.actions?.listTypes(),
getAlertsClient: () => plugins.alerts.getAlertsClientWithRequest(req),
getActionsClient: () => plugins.actions.getActionsClientWithRequest(req),
getAlertsClient: () => {
try {
return plugins.alerts.getAlertsClientWithRequest(req);
} catch (err) {
// If security is disabled, this call will throw an error unless a certain config is set for dist builds
return null;
}
},
getActionsClient: () => {
try {
return plugins.actions.getActionsClientWithRequest(req);
} catch (err) {
// If security is disabled, this call will throw an error unless a certain config is set for dist builds
return null;
}
},
server: {
config: legacyConfigWrapper,
newPlatform: {
Expand Down

0 comments on commit e807ddd

Please sign in to comment.