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

Fix elastic-agent cloud image run issues #1630

Closed
Show file tree
Hide file tree
Changes from all 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
31 changes: 31 additions & 0 deletions changelog/fragments/1666988983-cloud-build-paths.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# 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: fix runtime path setup when run in container mode

# Long description; in case the summary is not enough to describe the change
# this field accommodate a description without length limits.
#description:

# Affected component; a word indicating the component this changeset affects.
component: cmd/container.go

# PR number; 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: 1630

# Issue number; 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: 1234
14 changes: 6 additions & 8 deletions internal/pkg/agent/cmd/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ import (
const (
requestRetrySleepEnv = "KIBANA_REQUEST_RETRY_SLEEP"
maxRequestRetriesEnv = "KIBANA_REQUEST_RETRY_COUNT"
defaultRequestRetrySleep = "1s" // sleep 1 sec between retries for HTTP requests
defaultMaxRequestRetries = "30" // maximum number of retries for HTTP requests
defaultStateDirectory = "/usr/share/elastic-agent/state" // directory that will hold the state data
Copy link
Contributor

@michalpristas michalpristas Oct 29, 2022

Choose a reason for hiding this comment

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

this is here probably to share state across runs. have mounted volume.
this PR fixes the problem but i don't believe it's proper fix and will introduce another set of issues.

i believe proper fix would be to fix not just data/downloads but also data/components
will prepare PR on monday and test it as well

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

var (
Expand Down Expand Up @@ -766,13 +766,12 @@ func setPaths(statePath, configPath, logsPath string, writePaths bool) error {
if statePath == "" {
statePath = defaultStateDirectory
}
topPath := filepath.Join(statePath, "data")
configPath = envWithDefault(configPath, "CONFIG_PATH")
if configPath == "" {
configPath = statePath
}
// ensure that the directory and sub-directory data exists
if err := os.MkdirAll(topPath, 0755); err != nil {
if err := os.MkdirAll(statePath, 0755); err != nil {
return fmt.Errorf("preparing STATE_PATH(%s) failed: %w", statePath, err)
}
// ensure that the elastic-agent.yml exists in the state directory or if given in the config directory
Expand All @@ -789,10 +788,9 @@ func setPaths(statePath, configPath, logsPath string, writePaths bool) error {
}
originalInstall := paths.Install()
originalTop := paths.Top()
paths.SetTop(topPath)
paths.SetTop(statePath)
paths.SetConfig(configPath)
// when custom top path is provided the home directory is not versioned
paths.SetVersionHome(false)
Copy link
Member

Choose a reason for hiding this comment

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

I'm curious to know what this does (I expect we need Michal or Blake to answer this). It's a bit hard to tell from the code.

As far as I can tell in the container I built, the home path is versioned by default. I get /usr/share/elastic-agent/data/elastic-agent-fc3eba. I don't know that this would change if the STATE_PATH were to change either so removing it seems right but it would be good to confirm.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yah, this just adds the elastic-agent-fc3eba directory, which is still there in docker.


// install path stays on container default mount (otherwise a bind mounted directory could have noexec set)
paths.SetInstall(originalInstall)
// set LOGS_PATH is given
Expand Down