Skip to content

Commit 0bd97c9

Browse files
[Ingest Manager] Use local temp instead of system one (#21883) (#21906)
[Ingest Manager] Use local temp instead of system one (#21883)
1 parent 6328c86 commit 0bd97c9

File tree

4 files changed

+24
-3
lines changed

4 files changed

+24
-3
lines changed

x-pack/elastic-agent/CHANGELOG.next.asciidoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
- Include inputs in action store actions {pull}21298[21298]
1717
- Fix issue where inputs without processors defined would panic {pull}21628[21628]
1818
- Partial extracted beat result in failure to spawn beat {issue}21718[21718]
19+
- Use local temp instead of system one {pull}21883[21883]
1920
- Fix issue with named pipes on Windows 7 {pull}21931[21931]
2021
- Rename monitoring index from `elastic.agent` to `elastic_agent` {pull}21932[21932]
2122
- Fix missing elastic_agent event data {pull}21994[21994]

x-pack/elastic-agent/pkg/agent/application/paths/paths.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,20 @@ import (
1010
"os"
1111
"path/filepath"
1212
"strings"
13+
"sync"
1314

1415
"github.com/elastic/beats/v7/x-pack/elastic-agent/pkg/release"
1516
)
1617

18+
const (
19+
tempSubdir = "tmp"
20+
)
21+
1722
var (
1823
topPath string
1924
configPath string
2025
logsPath string
26+
tmpCreator sync.Once
2127
)
2228

2329
func init() {
@@ -37,6 +43,16 @@ func Top() string {
3743
return topPath
3844
}
3945

46+
// TempDir returns agent temp dir located within data dir.
47+
func TempDir() string {
48+
tmpDir := filepath.Join(Data(), tempSubdir)
49+
tmpCreator.Do(func() {
50+
// create tempdir as it probably don't exists
51+
os.MkdirAll(tmpDir, 0750)
52+
})
53+
return tmpDir
54+
}
55+
4056
// Home returns a directory where binary lives
4157
func Home() string {
4258
return versionedHome(topPath)

x-pack/elastic-agent/pkg/artifact/install/atomic/atomic_installer.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import (
99
"io/ioutil"
1010
"os"
1111
"path/filepath"
12+
13+
"github.com/elastic/beats/v7/x-pack/elastic-agent/pkg/agent/application/paths"
1214
)
1315

1416
type embeddedInstaller interface {
@@ -31,7 +33,7 @@ func NewInstaller(i embeddedInstaller) (*Installer, error) {
3133
// Install performs installation of program in a specific version.
3234
func (i *Installer) Install(ctx context.Context, programName, version, installDir string) error {
3335
// tar installer uses Dir of installDir to determine location of unpack
34-
tempDir, err := ioutil.TempDir(os.TempDir(), "elastic-agent-install")
36+
tempDir, err := ioutil.TempDir(paths.TempDir(), "elastic-agent-install")
3537
if err != nil {
3638
return err
3739
}

x-pack/elastic-agent/pkg/artifact/install/atomic/atomic_installer_test.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ import (
1414
"testing"
1515

1616
"github.com/stretchr/testify/assert"
17+
18+
"github.com/elastic/beats/v7/x-pack/elastic-agent/pkg/agent/application/paths"
1719
)
1820

1921
func TestOKInstall(t *testing.T) {
@@ -25,7 +27,7 @@ func TestOKInstall(t *testing.T) {
2527
assert.NoError(t, err)
2628

2729
ctx := context.Background()
28-
installDir := filepath.Join(os.TempDir(), "install_dir")
30+
installDir := filepath.Join(paths.TempDir(), "install_dir")
2931

3032
wg.Add(1)
3133
go func() {
@@ -59,7 +61,7 @@ func TestContextCancelledInstall(t *testing.T) {
5961
assert.NoError(t, err)
6062

6163
ctx, cancel := context.WithCancel(context.Background())
62-
installDir := filepath.Join(os.TempDir(), "install_dir")
64+
installDir := filepath.Join(paths.TempDir(), "install_dir")
6365

6466
wg.Add(1)
6567
go func() {

0 commit comments

Comments
 (0)