Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
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
2 changes: 1 addition & 1 deletion x-pack/elastic-agent/CHANGELOG.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
- Fix install command for Fleet Server bootstrap, remove need for --enrollment-token when using --fleet-server {pull}24981[24981]
- Respect host configuration for exposed processes endpoint {pull}25114[25114]
- Set --inscure in container when FLEET_SERVER_ENABLE and FLEET_INSECURE set {pull}25137[25137]

- Fixed: limit for retries to Kibana configurable {issue}25063[25063]
==== New features

- Prepare packaging for endpoint and asc files {pull}20186[20186]
Expand Down
37 changes: 33 additions & 4 deletions x-pack/elastic-agent/pkg/agent/cmd/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"os/exec"
"path/filepath"
"regexp"
"strconv"
"strings"
"sync"
"syscall"
Expand All @@ -40,15 +41,19 @@ import (
)

const (
requestRetrySleep = 1 * time.Second // sleep 1 sec between retries for HTTP requests
maxRequestRetries = 30 // maximum number of retries for HTTP requests
defaultStateDirectory = "/usr/share/elastic-agent/state" // directory that will hold the state data
requestRetrySleepEnv = "KIBANA_REQUEST_RETRY_SLEEP"
maxRequestRetriesEnv = "KIBANA_REQUEST_RETRY_COUNT"
defaultRequestRetrySleep = "1" // sleep 1 sec between retries for HTTP requests

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Can we make this 1s instead and have time parsing? This makes it possible to pass in any time values if needed and makes it more explicity.

defaultMaxRequestRetries = "30" // maximum number of retries for HTTP requests
defaultStateDirectory = "/usr/share/elastic-agent/state" // directory that will hold the state data
)

var (
// Used to strip the appended ({uuid}) from the name of an enrollment token. This makes much easier for
// a container to reference a token by name, without having to know what the generated UUID is for that name.
tokenNameStrip = regexp.MustCompile(`\s\([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}\)$`)
tokenNameStrip = regexp.MustCompile(`\s\([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}\)$`)
requestRetrySleep time.Duration
maxRequestRetries int
)

func newContainerCommand(_ []string, streams *cli.IOStreams) *cobra.Command {
Expand All @@ -70,6 +75,8 @@ The following actions are possible and grouped based on the actions.
KIBANA_FLEET_USERNAME - kibana username to enable Fleet [$KIBANA_USERNAME]
KIBANA_FLEET_PASSWORD - kibana password to enable Fleet [$KIBANA_PASSWORD]
KIBANA_FLEET_CA - path to certificate authority to use with communicate with Kibana [$KIBANA_CA]
KIBANA_REQUEST_RETRY_SLEEP - specifies number of seconds of sleep taken when agent performs a request to kibana [default 1]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

See above

Suggested change
KIBANA_REQUEST_RETRY_SLEEP - specifies number of seconds of sleep taken when agent performs a request to kibana [default 1]
KIBANA_REQUEST_RETRY_SLEEP - specifies number of seconds of sleep taken when agent performs a request to kibana [default 1s]

KIBANA_REQUEST_RETRY_COUNT - specifies number of retries agent performs when executing a request to kibana [default 30]
Comment thread
simitt marked this conversation as resolved.

* Bootstrapping Fleet Server
This bootstraps the Fleet Server to be run by this Elastic Agent. At least one Fleet Server is required in a Fleet
Expand Down Expand Up @@ -163,6 +170,10 @@ func containerCmd(streams *cli.IOStreams, cmd *cobra.Command) error {
return err
}

if err := setRetry(); err != nil {
return err
}

elasticCloud := envBool("ELASTIC_AGENT_CLOUD")
// if not in cloud mode, always run the agent
runAgent := !elasticCloud
Expand Down Expand Up @@ -669,6 +680,24 @@ func setPaths() error {
return nil
}

func setRetry() error {
retrySleepStr := envWithDefault(defaultRequestRetrySleep, requestRetrySleepEnv)
retrySleep, err := strconv.Atoi(retrySleepStr)
if err != nil {
return errors.New(err, fmt.Sprintf("failed to parse '%s'", requestRetrySleepEnv))
}
requestRetrySleep = time.Duration(retrySleep) * time.Second

retryMaxCountStr := envWithDefault(defaultMaxRequestRetries, maxRequestRetriesEnv)
retryRetries, err := strconv.Atoi(retryMaxCountStr)
if err != nil {
return errors.New(err, fmt.Sprintf("failed to parse '%s'", maxRequestRetriesEnv))
}
maxRequestRetries = retryRetries

return nil
}

func syncDir(src string, dest string) error {
return filepath.Walk(src, func(path string, info os.FileInfo, err error) error {
if err != nil {
Expand Down