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

[Ingest Manager] Use local temp instead of system one #21883

Merged
merged 5 commits into from
Oct 16, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
12 changes: 12 additions & 0 deletions x-pack/elastic-agent/pkg/agent/application/paths/paths.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ import (
"github.com/elastic/beats/v7/x-pack/elastic-agent/pkg/release"
)

const (
tempSubdir = "tmp"
)

var (
topPath string
configPath string
Expand All @@ -29,6 +33,9 @@ func init() {
fs.StringVar(&topPath, "path.home", topPath, "Agent root path")
fs.StringVar(&configPath, "path.config", configPath, "Config path is the directory Agent looks for its config file")
fs.StringVar(&logsPath, "path.logs", logsPath, "Logs path contains Agent log output")

// create tempdir as it probably don't exists
os.MkdirAll(TempDir(), 0750)
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this TempDir be wiped on startup to make sure it is always "clean"?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

we can wipe it but ideally whoever uses it cleans after work is done so we dont have to wait until restart and we free resources

}

// Top returns the top directory for Elastic Agent, all the versioned
Expand All @@ -37,6 +44,11 @@ func Top() string {
return topPath
}

// TempDir returns agent temp dir located within data dir.
func TempDir() string {
return filepath.Join(Data(), tempSubdir)
}

// Home returns a directory where binary lives
func Home() string {
return versionedHome(topPath)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (
"io/ioutil"
"os"
"path/filepath"

"github.com/elastic/beats/v7/x-pack/elastic-agent/pkg/agent/application/paths"
)

type embeddedInstaller interface {
Expand All @@ -31,7 +33,7 @@ func NewInstaller(i embeddedInstaller) (*Installer, error) {
// Install performs installation of program in a specific version.
func (i *Installer) Install(ctx context.Context, programName, version, installDir string) error {
// tar installer uses Dir of installDir to determine location of unpack
tempDir, err := ioutil.TempDir(os.TempDir(), "elastic-agent-install")
tempDir, err := ioutil.TempDir(paths.TempDir(), "elastic-agent-install")
if err != nil {
return err
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"sync"
"testing"

"github.com/elastic/beats/v7/x-pack/elastic-agent/pkg/agent/application/paths"
"github.com/stretchr/testify/assert"
)

Expand All @@ -25,7 +26,7 @@ func TestOKInstall(t *testing.T) {
assert.NoError(t, err)

ctx := context.Background()
installDir := filepath.Join(os.TempDir(), "install_dir")
installDir := filepath.Join(paths.TempDir(), "install_dir")

wg.Add(1)
go func() {
Expand Down Expand Up @@ -59,7 +60,7 @@ func TestContextCancelledInstall(t *testing.T) {
assert.NoError(t, err)

ctx, cancel := context.WithCancel(context.Background())
installDir := filepath.Join(os.TempDir(), "install_dir")
installDir := filepath.Join(paths.TempDir(), "install_dir")

wg.Add(1)
go func() {
Expand Down