[Watcher] Fix logic that determines watch error state (#67952)

Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
This commit is contained in:
Alison Goryachev 2020-06-12 10:23:04 -04:00 committed by GitHub
parent 1277934588
commit fc572c9e1a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 9 additions and 2 deletions

View file

@ -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',
@ -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);

View file

@ -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');
@ -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;
}

View file

@ -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);
});