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

Added loggers for Fleet enrollment call failures #6477

Open
wants to merge 39 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 32 commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
888e63f
Added skip audit/unenroll flag to uninstall command
Rohit-code14 Dec 4, 2024
b2983da
Merge branch 'elastic:main' into main
Rohit-code14 Dec 4, 2024
b5fb853
Added tests for skip-fleet-audit flag
Rohit-code14 Dec 10, 2024
b8405a0
Merge branch 'elastic:main' into main
Rohit-code14 Dec 10, 2024
b659cc2
Added tests for skip-fleet-audit flag
Rohit-code14 Dec 10, 2024
848e325
Merge branch 'main' of https://github.com/Rohit-code14/elastic-agent
Rohit-code14 Dec 10, 2024
17bd84d
Added tests for skip-fleet-audit flag
Rohit-code14 Dec 10, 2024
a6d5bd9
Merge branch 'elastic:main' into main
Rohit-code14 Dec 11, 2024
2d1d8b4
Merge branch 'main' into main
Rohit-code14 Dec 12, 2024
8d57889
Merge branch 'main' into main
Rohit-code14 Dec 13, 2024
0e12052
ran mage fmt
Rohit-code14 Dec 14, 2024
b0b048c
Merge branch 'main' into main
Rohit-code14 Dec 14, 2024
2b8165b
Merge branch 'main' into main
Rohit-code14 Dec 17, 2024
8874f84
Resolved conflicts
Rohit-code14 Dec 18, 2024
e058a38
Merge branch 'main' into main
Rohit-code14 Dec 19, 2024
9d83f96
Test all combinations for which fleet audit/unenroll will be skipped
Rohit-code14 Dec 19, 2024
e2cfb10
Merge branch 'main' of https://github.com/Rohit-code14/elastic-agent
Rohit-code14 Dec 19, 2024
ba3eb1f
Merge branch 'main' into main
Rohit-code14 Dec 23, 2024
cd45ac2
Merge branch 'main' into main
michalpristas Dec 27, 2024
4bb8dcb
Merge branch 'main' into main
Rohit-code14 Dec 27, 2024
92c8b58
Merge branch 'main' into main
Rohit-code14 Dec 30, 2024
6f2299c
Merge branch 'elastic:main' into main
Rohit-code14 Jan 2, 2025
5378c4d
Merge branch 'elastic:main' into main
Rohit-code14 Jan 4, 2025
bee2d6d
Added status logger
Rohit-code14 Jan 4, 2025
f8098ce
Added status logger
Rohit-code14 Jan 4, 2025
2bbe0b1
Merge branch 'elastic:main' into main
Rohit-code14 Jan 6, 2025
733ebae
Added loggers for fleet enrollment failure
Rohit-code14 Jan 6, 2025
23879b2
Added loggers for fleet enrollment failure
Rohit-code14 Jan 6, 2025
7029b44
Skip retry if there is no error
Rohit-code14 Jan 6, 2025
42597cb
Added logger for fleet enrollment failures
Rohit-code14 Jan 6, 2025
c7f5fe2
Added logger for fleet enrollment failures
Rohit-code14 Jan 6, 2025
238239c
Added logger for fleet enrollment failures
Rohit-code14 Jan 6, 2025
916eb08
Added logger for fleet enrollment failures
Rohit-code14 Jan 7, 2025
dd47311
Added logger for fleet enrollment failures
Rohit-code14 Jan 7, 2025
3a04378
Added logger for fleet enrollment failures
Rohit-code14 Jan 7, 2025
45220c2
Added logger for fleet enrollment failures
Rohit-code14 Jan 7, 2025
3be3722
Merge branch 'main' into main
Rohit-code14 Jan 7, 2025
52362ac
Merge branch 'main' into main
Rohit-code14 Jan 8, 2025
2612a0b
Merge branch 'main' into main
Rohit-code14 Jan 8, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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: enhancement

# Change summary; a 80ish characters long description of the change.
summary: Added logger to print the status and code when enrollment call to fleet failed.

# 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/6287
16 changes: 10 additions & 6 deletions internal/pkg/agent/cmd/enroll_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -524,21 +524,25 @@ func (c *enrollCmd) enrollWithBackoff(ctx context.Context, persistentConfig map[
}

c.log.Infof("1st enrollment attempt failed, retrying enrolling to URL: %s with exponential backoff (init %s, max %s)", c.client.URI(), enrollBackoffInit, enrollBackoffMax)

signal := make(chan struct{})
defer close(signal)
backExp := backoff.NewExpBackoff(signal, enrollBackoffInit, enrollBackoffMax)

for {
retry := false
if errors.Is(err, fleetapi.ErrTooManyRequests) {
c.log.Warn("Too many requests on the remote server, will retry in a moment.")
switch {
case errors.Is(err, fleetapi.ErrTooManyRequests):
c.log.Warnf("%s. Too many requests on the remote server, will retry in a moment.", err.Error())
Rohit-code14 marked this conversation as resolved.
Show resolved Hide resolved
retry = true
} else if errors.Is(err, fleetapi.ErrConnRefused) {
c.log.Warn("Remote server is not ready to accept connections, will retry in a moment.")
case errors.Is(err, fleetapi.ErrConnRefused):
c.log.Warnf("%s. Remote server is not ready to accept connections, will retry in a moment.", err.Error())
Rohit-code14 marked this conversation as resolved.
Show resolved Hide resolved
retry = true
} else if errors.Is(err, fleetapi.ErrTemporaryServerError) {
c.log.Warn("Remote server failed to handle the request, will retry in a moment.")
case errors.Is(err, fleetapi.ErrTemporaryServerError):
c.log.Warnf("%s. Remote server failed to handle the request, will retry in a moment.", err.Error())
Rohit-code14 marked this conversation as resolved.
Show resolved Hide resolved
retry = true
case err != nil:
c.log.Warnf("Enrollment failed: %s", err.Error())
}
if !retry {
break
Expand Down
16 changes: 8 additions & 8 deletions internal/pkg/fleetapi/enroll_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,19 @@ import (
type EnrollType string

// ErrTooManyRequests is received when the remote server is overloaded.
var ErrTooManyRequests = errors.New("too many requests received (429)")
var ErrTooManyRequests = errors.New("Received status 429(TooManyRequest)")
Rohit-code14 marked this conversation as resolved.
Show resolved Hide resolved

// ErrConnRefused is returned when the connection to the server is refused.
var ErrConnRefused = errors.New("connection refused")
var ErrConnRefused = errors.New("Connection refused")

// ErrTemporaryServerError is returned when the request caused a temporary server error
var ErrTemporaryServerError = errors.New("temporary server error, please retry later")

// temporaryServerErrorCodes defines status codes that allow clients to retry their request.
var temporaryServerErrorCodes = map[int]struct{}{
http.StatusBadGateway: {},
http.StatusServiceUnavailable: {},
http.StatusGatewayTimeout: {},
var temporaryServerErrorCodes = map[int]string{
http.StatusBadGateway: "BadGateway",
http.StatusServiceUnavailable: "ServiceUnavailable",
http.StatusGatewayTimeout: "GatewayTimeout",
}

const (
Expand Down Expand Up @@ -223,8 +223,8 @@ func (e *EnrollCmd) Execute(ctx context.Context, r *EnrollRequest) (*EnrollRespo
return nil, ErrTooManyRequests
}

if _, temporary := temporaryServerErrorCodes[resp.StatusCode]; temporary {
return nil, fmt.Errorf("received code %d: %w", resp.StatusCode, ErrTemporaryServerError)
if status, temporary := temporaryServerErrorCodes[resp.StatusCode]; temporary {
return nil, fmt.Errorf("received status code %d (%s): %w", resp.StatusCode, status, ErrTemporaryServerError)
}

if resp.StatusCode != http.StatusOK {
Expand Down