Skip to content
Open
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
8 changes: 4 additions & 4 deletions agent/agents/supervisor/supervisor.go
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ func (s *Supervisor) setAgentProcesses(agentProcesses map[string]*agentv1.SetSta

delete(s.agentProcesses, agentID)

agentTmp := filepath.Join(s.cfg.Get().Paths.TempDir, strings.ToLower(agent.requestedState.Type.String()), agentID)
agentTmp := filepath.Join(s.cfg.Get().Paths.TempDir, trimPrefix(agent.requestedState.Type.String()), agentID)
err := os.RemoveAll(agentTmp)
if err != nil {
s.l.Warnf("Failed to cleanup directory '%s': %s", agentTmp, err.Error())
Expand Down Expand Up @@ -370,7 +370,7 @@ func (s *Supervisor) setBuiltinAgents(builtinAgents map[string]*agentv1.SetState

delete(s.builtinAgents, agentID)

agentTmp := filepath.Join(s.cfg.Get().Paths.TempDir, strings.ToLower(agent.requestedState.Type.String()), agentID)
agentTmp := filepath.Join(s.cfg.Get().Paths.TempDir, trimPrefix(agent.requestedState.Type.String()), agentID)
err := os.RemoveAll(agentTmp)
if err != nil {
s.l.Warnf("Failed to cleanup directory '%s': %s", agentTmp, err.Error())
Expand Down Expand Up @@ -579,7 +579,7 @@ func (s *Supervisor) startBuiltin(agentID string, builtinAgent *agentv1.SetState

var dsn string
if builtinAgent.TextFiles != nil {
tempDir := filepath.Join(cfg.Paths.TempDir, strings.ToLower(builtinAgent.Type.String()), agentID)
tempDir := filepath.Join(cfg.Paths.TempDir, trimPrefix(builtinAgent.Type.String()), agentID)
dsn, err = templates.RenderDSN(builtinAgent.Dsn, builtinAgent.TextFiles, tempDir)
if err != nil {
cancel()
Expand Down Expand Up @@ -804,7 +804,7 @@ func (s *Supervisor) processParams(agentID string, agentProcess *agentv1.SetStat
TextFiles: agentProcess.TextFiles,
TemplateLeftDelim: agentProcess.TemplateLeftDelim,
TemplateRightDelim: agentProcess.TemplateRightDelim,
TempDir: filepath.Join(cfg.Paths.TempDir, strings.ToLower(agentProcess.Type.String()), agentID),
TempDir: filepath.Join(cfg.Paths.TempDir, trimPrefix(agentProcess.Type.String()), agentID),
}

processParams.TemplateRenderer = tr
Expand Down
18 changes: 9 additions & 9 deletions agent/agents/supervisor/supervisor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -371,18 +371,18 @@ func TestSupervisorProcessParams(t *testing.T) {
actual, err := s.processParams("ID", p, 12345)
require.NoError(t, err)

configFilePath := filepath.Join(s.cfg.Get().Paths.TempDir, "agent_type_mysqld_exporter", "ID", "Config")
configFilePath := filepath.Join(s.cfg.Get().Paths.TempDir, "mysqld_exporter", "ID", "Config")
expected := process.Params{
Path: "/path/to/mysql_exporter",
Args: []string{
"-web.listen-address=:12345",
"-web.ssl-cert-file=" + filepath.Join(s.cfg.Get().Paths.TempDir, "agent_type_mysqld_exporter", "ID", "Cert"),
"-web.ssl-cert-file=" + filepath.Join(s.cfg.Get().Paths.TempDir, "mysqld_exporter", "ID", "Cert"),
"-web.config=" + configFilePath,
},
Env: []string{
"MONGODB_URI=mongodb://username:s3cur3%20p%40$$w0r4.@1.2.3.4:12345/?connectTimeoutMS=1000&ssl=true&" +
"sslCaFile=" + filepath.Join(s.cfg.Get().Paths.TempDir, "agent_type_mysqld_exporter", "ID", "caFilePlaceholder") +
"&sslCertificateKeyFile=" + filepath.Join(s.cfg.Get().Paths.TempDir, "agent_type_mysqld_exporter", "ID", "certificateKeyFilePlaceholder"),
"sslCaFile=" + filepath.Join(s.cfg.Get().Paths.TempDir, "mysqld_exporter", "ID", "caFilePlaceholder") +
"&sslCertificateKeyFile=" + filepath.Join(s.cfg.Get().Paths.TempDir, "mysqld_exporter", "ID", "certificateKeyFilePlaceholder"),
"HTTP_AUTH=pmm:secret",
"TEST=:12345",
},
Expand Down Expand Up @@ -520,9 +520,9 @@ server {
tls {
http = true
rpc = true
ca_file = "` + filepath.Join(s.cfg.Get().Paths.TempDir, "agent_type_nomad_agent", "ID", "caCert") + `" # filled by PMM Agent
cert_file = "` + filepath.Join(s.cfg.Get().Paths.TempDir, "agent_type_nomad_agent", "ID", "certFile") + `" # filled by PMM Agent
key_file = "` + filepath.Join(s.cfg.Get().Paths.TempDir, "agent_type_nomad_agent", "ID", "keyFile") + `" # filled by PMM Agent
ca_file = "` + filepath.Join(s.cfg.Get().Paths.TempDir, "nomad_agent", "ID", "caCert") + `" # filled by PMM Agent
cert_file = "` + filepath.Join(s.cfg.Get().Paths.TempDir, "nomad_agent", "ID", "certFile") + `" # filled by PMM Agent
key_file = "` + filepath.Join(s.cfg.Get().Paths.TempDir, "nomad_agent", "ID", "keyFile") + `" # filled by PMM Agent

verify_server_hostname = true
}
Expand Down Expand Up @@ -555,7 +555,7 @@ plugin "raw_exec" {
actual, err := s.processParams("ID", p, 12345)
require.NoError(t, err)

configFilePath := filepath.Join(s.cfg.Get().Paths.TempDir, "agent_type_nomad_agent", "ID", "nomadConfig")
configFilePath := filepath.Join(s.cfg.Get().Paths.TempDir, "nomad_agent", "ID", "nomadConfig")
expected := process.Params{
Path: "/path/to/nomad",
Args: []string{
Expand Down Expand Up @@ -611,7 +611,7 @@ plugin "raw_exec" {
actual, err := s.processParams("vmagent-id", p, 12345)
require.NoError(t, err)

configFilePath := filepath.Join(s.cfg.Get().Paths.TempDir, "agent_type_vm_agent", "vmagent-id", "vmagentscrapecfg")
configFilePath := filepath.Join(s.cfg.Get().Paths.TempDir, "vm_agent", "vmagent-id", "vmagentscrapecfg")
tempDir := s.cfg.Get().Paths.TempDir
expected := process.Params{
Path: "/path/to/vmagent",
Expand Down
2 changes: 1 addition & 1 deletion agent/commands/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ func cleanupTmp(tmpRoot string, log *logrus.Entry) {
continue
}

agentTmp := filepath.Join(tmpRoot, strings.ToLower(agentType.String()))
agentTmp := filepath.Join(tmpRoot, strings.TrimPrefix(strings.ToLower(agentType.String()), "agent_type_"))
err := os.RemoveAll(agentTmp)
if err != nil {
log.Warnf("Failed to cleanup directory '%s': %s", agentTmp, err.Error())
Expand Down
Loading