Skip to content

Commit

Permalink
[Watcher] Fix logic that determines watch error state (#67952)
Browse files Browse the repository at this point in the history
Co-authored-by: Elastic Machine <[email protected]>
  • Loading branch information
alisonelizabeth and elasticmachine authored Jun 12, 2020
1 parent 1277934 commit fc572c9
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ describe('action_status', () => {
beforeEach(() => {
upstreamJson = {
id: 'my-action',
lastCheckedRawFormat: '2017-03-01T20:55:49.679Z',
actionStatusJson: {
ack: {
timestamp: '2017-03-01T20:56:58.442Z',
Expand All @@ -107,7 +108,7 @@ describe('action_status', () => {
});

describe(`correctly calculates ACTION_STATES.ERROR`, () => {
it('lastExecutionSuccessful is equal to false', () => {
it('lastExecutionSuccessful is equal to false and it is the most recent execution', () => {
upstreamJson.actionStatusJson.last_execution.successful = false;
const actionStatus = ActionStatus.fromUpstreamJson(upstreamJson);
expect(actionStatus.state).to.be(ACTION_STATES.ERROR);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ export class ActionStatus {
this.id = props.id;
this.actionStatusJson = props.actionStatusJson;
this.errors = props.errors;
this.lastCheckedRawFormat = props.lastCheckedRawFormat;

this.lastExecutionRawFormat = get(this.actionStatusJson, 'last_execution.timestamp');
this.lastAcknowledged = getMoment(get(this.actionStatusJson, 'ack.timestamp'));
this.lastExecution = getMoment(get(this.actionStatusJson, 'last_execution.timestamp'));
this.lastExecutionSuccessful = get(this.actionStatusJson, 'last_execution.successful');
Expand All @@ -30,7 +32,10 @@ export class ActionStatus {
const actionStatusJson = this.actionStatusJson;
const ackState = actionStatusJson.ack.state;

if (this.lastExecutionSuccessful === false) {
if (
this.lastExecutionSuccessful === false &&
this.lastCheckedRawFormat === this.lastExecutionRawFormat
) {
return ACTION_STATES.ERROR;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ export class WatchStatus {
id,
actionStatusJson,
errors: this.watchErrors.actions && this.watchErrors.actions[id],
lastCheckedRawFormat: get(this.watchStatusJson, 'last_checked'),
};
return ActionStatus.fromUpstreamJson(json);
});
Expand Down

0 comments on commit fc572c9

Please sign in to comment.