Skip to content

Commit

Permalink
Removed server app import into the frontend
Browse files Browse the repository at this point in the history
  • Loading branch information
igoristic committed Oct 29, 2020
1 parent 617cb32 commit 066a5f4
Show file tree
Hide file tree
Showing 49 changed files with 417 additions and 384 deletions.
173 changes: 164 additions & 9 deletions x-pack/plugins/monitoring/common/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { i18n } from '@kbn/i18n';
import { CommonAlertParamDetail } from './types/alerts';
import { AlertParamType } from './enums';

/**
* Helper string to add as a tag in every logging call
*/
Expand Down Expand Up @@ -215,15 +219,6 @@ export const REPORTING_SYSTEM_ID = 'reporting';
*/
export const TELEMETRY_COLLECTION_INTERVAL = 86400000;

/**
* We want to slowly rollout the migration from watcher-based cluster alerts to
* kibana alerts and we only want to enable the kibana alerts once all
* watcher-based cluster alerts have been migrated so this flag will serve
* as the only way to see the new UI and actually run Kibana alerts. It will
* be false until all alerts have been migrated, then it will be removed
*/
export const KIBANA_CLUSTER_ALERTS_ENABLED = false;

/**
* The prefix for all alert types used by monitoring
*/
Expand All @@ -241,6 +236,166 @@ export const ALERT_MISSING_MONITORING_DATA = `${ALERT_PREFIX}alert_missing_monit
export const ALERT_THREAD_POOL_SEARCH_REJECTIONS = `${ALERT_PREFIX}alert_thread_pool_search_rejections`;
export const ALERT_THREAD_POOL_WRITE_REJECTIONS = `${ALERT_PREFIX}alert_thread_pool_write_rejections`;

/**
* Legacy alerts details/label for server and public use
*/
export const LEGACY_ALERT_DETAILS = {
[ALERT_CLUSTER_HEALTH]: {
label: i18n.translate('xpack.monitoring.alerts.clusterHealth.label', {
defaultMessage: 'Cluster health',
}),
},
[ALERT_ELASTICSEARCH_VERSION_MISMATCH]: {
label: i18n.translate('xpack.monitoring.alerts.elasticsearchVersionMismatch.label', {
defaultMessage: 'Elasticsearch version mismatch',
}),
},
[ALERT_KIBANA_VERSION_MISMATCH]: {
label: i18n.translate('xpack.monitoring.alerts.kibanaVersionMismatch.label', {
defaultMessage: 'Kibana version mismatch',
}),
},
[ALERT_LICENSE_EXPIRATION]: {
label: i18n.translate('xpack.monitoring.alerts.licenseExpiration.label', {
defaultMessage: 'License expiration',
}),
},
[ALERT_LOGSTASH_VERSION_MISMATCH]: {
label: i18n.translate('xpack.monitoring.alerts.logstashVersionMismatch.label', {
defaultMessage: 'Logstash version mismatch',
}),
},
[ALERT_NODES_CHANGED]: {
label: i18n.translate('xpack.monitoring.alerts.nodesChanged.label', {
defaultMessage: 'Nodes changed',
}),
},
};

/**
* Alerts details/label for server and public use
*/
export const ALERT_DETAILS = {
[ALERT_CPU_USAGE]: {
label: i18n.translate('xpack.monitoring.alerts.cpuUsage.label', {
defaultMessage: 'CPU Usage',
}),
paramDetails: {
threshold: {
label: i18n.translate('xpack.monitoring.alerts.cpuUsage.paramDetails.threshold.label', {
defaultMessage: `Notify when CPU is over`,
}),
type: AlertParamType.Percentage,
} as CommonAlertParamDetail,
duration: {
label: i18n.translate('xpack.monitoring.alerts.cpuUsage.paramDetails.duration.label', {
defaultMessage: `Look at the average over`,
}),
type: AlertParamType.Duration,
} as CommonAlertParamDetail,
},
},
[ALERT_DISK_USAGE]: {
paramDetails: {
threshold: {
label: i18n.translate('xpack.monitoring.alerts.diskUsage.paramDetails.threshold.label', {
defaultMessage: `Notify when disk capacity is over`,
}),
type: AlertParamType.Percentage,
},
duration: {
label: i18n.translate('xpack.monitoring.alerts.diskUsage.paramDetails.duration.label', {
defaultMessage: `Look at the average over`,
}),
type: AlertParamType.Duration,
},
},
label: i18n.translate('xpack.monitoring.alerts.diskUsage.label', {
defaultMessage: 'Disk Usage',
}),
},
[ALERT_MEMORY_USAGE]: {
paramDetails: {
threshold: {
label: i18n.translate('xpack.monitoring.alerts.memoryUsage.paramDetails.threshold.label', {
defaultMessage: `Notify when memory usage is over`,
}),
type: AlertParamType.Percentage,
},
duration: {
label: i18n.translate('xpack.monitoring.alerts.memoryUsage.paramDetails.duration.label', {
defaultMessage: `Look at the average over`,
}),
type: AlertParamType.Duration,
},
},
label: i18n.translate('xpack.monitoring.alerts.memoryUsage.label', {
defaultMessage: 'Memory Usage (JVM)',
}),
},
[ALERT_MISSING_MONITORING_DATA]: {
paramDetails: {
duration: {
label: i18n.translate('xpack.monitoring.alerts.missingData.paramDetails.duration.label', {
defaultMessage: `Notify if monitoring data is missing for the last`,
}),
type: AlertParamType.Duration,
} as CommonAlertParamDetail,
limit: {
label: i18n.translate('xpack.monitoring.alerts.missingData.paramDetails.limit.label', {
defaultMessage: `looking back`,
}),
type: AlertParamType.Duration,
} as CommonAlertParamDetail,
},
label: i18n.translate('xpack.monitoring.alerts.missingData.label', {
defaultMessage: 'Missing monitoring data',
}),
},
[ALERT_THREAD_POOL_SEARCH_REJECTIONS]: {
paramDetails: {
threshold: {
label: i18n.translate('xpack.monitoring.alerts.rejection.paramDetails.threshold.label', {
defaultMessage: `Notify when {type} rejection count is over`,
values: { type: 'search' },
}),
type: AlertParamType.Number,
},
duration: {
label: i18n.translate('xpack.monitoring.alerts.rejection.paramDetails.duration.label', {
defaultMessage: `In the last`,
}),
type: AlertParamType.Duration,
},
},
label: i18n.translate('xpack.monitoring.alerts.threadPoolRejections.label', {
defaultMessage: 'Thread pool {type} rejections',
values: { type: 'search' },
}),
},
[ALERT_THREAD_POOL_WRITE_REJECTIONS]: {
paramDetails: {
threshold: {
label: i18n.translate('xpack.monitoring.alerts.rejection.paramDetails.threshold.label', {
defaultMessage: `Notify when {type} rejection count is over`,
values: { type: 'write' },
}),
type: AlertParamType.Number,
},
duration: {
label: i18n.translate('xpack.monitoring.alerts.rejection.paramDetails.duration.label', {
defaultMessage: `In the last`,
}),
type: AlertParamType.Duration,
},
},
label: i18n.translate('xpack.monitoring.alerts.threadPoolRejections.label', {
defaultMessage: 'Thread pool {type} rejections',
values: { type: 'write' },
}),
},
};

/**
* A listing of all alert types
*/
Expand Down
58 changes: 0 additions & 58 deletions x-pack/plugins/monitoring/common/types.ts

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,60 @@
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
import { AlertMessageTokenType, AlertSeverity } from '../../common/enums';
import { AlertInstanceState as BaseAlertInstanceState } from '../../../alerts/server';

import { Alert } from '../../../alerts/common';
import { AlertParamType, AlertMessageTokenType, AlertSeverity } from '../enums';

export interface CommonBaseAlert {
type: string;
label: string;
paramDetails: CommonAlertParamDetails;
rawAlert: Alert;
isLegacy: boolean;
}

export interface CommonAlertStatus {
exists: boolean;
enabled: boolean;
states: CommonAlertState[];
alert: CommonBaseAlert;
}

export interface CommonAlertState {
firing: boolean;
state: any;
meta: any;
}

export interface CommonAlertFilter {
nodeUuid?: string;
}

export interface CommonAlertNodeUuidFilter extends CommonAlertFilter {
nodeUuid: string;
}

export interface CommonAlertStackProductFilter extends CommonAlertFilter {
stackProduct: string;
}

export interface CommonAlertParamDetail {
label: string;
type?: AlertParamType;
}

export interface CommonAlertParamDetails {
[name: string]: CommonAlertParamDetail | undefined;
}

export interface CommonAlertParams {
[name: string]: string | number;
}

export interface ThreadPoolRejectionsAlertParams {
threshold: number;
duration: string;
}

export interface AlertEnableAction {
id: string;
Expand Down
4 changes: 2 additions & 2 deletions x-pack/plugins/monitoring/public/alerts/badge.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ import {
EuiFlexItem,
EuiText,
} from '@elastic/eui';
import { CommonAlertStatus, CommonAlertState } from '../../common/types';
import { CommonAlertStatus, CommonAlertState } from '../../common/types/alerts';
import { AlertSeverity } from '../../common/enums';
// @ts-ignore
import { formatDateTimeLocal } from '../../common/formatting';
import { AlertMessage, AlertState } from '../../server/alerts/types';
import { AlertMessage, AlertState } from '../../common/types/alerts';
import { AlertPanel } from './panel';
import { Legacy } from '../legacy_shims';
import { isInSetupMode } from '../lib/setup_mode';
Expand Down
4 changes: 2 additions & 2 deletions x-pack/plugins/monitoring/public/alerts/callout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
import React, { Fragment } from 'react';
import { i18n } from '@kbn/i18n';
import { EuiCallOut, EuiSpacer } from '@elastic/eui';
import { CommonAlertStatus } from '../../common/types';
import { CommonAlertStatus } from '../../common/types/alerts';
import { AlertSeverity } from '../../common/enums';
import { replaceTokens } from './lib/replace_tokens';
import { AlertMessage, AlertState } from '../../server/alerts/types';
import { AlertMessage, AlertState } from '../../common/types/alerts';

const TYPES = [
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import React, { Fragment } from 'react';
import { EuiForm, EuiSpacer } from '@elastic/eui';
import { CommonAlertParamDetails } from '../../../../common/types';
import { CommonAlertParamDetails } from '../../../../common/types/alerts';
import { AlertParamDuration } from '../../flyout_expressions/alert_param_duration';
import { AlertParamType } from '../../../../common/enums';
import { AlertParamPercentage } from '../../flyout_expressions/alert_param_percentage';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,17 @@
import React from 'react';
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
import { AlertTypeModel } from '../../../../triggers_actions_ui/public/types';
import { ALERT_CPU_USAGE } from '../../../common/constants';
import { ALERT_CPU_USAGE, ALERT_DETAILS } from '../../../common/constants';
import { validate } from '../components/duration/validation';
import { Expression, Props } from '../components/duration/expression';
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
import { CpuUsageAlert } from '../../../server/alerts';

export function createCpuUsageAlertType(): AlertTypeModel {
const alert = new CpuUsageAlert();
return {
id: ALERT_CPU_USAGE,
name: alert.label,
name: ALERT_DETAILS[ALERT_CPU_USAGE].label,
iconClass: 'bell',
alertParamsExpression: (props: Props) => (
<Expression {...props} paramDetails={CpuUsageAlert.paramDetails} />
<Expression {...props} paramDetails={ALERT_DETAILS[ALERT_CPU_USAGE].paramDetails} />
),
validate,
defaultActionMessage: '{{context.internalFullMessage}}',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,15 @@ import { Expression, Props } from '../components/duration/expression';

// eslint-disable-next-line @kbn/eslint/no-restricted-paths
import { AlertTypeModel } from '../../../../triggers_actions_ui/public/types';

// eslint-disable-next-line @kbn/eslint/no-restricted-paths
import { DiskUsageAlert } from '../../../server/alerts';
import { ALERT_DISK_USAGE, ALERT_DETAILS } from '../../../common/constants';

export function createDiskUsageAlertType(): AlertTypeModel {
return {
id: DiskUsageAlert.TYPE,
name: DiskUsageAlert.LABEL,
id: ALERT_DISK_USAGE,
name: ALERT_DETAILS[ALERT_DISK_USAGE].label,
iconClass: 'bell',
alertParamsExpression: (props: Props) => (
<Expression {...props} paramDetails={DiskUsageAlert.PARAM_DETAILS} />
<Expression {...props} paramDetails={ALERT_DETAILS[ALERT_DISK_USAGE].paramDetails} />
),
validate,
defaultActionMessage: '{{context.internalFullMessage}}',
Expand Down
Loading

0 comments on commit 066a5f4

Please sign in to comment.