Skip to content

Commit

Permalink
add support for additional watch action statuses
Browse files Browse the repository at this point in the history
  • Loading branch information
alisonelizabeth committed Jan 16, 2020
1 parent 6658412 commit 71dbb4c
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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',
}),
};
Original file line number Diff line number Diff line change
Expand Up @@ -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" />;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -46,6 +46,11 @@ export class ActionStatus {
return ACTION_STATES.ACKNOWLEDGED;
}

// A user could potentionally 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;
}
Expand All @@ -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() {
Expand Down

0 comments on commit 71dbb4c

Please sign in to comment.