Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow upgrade action to signal retry #1887

Merged
merged 12 commits into from
Oct 24, 2022
22 changes: 14 additions & 8 deletions internal/pkg/api/handleAck.go
Original file line number Diff line number Diff line change
Expand Up @@ -505,11 +505,7 @@ func (ack *AckT) handleUnenroll(ctx context.Context, zlog zerolog.Logger, agent

func (ack *AckT) handleUpgrade(ctx context.Context, zlog zerolog.Logger, agent *model.Agent, event Event) error {
now := time.Now().UTC().Format(time.RFC3339)
doc := bulk.UpdateFields{
dl.FieldUpgradeStartedAt: nil,
dl.FieldUpgradeStatus: nil,
dl.FieldUpgradedAt: now,
}
doc := bulk.UpdateFields{}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what does an empty UpdateFields do?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's a nop

Copy link
Contributor

@juliaElastic juliaElastic Oct 25, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we remove it then?

if event.Error != "" {
// unmarshal event payload
var pl struct {
Expand All @@ -524,10 +520,20 @@ func (ack *AckT) handleUpgrade(ctx context.Context, zlog zerolog.Logger, agent *
// if the payload indicates a retry, mark change the upgrade status to retrying.
if pl.Retry {
zlog.Info().Int("retry_attempt", pl.Attempt).Msg("marking agent upgrade as retrying")
doc[dl.FieldUpgradeStatus] = "retrying" // TODO should we also change FieldUpgradedAt and FieldUpgradeStated at?
doc[dl.FieldUpgradeStatus] = "retrying" // Keep FieldUpgradeStatedAt abd FieldUpgradeded at to original values
} else {
zlog.Info().Int("retry_attempt", pl.Attempt).Msg("marking agent upgrade as failed")
doc[dl.FieldUpgradeStatus] = "failed" // TODO should we also change FieldUpgradedAt and FieldUpgradeStated at?
zlog.Info().Int("retry_attempt", pl.Attempt).Msg("Agent upgrade failed, marking agent as healthy, agent logs contain failure message")
doc = bulk.UpdateFields{
dl.FieldUpgradeStartedAt: nil,
dl.FieldUpgradeStatus: nil,
michel-laterman marked this conversation as resolved.
Show resolved Hide resolved
dl.FieldUpgradedAt: now,
michel-laterman marked this conversation as resolved.
Show resolved Hide resolved
}
}
} else {
doc = bulk.UpdateFields{
dl.FieldUpgradeStartedAt: nil,
dl.FieldUpgradeStatus: nil,
dl.FieldUpgradedAt: now,
}
}

Expand Down
2 changes: 1 addition & 1 deletion internal/pkg/api/handleAck_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -599,7 +599,7 @@ func TestAckHandleUpgrade(t *testing.T) {
if err := json.Unmarshal(p, &body); err != nil {
t.Fatal(err)
}
return body.Doc.Status == "failed"
return body.Doc.Status == ""
}), mock.Anything).Return(nil).Once()
return m
},
Expand Down