Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[7.9] [Monitoring] Out of the box alert tweaks (#71942) #72148

Merged
merged 1 commit into from
Jul 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion x-pack/plugins/monitoring/public/alerts/callout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const TYPES = [
severity: AlertSeverity.Danger,
color: 'danger',
label: i18n.translate('xpack.monitoring.alerts.callout.dangerLabel', {
defaultMessage: 'DAnger alert(s)',
defaultMessage: 'Danger alert(s)',
}),
},
];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ interface Props {
setAlertParams: (property: string, value: any) => void;
}

const parseRegex = /(\d+)(\smhd)/;
const parseRegex = /(\d+)([smhd]{1})/;
export const AlertParamDuration: React.FC<Props> = (props: Props) => {
const { name, label, setAlertParams, errors } = props;
const parsed = parseRegex.exec(props.duration);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ export function shouldShowAlertBadge(
alerts: { [alertTypeId: string]: CommonAlertStatus },
alertTypeIds: string[]
) {
if (!alerts) {
return false;
}
const inSetupMode = isInSetupMode();
return inSetupMode || alertTypeIds.find((name) => alerts[name] && alerts[name].states.length);
}
2 changes: 1 addition & 1 deletion x-pack/plugins/monitoring/server/alerts/base_alert.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ describe('BaseAlert', () => {
interval: '1m',
},
tags: [],
throttle: '1m',
throttle: '1d',
},
});
});
Expand Down
2 changes: 1 addition & 1 deletion x-pack/plugins/monitoring/server/alerts/base_alert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ import { MonitoringLicenseService } from '../types';
export class BaseAlert {
public type!: string;
public label!: string;
public defaultThrottle: string = '1m';
public defaultThrottle: string = '1d';
public defaultInterval: string = '1m';
public rawAlert: Alert | undefined;
public isLegacy: boolean = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ describe('ClusterHealthAlert', () => {
const alert = new ClusterHealthAlert();
expect(alert.type).toBe(ALERT_CLUSTER_HEALTH);
expect(alert.label).toBe('Cluster health');
expect(alert.defaultThrottle).toBe('1m');
expect(alert.defaultThrottle).toBe('1d');
// @ts-ignore
expect(alert.actionVariables).toStrictEqual([
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ describe('CpuUsageAlert', () => {
const alert = new CpuUsageAlert();
expect(alert.type).toBe(ALERT_CPU_USAGE);
expect(alert.label).toBe('CPU Usage');
expect(alert.defaultThrottle).toBe('1m');
expect(alert.defaultThrottle).toBe('1d');
// @ts-ignore
expect(alert.defaultParams).toStrictEqual({ threshold: 90, duration: '5m' });
expect(alert.defaultParams).toStrictEqual({ threshold: 85, duration: '5m' });
// @ts-ignore
expect(alert.actionVariables).toStrictEqual([
{
Expand Down
13 changes: 11 additions & 2 deletions x-pack/plugins/monitoring/server/alerts/cpu_usage_alert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const FIRING = i18n.translate('xpack.monitoring.alerts.cpuUsage.firing', {
defaultMessage: 'firing',
});

const DEFAULT_THRESHOLD = 90;
const DEFAULT_THRESHOLD = 85;
const DEFAULT_DURATION = '5m';

interface CpuUsageParams {
Expand Down Expand Up @@ -393,7 +393,16 @@ export class CpuUsageAlert extends BaseAlert {
continue;
}

const instance = services.alertInstanceFactory(`${this.type}:${cluster.clusterUuid}`);
const firingNodeUuids = nodes.reduce((list: string[], node) => {
const stat = node.meta as AlertCpuUsageNodeStats;
if (node.shouldFire) {
list.push(stat.nodeId);
}
return list;
}, [] as string[]);
firingNodeUuids.sort(); // It doesn't matter how we sort, but keep the order consistent
const instanceId = `${this.type}:${cluster.clusterUuid}:${firingNodeUuids.join(',')}`;
const instance = services.alertInstanceFactory(instanceId);
const state = (instance.getState() as unknown) as AlertInstanceState;
const alertInstanceState: AlertInstanceState = { alertStates: state?.alertStates || [] };
let shouldExecuteActions = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ describe('ElasticsearchVersionMismatchAlert', () => {
const alert = new ElasticsearchVersionMismatchAlert();
expect(alert.type).toBe(ALERT_ELASTICSEARCH_VERSION_MISMATCH);
expect(alert.label).toBe('Elasticsearch version mismatch');
expect(alert.defaultThrottle).toBe('1m');
expect(alert.defaultThrottle).toBe('1d');
// @ts-ignore
expect(alert.actionVariables).toStrictEqual([
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ describe('KibanaVersionMismatchAlert', () => {
const alert = new KibanaVersionMismatchAlert();
expect(alert.type).toBe(ALERT_KIBANA_VERSION_MISMATCH);
expect(alert.label).toBe('Kibana version mismatch');
expect(alert.defaultThrottle).toBe('1m');
expect(alert.defaultThrottle).toBe('1d');
// @ts-ignore
expect(alert.actionVariables).toStrictEqual([
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ describe('LicenseExpirationAlert', () => {
const alert = new LicenseExpirationAlert();
expect(alert.type).toBe(ALERT_LICENSE_EXPIRATION);
expect(alert.label).toBe('License expiration');
expect(alert.defaultThrottle).toBe('1m');
expect(alert.defaultThrottle).toBe('1d');
// @ts-ignore
expect(alert.actionVariables).toStrictEqual([
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ describe('LogstashVersionMismatchAlert', () => {
const alert = new LogstashVersionMismatchAlert();
expect(alert.type).toBe(ALERT_LOGSTASH_VERSION_MISMATCH);
expect(alert.label).toBe('Logstash version mismatch');
expect(alert.defaultThrottle).toBe('1m');
expect(alert.defaultThrottle).toBe('1d');
// @ts-ignore
expect(alert.actionVariables).toStrictEqual([
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ describe('NodesChangedAlert', () => {
const alert = new NodesChangedAlert();
expect(alert.type).toBe(ALERT_NODES_CHANGED);
expect(alert.label).toBe('Nodes changed');
expect(alert.defaultThrottle).toBe('1m');
expect(alert.defaultThrottle).toBe('1d');
// @ts-ignore
expect(alert.actionVariables).toStrictEqual([
{
Expand Down
15 changes: 15 additions & 0 deletions x-pack/plugins/monitoring/server/alerts/nodes_changed_alert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,21 @@ export class NodesChangedAlert extends BaseAlert {
};
}

if (
Object.values(states.added).length === 0 &&
Object.values(states.removed).length === 0 &&
Object.values(states.restarted).length === 0
) {
return {
text: i18n.translate(
'xpack.monitoring.alerts.nodesChanged.ui.nothingDetectedFiringMessage',
{
defaultMessage: `Elasticsearch nodes have changed`,
}
),
};
}

const addedText =
Object.values(states.added).length > 0
? i18n.translate('xpack.monitoring.alerts.nodesChanged.ui.addedFiringMessage', {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ export function enableAlertsRoute(server: any, npRoute: RouteDependencies) {
npRoute.router.post(
{
path: '/api/monitoring/v1/alerts/enable',
options: { tags: ['access:monitoring'] },
validate: false,
},
async (context, request, response) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ export function alertStatusRoute(server: any, npRoute: RouteDependencies) {
npRoute.router.post(
{
path: '/api/monitoring/v1/alert/{clusterUuid}/status',
options: { tags: ['access:monitoring'] },
validate: {
params: schema.object({
clusterUuid: schema.string(),
Expand Down