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

[Metrics UI] Add context.reason and alertOnNoData to Inventory alerts #70260

Merged
merged 6 commits into from
Jun 30, 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
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import React, { useMemo } from 'react';
import { EuiFlexItem } from '@elastic/eui';
import { toMetricOpt } from '../../../snapshot_metric_i18n';
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
import { WaffleSortControls } from '../../../../public/pages/metrics/inventory_view/components/waffle/waffle_sort_controls';
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
Expand All @@ -16,7 +17,6 @@ import { WaffleMetricControls } from '../../../../public/pages/metrics/inventory
import { WaffleGroupByControls } from '../../../../public/pages/metrics/inventory_view/components/waffle/waffle_group_by_controls';
import {
toGroupByOpt,
toMetricOpt,
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
} from '../../../../public/pages/metrics/inventory_view/components/toolbars/toolbar_wrapper';
import { SnapshotMetricType } from '../../types';
Expand Down
208 changes: 208 additions & 0 deletions x-pack/plugins/infra/common/snapshot_metric_i18n.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,208 @@
/*
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note to self: switch to the implementation in #69757 instead

* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
import { i18n } from '@kbn/i18n';
import { SnapshotMetricType } from './inventory_models/types';

const Translations = {
CPUUsage: i18n.translate('xpack.infra.waffle.metricOptions.cpuUsageText', {
defaultMessage: 'CPU usage',
}),

MemoryUsage: i18n.translate('xpack.infra.waffle.metricOptions.memoryUsageText', {
defaultMessage: 'Memory usage',
}),

InboundTraffic: i18n.translate('xpack.infra.waffle.metricOptions.inboundTrafficText', {
defaultMessage: 'Inbound traffic',
}),

OutboundTraffic: i18n.translate('xpack.infra.waffle.metricOptions.outboundTrafficText', {
defaultMessage: 'Outbound traffic',
}),

LogRate: i18n.translate('xpack.infra.waffle.metricOptions.hostLogRateText', {
defaultMessage: 'Log rate',
}),

Load: i18n.translate('xpack.infra.waffle.metricOptions.loadText', {
defaultMessage: 'Load',
}),

Count: i18n.translate('xpack.infra.waffle.metricOptions.countText', {
defaultMessage: 'Count',
}),
DiskIOReadBytes: i18n.translate('xpack.infra.waffle.metricOptions.diskIOReadBytes', {
defaultMessage: 'Disk Reads',
}),
DiskIOWriteBytes: i18n.translate('xpack.infra.waffle.metricOptions.diskIOWriteBytes', {
defaultMessage: 'Disk Writes',
}),
s3BucketSize: i18n.translate('xpack.infra.waffle.metricOptions.s3BucketSize', {
defaultMessage: 'Bucket Size',
}),
s3TotalRequests: i18n.translate('xpack.infra.waffle.metricOptions.s3TotalRequests', {
defaultMessage: 'Total Requests',
}),
s3NumberOfObjects: i18n.translate('xpack.infra.waffle.metricOptions.s3NumberOfObjects', {
defaultMessage: 'Number of Objects',
}),
s3DownloadBytes: i18n.translate('xpack.infra.waffle.metricOptions.s3DownloadBytes', {
defaultMessage: 'Downloads (Bytes)',
}),
s3UploadBytes: i18n.translate('xpack.infra.waffle.metricOptions.s3UploadBytes', {
defaultMessage: 'Uploads (Bytes)',
}),
rdsConnections: i18n.translate('xpack.infra.waffle.metricOptions.rdsConnections', {
defaultMessage: 'Connections',
}),
rdsQueriesExecuted: i18n.translate('xpack.infra.waffle.metricOptions.rdsQueriesExecuted', {
defaultMessage: 'Queries Executed',
}),
rdsActiveTransactions: i18n.translate('xpack.infra.waffle.metricOptions.rdsActiveTransactions', {
defaultMessage: 'Active Transactions',
}),
rdsLatency: i18n.translate('xpack.infra.waffle.metricOptions.rdsLatency', {
defaultMessage: 'Latency',
}),
sqsMessagesVisible: i18n.translate('xpack.infra.waffle.metricOptions.sqsMessagesVisible', {
defaultMessage: 'Messages Available',
}),
sqsMessagesDelayed: i18n.translate('xpack.infra.waffle.metricOptions.sqsMessagesDelayed', {
defaultMessage: 'Messages Delayed',
}),
sqsMessagesSent: i18n.translate('xpack.infra.waffle.metricOptions.sqsMessagesSent', {
defaultMessage: 'Messages Added',
}),
sqsMessagesEmpty: i18n.translate('xpack.infra.waffle.metricOptions.sqsMessagesEmpty', {
defaultMessage: 'Messages Returned Empty',
}),
sqsOldestMessage: i18n.translate('xpack.infra.waffle.metricOptions.sqsOldestMessage', {
defaultMessage: 'Oldest Message',
}),
};

export const toMetricOpt = (
metric: SnapshotMetricType
): { text: string; value: SnapshotMetricType } | undefined => {
switch (metric) {
case 'cpu':
return {
text: Translations.CPUUsage,
value: 'cpu',
};
case 'memory':
return {
text: Translations.MemoryUsage,
value: 'memory',
};
case 'rx':
return {
text: Translations.InboundTraffic,
value: 'rx',
};
case 'tx':
return {
text: Translations.OutboundTraffic,
value: 'tx',
};
case 'logRate':
return {
text: Translations.LogRate,
value: 'logRate',
};
case 'load':
return {
text: Translations.Load,
value: 'load',
};

case 'count':
return {
text: Translations.Count,
value: 'count',
};
case 'diskIOReadBytes':
return {
text: Translations.DiskIOReadBytes,
value: 'diskIOReadBytes',
};
case 'diskIOWriteBytes':
return {
text: Translations.DiskIOWriteBytes,
value: 'diskIOWriteBytes',
};
case 's3BucketSize':
return {
text: Translations.s3BucketSize,
value: 's3BucketSize',
};
case 's3TotalRequests':
return {
text: Translations.s3TotalRequests,
value: 's3TotalRequests',
};
case 's3NumberOfObjects':
return {
text: Translations.s3NumberOfObjects,
value: 's3NumberOfObjects',
};
case 's3DownloadBytes':
return {
text: Translations.s3DownloadBytes,
value: 's3DownloadBytes',
};
case 's3UploadBytes':
return {
text: Translations.s3UploadBytes,
value: 's3UploadBytes',
};
case 'rdsConnections':
return {
text: Translations.rdsConnections,
value: 'rdsConnections',
};
case 'rdsQueriesExecuted':
return {
text: Translations.rdsQueriesExecuted,
value: 'rdsQueriesExecuted',
};
case 'rdsActiveTransactions':
return {
text: Translations.rdsActiveTransactions,
value: 'rdsActiveTransactions',
};
case 'rdsLatency':
return {
text: Translations.rdsLatency,
value: 'rdsLatency',
};
case 'sqsMessagesVisible':
return {
text: Translations.sqsMessagesVisible,
value: 'sqsMessagesVisible',
};
case 'sqsMessagesDelayed':
return {
text: Translations.sqsMessagesDelayed,
value: 'sqsMessagesDelayed',
};
case 'sqsMessagesSent':
return {
text: Translations.sqsMessagesSent,
value: 'sqsMessagesSent',
};
case 'sqsMessagesEmpty':
return {
text: Translations.sqsMessagesEmpty,
value: 'sqsMessagesEmpty',
};
case 'sqsOldestMessage':
return {
text: Translations.sqsOldestMessage,
value: 'sqsOldestMessage',
};
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,13 @@ import {
EuiFormRow,
EuiButtonEmpty,
EuiFieldSearch,
EuiCheckbox,
EuiToolTip,
EuiIcon,
} from '@elastic/eui';
import { FormattedMessage } from '@kbn/i18n/react';
import { i18n } from '@kbn/i18n';
import { toMetricOpt } from '../../../../common/snapshot_metric_i18n';
import { AlertPreview } from '../../common';
import { METRIC_INVENTORY_THRESHOLD_ALERT_TYPE_ID } from '../../../../common/alerting/metrics';
import {
Expand All @@ -38,7 +42,6 @@ import { AlertsContextValue } from '../../../../../triggers_actions_ui/public/ap
// eslint-disable-next-line @kbn/eslint/no-restricted-paths
import { MetricsExplorerKueryBar } from '../../../pages/metrics/metrics_explorer/components/kuery_bar';
import { useSourceViaHttp } from '../../../containers/source/use_source_via_http';
import { toMetricOpt } from '../../../pages/metrics/inventory_view/components/toolbars/toolbar_wrapper';
import { sqsMetricTypes } from '../../../../common/inventory_models/aws_sqs/toolbar_items';
import { ec2MetricTypes } from '../../../../common/inventory_models/aws_ec2/toolbar_items';
import { s3MetricTypes } from '../../../../common/inventory_models/aws_s3/toolbar_items';
Expand Down Expand Up @@ -73,6 +76,7 @@ interface Props {
filterQuery?: string;
filterQueryText?: string;
sourceId?: string;
alertOnNoData?: boolean;
};
alertInterval: string;
alertsContext: AlertsContextValue<AlertContextMeta>;
Expand Down Expand Up @@ -306,6 +310,28 @@ export const Expressions: React.FC<Props> = (props) => {
</EuiButtonEmpty>
</div>

<EuiSpacer size={'m'} />
<EuiCheckbox
id="metrics-alert-no-data-toggle"
label={
<>
{i18n.translate('xpack.infra.metrics.alertFlyout.alertOnNoData', {
defaultMessage: "Alert me if there's no data",
})}{' '}
<EuiToolTip
content={i18n.translate('xpack.infra.metrics.alertFlyout.noDataHelpText', {
defaultMessage:
'Enable this to trigger the action if the metric(s) do not report any data over the expected time period, or if the alert fails to query Elasticsearch',
})}
>
<EuiIcon type="questionInCircle" color="subdued" />
</EuiToolTip>
</>
}
checked={alertParams.alertOnNoData}
onChange={(e) => setAlertParams('alertOnNoData', e.target.checked)}
/>

<EuiSpacer size={'m'} />

<EuiFormRow
Expand Down
6 changes: 3 additions & 3 deletions x-pack/plugins/infra/public/alerting/inventory/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@ export function createInventoryMetricAlertType(): AlertTypeModel {
defaultActionMessage: i18n.translate(
'xpack.infra.metrics.alerting.inventory.threshold.defaultActionMessage',
{
defaultMessage: `\\{\\{alertName\\}\\} - \\{\\{context.group\\}\\}
defaultMessage: `\\{\\{alertName\\}\\} - \\{\\{context.group\\}\\} is in a state of \\{\\{context.alertState\\}\\}

\\{\\{context.metricOf.condition0\\}\\} has crossed a threshold of \\{\\{context.thresholdOf.condition0\\}\\}
Current value is \\{\\{context.valueOf.condition0\\}\\}
Reason:
\\{\\{context.reason\\}\\}
`,
}
),
Expand Down
Loading