-
Notifications
You must be signed in to change notification settings - Fork 100
Make action optional when upgrade details are provided #5609
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
base: main
Are you sure you want to change the base?
Changes from 7 commits
f8a4a2c
6331a01
e455769
e5e9f68
8a895c0
80d23ca
bd39320
0862864
7809dfb
45376cb
0ad1868
72ee7a5
3d7aa6a
42f4781
0e8cefe
378d270
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -719,67 +719,6 @@ func TestAckHandleUpgrade(t *testing.T) { | |
| ESDocument: model.ESDocument{Id: "ab12dcd8-bde0-4045-92dc-c4b27668d735"}, | ||
| Agent: &model.AgentMetadata{Version: "8.0.0"}, | ||
| }, | ||
| }, { | ||
| name: "retry signaled", | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we need to remove these tests in this PR? |
||
| event: UpgradeEvent{ | ||
| Error: ptr("upgrade error"), | ||
| Payload: &struct { | ||
| Retry bool `json:"retry"` | ||
| RetryAttempt int `json:"retry_attempt"` | ||
| }{ | ||
| Retry: true, | ||
| RetryAttempt: 1, | ||
| }, | ||
| }, | ||
| bulker: func(t *testing.T) *ftesting.MockBulk { | ||
| m := ftesting.NewMockBulk() | ||
| m.On("Update", mock.Anything, mock.Anything, mock.Anything, mock.MatchedBy(func(p []byte) bool { | ||
| var body struct { | ||
| Doc struct { | ||
| Status string `json:"upgrade_status"` | ||
| } `json:"doc"` | ||
| } | ||
| if err := json.Unmarshal(p, &body); err != nil { | ||
| t.Fatal(err) | ||
| } | ||
| return body.Doc.Status == "retrying" | ||
| }), mock.Anything).Return(nil).Once() | ||
| return m | ||
| }, | ||
| agent: &model.Agent{ | ||
| ESDocument: model.ESDocument{Id: "ab12dcd8-bde0-4045-92dc-c4b27668d735"}, | ||
| Agent: &model.AgentMetadata{Version: "8.0.0"}, | ||
| }, | ||
| }, { | ||
| name: "no more retries", | ||
| event: UpgradeEvent{ | ||
| Error: ptr("upgrade error"), | ||
| Payload: &struct { | ||
| Retry bool `json:"retry"` | ||
| RetryAttempt int `json:"retry_attempt"` | ||
| }{ | ||
| Retry: false, | ||
| }, | ||
| }, | ||
| bulker: func(t *testing.T) *ftesting.MockBulk { | ||
| m := ftesting.NewMockBulk() | ||
| m.On("Update", mock.Anything, mock.Anything, mock.Anything, mock.MatchedBy(func(p []byte) bool { | ||
| var body struct { | ||
| Doc struct { | ||
| Status string `json:"upgrade_status"` | ||
| } `json:"doc"` | ||
| } | ||
| if err := json.Unmarshal(p, &body); err != nil { | ||
| t.Fatal(err) | ||
| } | ||
| return body.Doc.Status == "failed" | ||
| }), mock.Anything).Return(nil).Once() | ||
| return m | ||
| }, | ||
| agent: &model.Agent{ | ||
| ESDocument: model.ESDocument{Id: "ab12dcd8-bde0-4045-92dc-c4b27668d735"}, | ||
| Agent: &model.AgentMetadata{Version: "8.0.0"}, | ||
| }, | ||
| }, { | ||
| name: "keep upgrade_attempts if upgrade_details is not nil", | ||
| event: UpgradeEvent{}, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -28,6 +28,7 @@ import ( | |
| "github.com/elastic/fleet-server/v7/internal/pkg/checkin" | ||
| "github.com/elastic/fleet-server/v7/internal/pkg/config" | ||
| "github.com/elastic/fleet-server/v7/internal/pkg/dl" | ||
| "github.com/elastic/fleet-server/v7/internal/pkg/es" | ||
| "github.com/elastic/fleet-server/v7/internal/pkg/logger/ecs" | ||
| "github.com/elastic/fleet-server/v7/internal/pkg/model" | ||
| "github.com/elastic/fleet-server/v7/internal/pkg/monitor" | ||
|
|
@@ -454,22 +455,21 @@ func (ct *CheckinT) processUpgradeDetails(ctx context.Context, agent *model.Agen | |
| return nil | ||
| } | ||
| // update docs with in progress details | ||
|
|
||
| vSpan, vCtx := apm.StartSpan(ctx, "Check update action", "validate") | ||
| action, err := ct.verifyActionExists(ctx, vSpan, agent, details) | ||
| if err != nil { | ||
|
|
||
| var actionTraceparent string | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @blakerouse normally when no actin is present we stop here then later we check if we have here when setting parent span and continue until we reach a point where we update details on line 543 |
||
| if action, err := ct.verifyActionExists(ctx, vSpan, agent, details); err == nil && action != nil { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does Kibana tolerate having an action ID it doesn't recognize as well? I think passing through the upgrade details unmodified is correct, but we need to avoid Kibana now or in the future trying to do this same validation or making assumption about this field.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Well a possibility here would be removing the action_id if it doesn't exist so kibana can't depend on it, or putting some marker in the details about whether the action exists or not (though kibana can also just check this).
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @juliaElastic any opinions on if sending upgrade_details to Kibana for action_ids that don't exist or are from another cluster is a problem? |
||
| actionTraceparent = action.Traceparent | ||
| } else if !errors.Is(err, es.ErrNotFound) { | ||
michel-laterman marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| return err | ||
| } | ||
| if action == nil { | ||
| return nil | ||
| } | ||
|
|
||
| // link action with APM spans | ||
| var links []apm.SpanLink | ||
| if ct.bulker.HasTracer() && action.Traceparent != "" { | ||
| traceCtx, err := apmhttp.ParseTraceparentHeader(action.Traceparent) | ||
| if ct.bulker.HasTracer() && actionTraceparent != "" { | ||
| traceCtx, err := apmhttp.ParseTraceparentHeader(actionTraceparent) | ||
| if err != nil { | ||
| zerolog.Ctx(vCtx).Trace().Err(err).Msgf("Error parsing traceparent: %s %s", action.Traceparent, err) | ||
| zerolog.Ctx(vCtx).Trace().Err(err).Msgf("Error parsing traceparent: %s %s", actionTraceparent, err) | ||
| } else { | ||
| links = []apm.SpanLink{ | ||
| { | ||
|
|
@@ -565,7 +565,6 @@ func (ct *CheckinT) markUpgradeComplete(ctx context.Context, agent *model.Agent) | |
| doc := bulk.UpdateFields{ | ||
| dl.FieldUpgradeDetails: nil, | ||
| dl.FieldUpgradeStartedAt: nil, | ||
| dl.FieldUpgradeStatus: nil, | ||
michalpristas marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| dl.FieldUpgradedAt: time.Now().UTC().Format(time.RFC3339), | ||
| } | ||
| body, err := doc.Marshal() | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.