mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 09:48:58 -04:00
[Watcher] Add support for additional watch action statuses (#55092)
This commit is contained in:
parent
07d1dac0da
commit
7b145bffa0
6 changed files with 49 additions and 34 deletions
|
@ -36,4 +36,9 @@ export const ACTION_STATES: { [key: string]: string } = {
|
|||
CONFIG_ERROR: i18n.translate('xpack.watcher.constants.actionStates.configErrorStateText', {
|
||||
defaultMessage: 'Config error',
|
||||
}),
|
||||
|
||||
// Action status is unknown; we should never end up in this state
|
||||
UNKNOWN: i18n.translate('xpack.watcher.constants.actionStates.unknownStateText', {
|
||||
defaultMessage: 'Unknown',
|
||||
}),
|
||||
};
|
||||
|
|
|
@ -23,6 +23,8 @@ function StatusIcon({ status }: { status: string }) {
|
|||
return <EuiIcon type="minusInCircleFilled" color="subdued" />;
|
||||
case WATCH_STATES.CONFIG_ERROR:
|
||||
case WATCH_STATES.ERROR:
|
||||
case ACTION_STATES.UNKNOWN:
|
||||
return <EuiIcon type="cross" color="subdued" />;
|
||||
case ACTION_STATES.CONFIG_ERROR:
|
||||
case ACTION_STATES.ERROR:
|
||||
return <EuiIcon type="crossInACircleFilled" color="danger" />;
|
||||
|
|
|
@ -106,11 +106,39 @@ describe('action_status', () => {
|
|||
};
|
||||
});
|
||||
|
||||
it(`correctly calculates ACTION_STATES.ERROR`, () => {
|
||||
upstreamJson.actionStatusJson.last_execution.successful = false;
|
||||
const actionStatus = ActionStatus.fromUpstreamJson(upstreamJson);
|
||||
describe(`correctly calculates ACTION_STATES.ERROR`, () => {
|
||||
it('lastExecutionSuccessful is equal to false', () => {
|
||||
upstreamJson.actionStatusJson.last_execution.successful = false;
|
||||
const actionStatus = ActionStatus.fromUpstreamJson(upstreamJson);
|
||||
expect(actionStatus.state).to.be(ACTION_STATES.ERROR);
|
||||
});
|
||||
|
||||
expect(actionStatus.state).to.be(ACTION_STATES.ERROR);
|
||||
it('action is acked and lastAcknowledged is less than lastExecution', () => {
|
||||
const actionStatus = ActionStatus.fromUpstreamJson({
|
||||
...upstreamJson,
|
||||
actionStatusJson: {
|
||||
ack: {
|
||||
state: 'acked',
|
||||
timestamp: '2017-03-01T00:00:00.000Z',
|
||||
},
|
||||
last_execution: {
|
||||
timestamp: '2017-03-02T00:00:00.000Z',
|
||||
},
|
||||
},
|
||||
});
|
||||
expect(actionStatus.state).to.be(ACTION_STATES.ERROR);
|
||||
});
|
||||
|
||||
it('action is ackable and lastSuccessfulExecution is less than lastExecution', () => {
|
||||
delete upstreamJson.actionStatusJson.last_throttle;
|
||||
upstreamJson.actionStatusJson.ack.state = 'ackable';
|
||||
upstreamJson.actionStatusJson.last_successful_execution.timestamp =
|
||||
'2017-03-01T00:00:00.000Z';
|
||||
upstreamJson.actionStatusJson.last_execution.timestamp = '2017-03-02T00:00:00.000Z';
|
||||
const actionStatus = ActionStatus.fromUpstreamJson(upstreamJson);
|
||||
|
||||
expect(actionStatus.state).to.be(ACTION_STATES.ERROR);
|
||||
});
|
||||
});
|
||||
|
||||
it('correctly calculates ACTION_STATES.CONFIG_ERROR', () => {
|
||||
|
@ -192,18 +220,7 @@ describe('action_status', () => {
|
|||
});
|
||||
});
|
||||
|
||||
it(`correctly calculates ACTION_STATES.ERROR`, () => {
|
||||
delete upstreamJson.actionStatusJson.last_throttle;
|
||||
upstreamJson.actionStatusJson.ack.state = 'ackable';
|
||||
upstreamJson.actionStatusJson.last_successful_execution.timestamp =
|
||||
'2017-03-01T00:00:00.000Z';
|
||||
upstreamJson.actionStatusJson.last_execution.timestamp = '2017-03-02T00:00:00.000Z';
|
||||
const actionStatus = ActionStatus.fromUpstreamJson(upstreamJson);
|
||||
|
||||
expect(actionStatus.state).to.be(ACTION_STATES.ERROR);
|
||||
});
|
||||
|
||||
it(`throws an error if it can not determine ACTION_STATE`, () => {
|
||||
it(`correctly calculates ACTION_STATES.UNKNOWN if it can not determine state`, () => {
|
||||
upstreamJson = {
|
||||
id: 'my-action',
|
||||
actionStatusJson: {
|
||||
|
@ -213,9 +230,7 @@ describe('action_status', () => {
|
|||
};
|
||||
const actionStatus = ActionStatus.fromUpstreamJson(upstreamJson);
|
||||
|
||||
expect(() => {
|
||||
actionStatus.state;
|
||||
}).to.throwError(/could not determine action status/i);
|
||||
expect(actionStatus.state).to.be(ACTION_STATES.UNKNOWN);
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
*/
|
||||
|
||||
import { get } from 'lodash';
|
||||
import { badImplementation, badRequest } from 'boom';
|
||||
import { badRequest } from 'boom';
|
||||
import { getMoment } from '../../../../common/lib/get_moment';
|
||||
import { ACTION_STATES } from '../../../../common/constants';
|
||||
import { i18n } from '@kbn/i18n';
|
||||
|
@ -46,6 +46,11 @@ export class ActionStatus {
|
|||
return ACTION_STATES.ACKNOWLEDGED;
|
||||
}
|
||||
|
||||
// A user could potentially land in this state if running on multiple nodes and timing is off
|
||||
if (ackState === 'acked' && this.lastAcknowledged < this.lastExecution) {
|
||||
return ACTION_STATES.ERROR;
|
||||
}
|
||||
|
||||
if (ackState === 'ackable' && this.lastThrottled >= this.lastExecution) {
|
||||
return ACTION_STATES.THROTTLED;
|
||||
}
|
||||
|
@ -58,20 +63,10 @@ export class ActionStatus {
|
|||
return ACTION_STATES.ERROR;
|
||||
}
|
||||
|
||||
// At this point, we cannot determine the action status so we thrown an error.
|
||||
// At this point, we cannot determine the action status so mark it as "unknown".
|
||||
// We should never get to this point in the code. If we do, it means we are
|
||||
// missing an action status and the logic to determine it.
|
||||
throw badImplementation(
|
||||
i18n.translate(
|
||||
'xpack.watcher.models.actionStatus.notDetermineActionStatusBadImplementationMessage',
|
||||
{
|
||||
defaultMessage: 'Could not determine action status; action = {actionStatusJson}',
|
||||
values: {
|
||||
actionStatusJson: JSON.stringify(actionStatusJson),
|
||||
},
|
||||
}
|
||||
)
|
||||
);
|
||||
return ACTION_STATES.UNKNOWN;
|
||||
}
|
||||
|
||||
get isAckable() {
|
||||
|
|
|
@ -12890,7 +12890,6 @@
|
|||
"xpack.watcher.deleteSelectedWatchesConfirmModal.deleteButtonLabel": "{numWatchesToDelete, plural, one {ウォッチ} other {# ウォッチ}}を削除 ",
|
||||
"xpack.watcher.deleteSelectedWatchesConfirmModal.descriptionText": "{numWatchesToDelete, plural, one {削除されたウォッチ} other {削除されたウォッチ}}は回復できません",
|
||||
"xpack.watcher.models.actionStatus.actionStatusJsonPropertyMissingBadRequestMessage": "JSON引数には\"{missingProperty}\"プロパティが含まれている必要があります",
|
||||
"xpack.watcher.models.actionStatus.notDetermineActionStatusBadImplementationMessage": "アクションステータスを把握できませんでした; action = {actionStatusJson}",
|
||||
"xpack.watcher.models.baseAction.selectMessageText": "アクションを実行します。",
|
||||
"xpack.watcher.models.baseAction.simulateButtonLabel": "今すぐこのアクションをシミュレート",
|
||||
"xpack.watcher.models.baseAction.simulateMessage": "アクション {id} のシミュレーションが完了しました",
|
||||
|
|
|
@ -12889,7 +12889,6 @@
|
|||
"xpack.watcher.deleteSelectedWatchesConfirmModal.deleteButtonLabel": "删除 {numWatchesToDelete, plural, one {个监视} other {# 个监视}} ",
|
||||
"xpack.watcher.deleteSelectedWatchesConfirmModal.descriptionText": "无法恢复{numWatchesToDelete, plural, one {已删除监视} other {已删除监视}}。",
|
||||
"xpack.watcher.models.actionStatus.actionStatusJsonPropertyMissingBadRequestMessage": "JSON 参数必须包含“{missingProperty}”属性",
|
||||
"xpack.watcher.models.actionStatus.notDetermineActionStatusBadImplementationMessage": "无法确定操作状态;操作 = {actionStatusJson}",
|
||||
"xpack.watcher.models.baseAction.selectMessageText": "执行操作。",
|
||||
"xpack.watcher.models.baseAction.simulateButtonLabel": "立即模拟此操作",
|
||||
"xpack.watcher.models.baseAction.simulateMessage": "已成功模拟操作 {id}",
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue