forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Metrics UI] Add inventory alert preview (elastic#68909) (elastic#69766)
Co-authored-by: Elastic Machine <[email protected]> Co-authored-by: Elastic Machine <[email protected]>
- Loading branch information
1 parent
89ba7ff
commit 30b997f
Showing
20 changed files
with
563 additions
and
208 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
x-pack/plugins/infra/public/alerting/common/get_alert_preview.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* | ||
* 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 * as rt from 'io-ts'; | ||
import { HttpSetup } from 'src/core/public'; | ||
import { | ||
INFRA_ALERT_PREVIEW_PATH, | ||
METRIC_THRESHOLD_ALERT_TYPE_ID, | ||
METRIC_INVENTORY_THRESHOLD_ALERT_TYPE_ID, | ||
alertPreviewRequestParamsRT, | ||
alertPreviewSuccessResponsePayloadRT, | ||
} from '../../../common/alerting/metrics'; | ||
|
||
async function getAlertPreview({ | ||
fetch, | ||
params, | ||
alertType, | ||
}: { | ||
fetch: HttpSetup['fetch']; | ||
params: rt.TypeOf<typeof alertPreviewRequestParamsRT>; | ||
alertType: | ||
| typeof METRIC_THRESHOLD_ALERT_TYPE_ID | ||
| typeof METRIC_INVENTORY_THRESHOLD_ALERT_TYPE_ID; | ||
}): Promise<rt.TypeOf<typeof alertPreviewSuccessResponsePayloadRT>> { | ||
return await fetch(`${INFRA_ALERT_PREVIEW_PATH}`, { | ||
method: 'POST', | ||
body: JSON.stringify({ | ||
...params, | ||
alertType, | ||
}), | ||
}); | ||
} | ||
|
||
export const getMetricThresholdAlertPreview = ({ | ||
fetch, | ||
params, | ||
}: { | ||
fetch: HttpSetup['fetch']; | ||
params: rt.TypeOf<typeof alertPreviewRequestParamsRT>; | ||
}) => getAlertPreview({ fetch, params, alertType: METRIC_THRESHOLD_ALERT_TYPE_ID }); | ||
|
||
export const getInventoryAlertPreview = ({ | ||
fetch, | ||
params, | ||
}: { | ||
fetch: HttpSetup['fetch']; | ||
params: rt.TypeOf<typeof alertPreviewRequestParamsRT>; | ||
}) => getAlertPreview({ fetch, params, alertType: METRIC_INVENTORY_THRESHOLD_ALERT_TYPE_ID }); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/* | ||
* 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'; | ||
|
||
export * from './get_alert_preview'; | ||
|
||
export const previewOptions = [ | ||
{ | ||
value: 'h', | ||
text: i18n.translate('xpack.infra.metrics.alertFlyout.lastHourLabel', { | ||
defaultMessage: 'Last hour', | ||
}), | ||
shortText: i18n.translate('xpack.infra.metrics.alertFlyout.hourLabel', { | ||
defaultMessage: 'hour', | ||
}), | ||
}, | ||
{ | ||
value: 'd', | ||
text: i18n.translate('xpack.infra.metrics.alertFlyout.lastDayLabel', { | ||
defaultMessage: 'Last day', | ||
}), | ||
shortText: i18n.translate('xpack.infra.metrics.alertFlyout.dayLabel', { | ||
defaultMessage: 'day', | ||
}), | ||
}, | ||
{ | ||
value: 'w', | ||
text: i18n.translate('xpack.infra.metrics.alertFlyout.lastWeekLabel', { | ||
defaultMessage: 'Last week', | ||
}), | ||
shortText: i18n.translate('xpack.infra.metrics.alertFlyout.weekLabel', { | ||
defaultMessage: 'week', | ||
}), | ||
}, | ||
{ | ||
value: 'M', | ||
text: i18n.translate('xpack.infra.metrics.alertFlyout.lastMonthLabel', { | ||
defaultMessage: 'Last month', | ||
}), | ||
shortText: i18n.translate('xpack.infra.metrics.alertFlyout.monthLabel', { | ||
defaultMessage: 'month', | ||
}), | ||
}, | ||
]; | ||
|
||
export const firedTimeLabel = i18n.translate('xpack.infra.metrics.alertFlyout.firedTime', { | ||
defaultMessage: 'time', | ||
}); | ||
export const firedTimesLabel = i18n.translate('xpack.infra.metrics.alertFlyout.firedTimes', { | ||
defaultMessage: 'times', | ||
}); |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
Oops, something went wrong.