Skip to content

Commit

Permalink
Clean up message when audit/uninstall returns 401 (#6735) (#6765)
Browse files Browse the repository at this point in the history
* Clean up message when audit/uninstall returns 401

* Update internal/pkg/agent/install/uninstall.go

Co-authored-by: Craig MacKenzie <[email protected]>

---------

Co-authored-by: Craig MacKenzie <[email protected]>
(cherry picked from commit c82d568)

Co-authored-by: Michel Laterman <[email protected]>
  • Loading branch information
mergify[bot] and michel-laterman authored Feb 18, 2025
1 parent 85fafe2 commit 58d496b
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Kind can be one of:
# - breaking-change: a change to previously-documented behavior
# - deprecation: functionality that is being removed in a later release
# - bug-fix: fixes a problem in a previous version
# - enhancement: extends functionality but does not break or fix existing behavior
# - feature: new functionality
# - known-issue: problems that we are aware of in a given version
# - security: impacts on the security of a product or a user’s deployment.
# - upgrade: important information for someone upgrading from a prior version
# - other: does not fit into any of the other categories
kind: bug-fix

# Change summary; a 80ish characters long description of the change.
summary: Improve message when audit/uninstall returns 401

# Long description; in case the summary is not enough to describe the change
# this field accommodate a description without length limits.
# NOTE: This field will be rendered only for breaking-change and known-issue kinds at the moment.
#description:

# Affected component; usually one of "elastic-agent", "fleet-server", "filebeat", "metricbeat", "auditbeat", "all", etc.
component: elastic-agent

# PR URL; optional; the PR number that added the changeset.
# If not present is automatically filled by the tooling finding the PR where this changelog fragment has been added.
# NOTE: the tooling supports backports, so it's able to fill the original PR number instead of the backport PR number.
# Please provide it if you are adding a fragment for a different PR.
#pr: https://github.com/owner/repo/1234

# Issue URL; optional; the GitHub issue related to this changeset (either closes or is part of).
# If not present is automatically filled by the tooling with the issue linked to the PR number.
issue: https://github.com/elastic/elastic-agent/issues/6711
3 changes: 3 additions & 0 deletions internal/pkg/agent/install/uninstall.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,9 @@ func notifyFleetAuditUninstall(ctx context.Context, log *logp.Logger, pt *progre
// Do not retry if it was a context error, or an error with the request.
if errors.Is(err, context.Canceled) {
return ctx.Err()
} else if errors.Is(err, fleetclient.ErrInvalidAPIKey) {
pt.Describe("API key is invalid (normal if already unenrolled), notification dropped.")
return nil
} else if errors.As(err, &reqErr) {
pt.Describe(fmt.Sprintf("notify Fleet: encountered unretryable error: %v", err))
return err
Expand Down
3 changes: 1 addition & 2 deletions internal/pkg/agent/install/uninstall_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import (
"github.com/elastic/elastic-agent/internal/pkg/agent/configuration"
"github.com/elastic/elastic-agent/internal/pkg/agent/vault"
"github.com/elastic/elastic-agent/internal/pkg/fleetapi"
"github.com/elastic/elastic-agent/internal/pkg/fleetapi/client"
"github.com/elastic/elastic-agent/internal/pkg/remote"
)

Expand Down Expand Up @@ -165,7 +164,7 @@ func TestNotifyFleetAuditUnenroll(t *testing.T) {
w.WriteHeader(http.StatusUnauthorized)
}))
},
err: client.ErrInvalidAPIKey,
err: nil,
}, {
name: "returns 409",
getServer: func() *httptest.Server {
Expand Down

0 comments on commit 58d496b

Please sign in to comment.