Skip to content

Commit

Permalink
Feedback and tests
Browse files Browse the repository at this point in the history
  • Loading branch information
igoristic committed Oct 2, 2020
1 parent 14c456e commit 7ddae02
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,6 @@ describe('AlertsFactory', () => {

it('should get all', () => {
const alerts = AlertsFactory.getAll();
expect(alerts.length).toBe(9);
expect(alerts.length).toBe(10);
});
});
9 changes: 9 additions & 0 deletions x-pack/plugins/monitoring/server/alerts/base_alert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -377,4 +377,13 @@ export class BaseAlert {
) {
throw new Error('Child classes must implement `executeActions`');
}

protected createGlobalStateLink(link: string, clusterUuid: string, ccs?: string) {
const globalState = [`cluster_uuid:${clusterUuid}`];
if (ccs) {
globalState.push(`ccs:${ccs}`);
}
globalState.push('refreshInterval:(pause:!f,value:10000),time:(from:now-1h,to:now)');
return `${this.kibanaUrl}/app/monitoring#/${link}?_g=(${globalState.toString()})`;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,13 @@ export class MemoryUsageAlert extends BaseAlert {
defaultMessage: 'View nodes',
});

const action = `[${fullActionText}](elasticsearch/nodes)`;
const ccs = alertStates.find((state) => state.ccs)?.ccs;
const globalStateLink = this.createGlobalStateLink(
'elasticsearch/nodes',
cluster.clusterUuid,
ccs
);
const action = `[${fullActionText}](${globalStateLink})`;
const internalShortMessage = i18n.translate(
'xpack.monitoring.alerts.memoryUsage.firing.internalShortMessage',
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,9 +234,9 @@ describe('MissingMonitoringDataAlert', () => {
],
});
expect(scheduleActions).toHaveBeenCalledWith('default', {
internalFullMessage: `We have not detected any monitoring data for 2 stack product(s) in cluster: testCluster. [View what monitoring data we do have for these stack products.](http://localhost:5601/app/monitoring#overview?_g=(cluster_uuid:abc123))`,
internalFullMessage: `We have not detected any monitoring data for 2 stack product(s) in cluster: testCluster. [View what monitoring data we do have for these stack products.](http://localhost:5601/app/monitoring#/overview?_g=(cluster_uuid:abc123,refreshInterval:(pause:!f,value:10000),time:(from:now-1h,to:now)))`,
internalShortMessage: `We have not detected any monitoring data for 2 stack product(s) in cluster: testCluster. Verify these stack products are up and running, then double check the monitoring settings.`,
action: `[View what monitoring data we do have for these stack products.](http://localhost:5601/app/monitoring#overview?_g=(cluster_uuid:abc123))`,
action: `[View what monitoring data we do have for these stack products.](http://localhost:5601/app/monitoring#/overview?_g=(cluster_uuid:abc123,refreshInterval:(pause:!f,value:10000),time:(from:now-1h,to:now)))`,
actionPlain:
'Verify these stack products are up and running, then double check the monitoring settings.',
clusterName,
Expand Down Expand Up @@ -414,9 +414,9 @@ describe('MissingMonitoringDataAlert', () => {
} as any);
const count = 1;
expect(scheduleActions).toHaveBeenCalledWith('default', {
internalFullMessage: `We have not detected any monitoring data for 1 stack product(s) in cluster: testCluster. [View what monitoring data we do have for these stack products.](http://localhost:5601/app/monitoring#overview?_g=(cluster_uuid:abc123,ccs:testCluster))`,
internalFullMessage: `We have not detected any monitoring data for 1 stack product(s) in cluster: testCluster. [View what monitoring data we do have for these stack products.](http://localhost:5601/app/monitoring#/overview?_g=(cluster_uuid:abc123,ccs:testCluster,refreshInterval:(pause:!f,value:10000),time:(from:now-1h,to:now)))`,
internalShortMessage: `We have not detected any monitoring data for 1 stack product(s) in cluster: testCluster. Verify these stack products are up and running, then double check the monitoring settings.`,
action: `[View what monitoring data we do have for these stack products.](http://localhost:5601/app/monitoring#overview?_g=(cluster_uuid:abc123,ccs:testCluster))`,
action: `[View what monitoring data we do have for these stack products.](http://localhost:5601/app/monitoring#/overview?_g=(cluster_uuid:abc123,ccs:testCluster,refreshInterval:(pause:!f,value:10000),time:(from:now-1h,to:now)))`,
actionPlain:
'Verify these stack products are up and running, then double check the monitoring settings.',
clusterName,
Expand Down Expand Up @@ -446,7 +446,7 @@ describe('MissingMonitoringDataAlert', () => {
expect(scheduleActions).toHaveBeenCalledWith('default', {
internalFullMessage: `We have not detected any monitoring data for 2 stack product(s) in cluster: testCluster. Verify these stack products are up and running, then double check the monitoring settings.`,
internalShortMessage: `We have not detected any monitoring data for 2 stack product(s) in cluster: testCluster. Verify these stack products are up and running, then double check the monitoring settings.`,
action: `[View what monitoring data we do have for these stack products.](http://localhost:5601/app/monitoring#overview?_g=(cluster_uuid:abc123))`,
action: `[View what monitoring data we do have for these stack products.](http://localhost:5601/app/monitoring#/overview?_g=(cluster_uuid:abc123,refreshInterval:(pause:!f,value:10000),time:(from:now-1h,to:now)))`,
actionPlain:
'Verify these stack products are up and running, then double check the monitoring settings.',
clusterName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -309,13 +309,6 @@ export class MissingMonitoringDataAlert extends BaseAlert {
return;
}

const ccs = instanceState.alertStates.reduce((accum: string, state): string => {
if (state.ccs) {
return state.ccs;
}
return accum;
}, '');

const firingCount = instanceState.alertStates.filter((alertState) => alertState.ui.isFiring)
.length;
const firingStackProducts = instanceState.alertStates
Expand All @@ -336,12 +329,10 @@ export class MissingMonitoringDataAlert extends BaseAlert {
const fullActionText = i18n.translate('xpack.monitoring.alerts.missingData.fullAction', {
defaultMessage: 'View what monitoring data we do have for these stack products.',
});
const globalState = [`cluster_uuid:${cluster.clusterUuid}`];
if (ccs) {
globalState.push(`ccs:${ccs}`);
}
const url = `${this.kibanaUrl}/app/monitoring#overview?_g=(${globalState.join(',')})`;
const action = `[${fullActionText}](${url})`;

const ccs = instanceState.alertStates.find((state) => state.ccs)?.ccs;
const globalStateLink = this.createGlobalStateLink('overview', cluster.clusterUuid, ccs);
const action = `[${fullActionText}](${globalStateLink})`;
const internalShortMessage = i18n.translate(
'xpack.monitoring.alerts.missingData.firing.internalShortMessage',
{
Expand Down

0 comments on commit 7ddae02

Please sign in to comment.