mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 17:28:26 -04:00
[Monitoring] Fetch status once and change fetchStatus to support an array of clusters (#91749) (#95409)
* Fetch status once and change fetchStatus to support an array of clusters * Update test
This commit is contained in:
parent
83f3c61201
commit
983ebad298
4 changed files with 41 additions and 41 deletions
|
@ -74,12 +74,9 @@ describe('fetchStatus', () => {
|
|||
});
|
||||
|
||||
it('should fetch from the alerts client', async () => {
|
||||
const status = await fetchStatus(
|
||||
alertsClient as any,
|
||||
licenseService as any,
|
||||
alertTypes,
|
||||
defaultClusterState.clusterUuid
|
||||
);
|
||||
const status = await fetchStatus(alertsClient as any, licenseService as any, alertTypes, [
|
||||
defaultClusterState.clusterUuid,
|
||||
]);
|
||||
expect(status).toEqual({
|
||||
monitoring_alert_cpu_usage: {
|
||||
rawAlert: { id: 1 },
|
||||
|
@ -99,24 +96,18 @@ describe('fetchStatus', () => {
|
|||
},
|
||||
];
|
||||
|
||||
const status = await fetchStatus(
|
||||
alertsClient as any,
|
||||
licenseService as any,
|
||||
alertTypes,
|
||||
defaultClusterState.clusterUuid
|
||||
);
|
||||
const status = await fetchStatus(alertsClient as any, licenseService as any, alertTypes, [
|
||||
defaultClusterState.clusterUuid,
|
||||
]);
|
||||
expect(Object.values(status).length).toBe(1);
|
||||
expect(Object.keys(status)).toEqual(alertTypes);
|
||||
expect(status[alertType].states[0].state.ui.isFiring).toBe(true);
|
||||
});
|
||||
|
||||
it('should pass in the right filter to the alerts client', async () => {
|
||||
await fetchStatus(
|
||||
alertsClient as any,
|
||||
licenseService as any,
|
||||
alertTypes,
|
||||
defaultClusterState.clusterUuid
|
||||
);
|
||||
await fetchStatus(alertsClient as any, licenseService as any, alertTypes, [
|
||||
defaultClusterState.clusterUuid,
|
||||
]);
|
||||
expect((alertsClient.find as jest.Mock).mock.calls[0][0].options.filter).toBe(
|
||||
`alert.attributes.alertTypeId:${alertType}`
|
||||
);
|
||||
|
@ -127,12 +118,9 @@ describe('fetchStatus', () => {
|
|||
alertTypeState: null,
|
||||
})) as any;
|
||||
|
||||
const status = await fetchStatus(
|
||||
alertsClient as any,
|
||||
licenseService as any,
|
||||
alertTypes,
|
||||
defaultClusterState.clusterUuid
|
||||
);
|
||||
const status = await fetchStatus(alertsClient as any, licenseService as any, alertTypes, [
|
||||
defaultClusterState.clusterUuid,
|
||||
]);
|
||||
expect(status[alertType].states.length).toEqual(0);
|
||||
});
|
||||
|
||||
|
@ -142,12 +130,9 @@ describe('fetchStatus', () => {
|
|||
data: [],
|
||||
})) as any;
|
||||
|
||||
const status = await fetchStatus(
|
||||
alertsClient as any,
|
||||
licenseService as any,
|
||||
alertTypes,
|
||||
defaultClusterState.clusterUuid
|
||||
);
|
||||
const status = await fetchStatus(alertsClient as any, licenseService as any, alertTypes, [
|
||||
defaultClusterState.clusterUuid,
|
||||
]);
|
||||
expect(status).toEqual({});
|
||||
});
|
||||
|
||||
|
@ -163,7 +148,7 @@ describe('fetchStatus', () => {
|
|||
alertsClient as any,
|
||||
customLicenseService as any,
|
||||
[ALERT_CLUSTER_HEALTH],
|
||||
defaultClusterState.clusterUuid
|
||||
[defaultClusterState.clusterUuid]
|
||||
);
|
||||
expect(customLicenseService.getWatcherFeature).toHaveBeenCalled();
|
||||
});
|
||||
|
@ -200,7 +185,7 @@ describe('fetchStatus', () => {
|
|||
customAlertsClient as any,
|
||||
licenseService as any,
|
||||
[ALERT_CPU_USAGE, ALERT_DISK_USAGE, ALERT_MISSING_MONITORING_DATA],
|
||||
defaultClusterState.clusterUuid
|
||||
[defaultClusterState.clusterUuid]
|
||||
);
|
||||
expect(Object.keys(status)).toEqual([
|
||||
ALERT_CPU_USAGE,
|
||||
|
|
|
@ -20,7 +20,7 @@ export async function fetchStatus(
|
|||
alertsClient: AlertsClient,
|
||||
licenseService: MonitoringLicenseService,
|
||||
alertTypes: string[] | undefined,
|
||||
clusterUuid: string,
|
||||
clusterUuids: string[],
|
||||
filters: CommonAlertFilter[] = []
|
||||
): Promise<{ [type: string]: CommonAlertStatus }> {
|
||||
const types: Array<{ type: string; result: CommonAlertStatus }> = [];
|
||||
|
@ -57,7 +57,7 @@ export async function fetchStatus(
|
|||
}
|
||||
for (const state of alertInstanceState.alertStates) {
|
||||
const meta = instance.meta;
|
||||
if (clusterUuid && state.cluster.clusterUuid !== clusterUuid) {
|
||||
if (clusterUuids && !clusterUuids.includes(state.cluster.clusterUuid)) {
|
||||
return accum;
|
||||
}
|
||||
|
||||
|
|
|
@ -120,6 +120,13 @@ export async function getClustersFromRequest(
|
|||
// add alerts data
|
||||
if (isInCodePath(codePaths, [CODE_PATH_ALERTS])) {
|
||||
const alertsClient = req.getAlertsClient();
|
||||
const alertStatus = await fetchStatus(
|
||||
alertsClient,
|
||||
req.server.plugins.monitoring.info,
|
||||
undefined,
|
||||
clusters.map((cluster) => cluster.cluster_uuid)
|
||||
);
|
||||
|
||||
for (const cluster of clusters) {
|
||||
const verification = verifyMonitoringLicense(req.server);
|
||||
if (!verification.enabled) {
|
||||
|
@ -154,12 +161,20 @@ export async function getClustersFromRequest(
|
|||
if (prodLicenseInfo.clusterAlerts.enabled) {
|
||||
try {
|
||||
cluster.alerts = {
|
||||
list: await fetchStatus(
|
||||
alertsClient,
|
||||
req.server.plugins.monitoring.info,
|
||||
undefined,
|
||||
cluster.cluster_uuid
|
||||
),
|
||||
list: Object.keys(alertStatus).reduce((accum, alertName) => {
|
||||
const value = alertStatus[alertName];
|
||||
if (value.states && value.states.length) {
|
||||
accum[alertName] = {
|
||||
...value,
|
||||
states: value.states.filter(
|
||||
(state) => state.state.cluster.clusterUuid === cluster.cluster_uuid
|
||||
),
|
||||
};
|
||||
} else {
|
||||
accum[alertName] = value;
|
||||
}
|
||||
return accum;
|
||||
}, {}),
|
||||
alertsMeta: {
|
||||
enabled: true,
|
||||
},
|
||||
|
|
|
@ -43,7 +43,7 @@ export function alertStatusRoute(server: any, npRoute: RouteDependencies) {
|
|||
alertsClient,
|
||||
npRoute.licenseService,
|
||||
alertTypeIds,
|
||||
clusterUuid,
|
||||
[clusterUuid],
|
||||
filters as CommonAlertFilter[]
|
||||
);
|
||||
return response.ok({ body: status });
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue