Skip to content

Commit

Permalink
fix: use agent tmp folder only in windows (#1600)
Browse files Browse the repository at this point in the history
  • Loading branch information
rubenruizdegauna authored Mar 17, 2023
1 parent ea58c3e commit 5051b41
Show file tree
Hide file tree
Showing 8 changed files with 9 additions and 37 deletions.
12 changes: 1 addition & 11 deletions cmd/newrelic-infra/initialize/initialize_darwin_amd64.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,15 @@
package initialize

import (
"os"

"github.com/newrelic/infrastructure-agent/pkg/config"
"github.com/newrelic/infrastructure-agent/pkg/log"
)

// only used in windows. it will be refactored.
const agentTemporaryFolder = "/usr/local/var/db/newrelic-infra/tmp"

// AgentService performs OS-specific initialization steps for the Agent service.
// It is executed after the initialize.osProcess function.
func AgentService(cfg *config.Config) error {
err := emptyTemporaryFolder(cfg)
if err != nil {
log.WithField("temporaryFolder", agentTemporaryFolder).
WithError(err).
Error("error emptying temporary folder")
os.Exit(1)
}

return nil
}

Expand Down
12 changes: 1 addition & 11 deletions cmd/newrelic-infra/initialize/initialize_darwin_arm64.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,15 @@
package initialize

import (
"os"

"github.com/newrelic/infrastructure-agent/pkg/config"
"github.com/newrelic/infrastructure-agent/pkg/log"
)

// only used in windows. it will be refactored.
const agentTemporaryFolder = "/opt/homebrew/var/db/newrelic-infra/tmp"

// AgentService performs OS-specific initialization steps for the Agent service.
// It is executed after the initialize.osProcess function.
func AgentService(cfg *config.Config) error {
err := emptyTemporaryFolder(cfg)
if err != nil {
log.WithField("temporaryFolder", agentTemporaryFolder).
WithError(err).
Error("error emptying temporary folder")
os.Exit(1)
}

return nil
}

Expand Down
8 changes: 0 additions & 8 deletions cmd/newrelic-infra/initialize/initialize_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,6 @@ const (
// AgentService performs OS-specific initialization steps for the Agent service.
// It is executed after the initialize.osProcess function.
func AgentService(cfg *config.Config) error {
err := emptyTemporaryFolder(cfg)
if err != nil {
log.WithField("temporaryFolder", agentTemporaryFolder).
WithError(err).
Error("error emptying temporary folder")
os.Exit(1)
}

return nil
}

Expand Down
3 changes: 2 additions & 1 deletion pkg/config/config_darwin_amd64.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
package config

import (
"os"
"path/filepath"
)

Expand All @@ -12,5 +13,5 @@ func init() { //nolint:gochecknoinits
filepath.Join("/usr", "local", "etc", "newrelic-infra", "newrelic-infra.yml"),
}
defaultAgentDir = filepath.Join("/usr", "local", "var", "db", "newrelic-infra")
defaultAgentTempDir = filepath.Join(defaultAgentDir, agentTemporaryFolderName)
defaultAgentTempDir = os.TempDir()
}
3 changes: 2 additions & 1 deletion pkg/config/config_darwin_arm64.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
package config

import (
"os"
"path/filepath"
)

Expand All @@ -12,5 +13,5 @@ func init() { //nolint:gochecknoinits
filepath.Join("/opt", "homebrew", "etc", "newrelic-infra", "newrelic-infra.yml"),
}
defaultAgentDir = filepath.Join("/opt", "homebrew", "var", "db", "newrelic-infra")
defaultAgentTempDir = filepath.Join(defaultAgentDir, agentTemporaryFolderName)
defaultAgentTempDir = os.TempDir()
}
3 changes: 1 addition & 2 deletions pkg/config/config_darwin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ package config
import (
"io/ioutil"
"os"
"path/filepath"
"testing"

"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -42,7 +41,7 @@ custom_attributes:
assert.Equal(t, false, cfg.Log.Rotate.CompressionEnabled)
assert.Equal(t, "", cfg.Log.Rotate.FilePattern)

assert.Equal(t, filepath.Join(cfg.AgentDir, agentTemporaryFolderName), cfg.AgentTempDir)
assert.Equal(t, os.TempDir(), cfg.AgentTempDir)
}

func TestRotateConfig(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/config/config_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func init() {
// this is the default dir the infra sdk uses to store "temporary" data
defaultIntegrationsTempDir = filepath.Join("/tmp", "nr-integrations")

defaultAgentTempDir = filepath.Join(defaultAgentDir, agentTemporaryFolderName)
defaultAgentTempDir = os.TempDir()
}

func configOverride(cfg *Config) {
Expand Down
3 changes: 1 addition & 2 deletions pkg/config/config_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ package config
import (
"io/ioutil"
"os"
"path/filepath"
"testing"

"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -127,7 +126,7 @@ log:
assert.Equal(t, false, cfg.Log.Rotate.CompressionEnabled)
assert.Equal(t, "", cfg.Log.Rotate.FilePattern)

assert.Equal(t, filepath.Join(cfg.AgentDir, agentTemporaryFolderName), cfg.AgentTempDir)
assert.Equal(t, os.TempDir(), cfg.AgentTempDir)
}

func TestRotateConfig(t *testing.T) {
Expand Down

0 comments on commit 5051b41

Please sign in to comment.