From dffefc54cb9ae1b5fb9a00b47b239d893cc0fc4f Mon Sep 17 00:00:00 2001 From: Michal Pristas Date: Fri, 24 Apr 2020 09:48:51 +0200 Subject: [PATCH 1/7] log paths within data --- .../pkg/agent/application/global_config.go | 34 ++----------------- .../plugin/app/monitoring/beats/monitoring.go | 14 ++++---- 2 files changed, 11 insertions(+), 37 deletions(-) diff --git a/x-pack/elastic-agent/pkg/agent/application/global_config.go b/x-pack/elastic-agent/pkg/agent/application/global_config.go index 44e9f2772ff2..d810b483e734 100644 --- a/x-pack/elastic-agent/pkg/agent/application/global_config.go +++ b/x-pack/elastic-agent/pkg/agent/application/global_config.go @@ -5,23 +5,11 @@ package application import ( - "os" - "path/filepath" - + "github.com/elastic/beats/v7/x-pack/elastic-agent/pkg/agent/application/paths" "github.com/elastic/beats/v7/x-pack/elastic-agent/pkg/agent/errors" "github.com/elastic/beats/v7/x-pack/elastic-agent/pkg/config" ) -var ( - homePath string - dataPath string -) - -func init() { - homePath = retrieveExecutablePath() - dataPath = retrieveDataPath() -} - // InjectAgentConfig injects config to a provided configuration. func InjectAgentConfig(c *config.Config) error { globalConfig := AgentGlobalConfig() @@ -37,24 +25,8 @@ func InjectAgentConfig(c *config.Config) error { func AgentGlobalConfig() map[string]interface{} { return map[string]interface{}{ "path": map[string]interface{}{ - "data": dataPath, - "home": homePath, + "data": paths.Data(), + "home": paths.Home(), }, } } - -// retrieveExecutablePath returns a directory where binary lives -// Executable is not supported on nacl. -func retrieveExecutablePath() string { - execPath, err := os.Executable() - if err != nil { - panic(err) - } - - return filepath.Dir(execPath) -} - -// retrieveHomePath returns a home directory of current user -func retrieveDataPath() string { - return filepath.Join(retrieveExecutablePath(), "data") -} diff --git a/x-pack/elastic-agent/pkg/core/plugin/app/monitoring/beats/monitoring.go b/x-pack/elastic-agent/pkg/core/plugin/app/monitoring/beats/monitoring.go index c551f5ef18cf..22e089ebea1d 100644 --- a/x-pack/elastic-agent/pkg/core/plugin/app/monitoring/beats/monitoring.go +++ b/x-pack/elastic-agent/pkg/core/plugin/app/monitoring/beats/monitoring.go @@ -6,13 +6,15 @@ package beats import ( "fmt" + + "github.com/elastic/beats/v7/x-pack/elastic-agent/pkg/agent/application/paths" ) const ( - // args: pipeline name, application name - logFileFormat = "/var/log/elastic-agent/%s/%s" - // args: install path, pipeline name, application name - logFileFormatWin = "%s\\logs\\elastic-agent\\%s\\%s" + // args: data path, pipeline name, application name + logFileFormat = "%s/logs/%s/%s" + // args: data path, install path, pipeline name, application name + logFileFormatWin = "%s\\logs\\%s\\%s" // args: pipeline name, application name mbEndpointFileFormat = "unix:///var/run/elastic-agent/%s/%s/%s.sock" @@ -30,8 +32,8 @@ func getMonitoringEndpoint(program, operatingSystem, pipelineID string) string { func getLoggingFile(program, operatingSystem, installPath, pipelineID string) string { if operatingSystem == "windows" { - return fmt.Sprintf(logFileFormatWin, installPath, pipelineID, program) + return fmt.Sprintf(logFileFormatWin, paths.Data(), pipelineID, program) } - return fmt.Sprintf(logFileFormat, pipelineID, program) + return fmt.Sprintf(logFileFormat, paths.Data(), pipelineID, program) } From 9cc4df0d13736bb9f4c903a185c239b78a61701b Mon Sep 17 00:00:00 2001 From: Michal Pristas Date: Fri, 24 Apr 2020 09:58:55 +0200 Subject: [PATCH 2/7] changelog --- x-pack/elastic-agent/CHANGELOG.asciidoc | 1 + 1 file changed, 1 insertion(+) diff --git a/x-pack/elastic-agent/CHANGELOG.asciidoc b/x-pack/elastic-agent/CHANGELOG.asciidoc index 1271df446467..e46bb23e6755 100644 --- a/x-pack/elastic-agent/CHANGELOG.asciidoc +++ b/x-pack/elastic-agent/CHANGELOG.asciidoc @@ -38,3 +38,4 @@ - Monitoring configuration reloadable {pull}17855[17855] - Pack ECS metadata to request payload send to fleet {pull}17894[17894] - Enable Filebeat input: S3, Azureeventhub, cloudfoundry, httpjson, netflow, o365audit. {pull}17909[17909] +- Use data subfolder as default for process logs {pull}17960[17960] From 55a5da9ffa60247584d424283a8970f0240fce7e Mon Sep 17 00:00:00 2001 From: Michal Pristas Date: Fri, 24 Apr 2020 10:39:09 +0200 Subject: [PATCH 3/7] removed file --- .../pkg/agent/application/paths/paths.go | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 x-pack/elastic-agent/pkg/agent/application/paths/paths.go diff --git a/x-pack/elastic-agent/pkg/agent/application/paths/paths.go b/x-pack/elastic-agent/pkg/agent/application/paths/paths.go new file mode 100644 index 000000000000..6d59952fefa6 --- /dev/null +++ b/x-pack/elastic-agent/pkg/agent/application/paths/paths.go @@ -0,0 +1,41 @@ +// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one +// or more contributor license agreements. Licensed under the Elastic License; +// you may not use this file except in compliance with the Elastic License. + +package paths + +import ( + "os" + "path/filepath" +) + +var ( + homePath string + dataPath string +) + +func init() { + exePath := retrieveExecutablePath() + homePath = exePath + dataPath = filepath.Join(exePath, "data") +} + +// Home returns a directory where binary lives +// Executable is not supported on nacl. +func Home() string { + return homePath +} + +// Data returns a home directory of current user +func Data() string { + return dataPath +} + +func retrieveExecutablePath() string { + execPath, err := os.Executable() + if err != nil { + panic(err) + } + + return filepath.Dir(execPath) +} From ce8b9a6ea726f347b25b68d1571a1dbb5ac1e0a9 Mon Sep 17 00:00:00 2001 From: Michal Pristas Date: Tue, 28 Apr 2020 09:56:13 +0200 Subject: [PATCH 4/7] switched path --- .../pkg/core/plugin/app/monitoring/beats/monitoring.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/x-pack/elastic-agent/pkg/core/plugin/app/monitoring/beats/monitoring.go b/x-pack/elastic-agent/pkg/core/plugin/app/monitoring/beats/monitoring.go index 22e089ebea1d..6049c9995b93 100644 --- a/x-pack/elastic-agent/pkg/core/plugin/app/monitoring/beats/monitoring.go +++ b/x-pack/elastic-agent/pkg/core/plugin/app/monitoring/beats/monitoring.go @@ -12,9 +12,9 @@ import ( const ( // args: data path, pipeline name, application name - logFileFormat = "%s/logs/%s/%s" + logFileFormat = "%s/%s/logs/%s" // args: data path, install path, pipeline name, application name - logFileFormatWin = "%s\\logs\\%s\\%s" + logFileFormatWin = "%s\\%s\\logs\\%s" // args: pipeline name, application name mbEndpointFileFormat = "unix:///var/run/elastic-agent/%s/%s/%s.sock" From c36e06b2da82d8b84274b6b3fd33a290701961bb Mon Sep 17 00:00:00 2001 From: Michal Pristas Date: Tue, 28 Apr 2020 09:57:36 +0200 Subject: [PATCH 5/7] unnecessary type specifier --- .../plugin/app/monitoring/beats/drop_test.go | 32 +++++++++---------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/x-pack/elastic-agent/pkg/core/plugin/app/monitoring/beats/drop_test.go b/x-pack/elastic-agent/pkg/core/plugin/app/monitoring/beats/drop_test.go index a4d06169ca85..5c2f6be7f19e 100644 --- a/x-pack/elastic-agent/pkg/core/plugin/app/monitoring/beats/drop_test.go +++ b/x-pack/elastic-agent/pkg/core/plugin/app/monitoring/beats/drop_test.go @@ -15,22 +15,22 @@ type testCase struct { func TestMonitoringDrops(t *testing.T) { cases := []testCase{ - testCase{`/var/lib/drop/abc.sock`, "/var/lib/drop"}, - testCase{`npipe://drop`, ""}, - testCase{`http+npipe://drop`, ""}, - testCase{`\\.\pipe\drop`, ""}, - testCase{`unix:///var/lib/drop/abc.sock`, "/var/lib/drop"}, - testCase{`http+unix:///var/lib/drop/abc.sock`, "/var/lib/drop"}, - testCase{`file:///var/lib/drop/abc.sock`, "/var/lib/drop"}, - testCase{`http://localhost/stats`, ""}, - testCase{`localhost/stats`, ""}, - testCase{`http://localhost:8080/stats`, ""}, - testCase{`localhost:8080/stats`, ""}, - testCase{`http://1.2.3.4/stats`, ""}, - testCase{`http://1.2.3.4:5678/stats`, ""}, - testCase{`1.2.3.4:5678/stats`, ""}, - testCase{`http://hithere.com:5678/stats`, ""}, - testCase{`hithere.com:5678/stats`, ""}, + {`/var/lib/drop/abc.sock`, "/var/lib/drop"}, + {`npipe://drop`, ""}, + {`http+npipe://drop`, ""}, + {`\\.\pipe\drop`, ""}, + {`unix:///var/lib/drop/abc.sock`, "/var/lib/drop"}, + {`http+unix:///var/lib/drop/abc.sock`, "/var/lib/drop"}, + {`file:///var/lib/drop/abc.sock`, "/var/lib/drop"}, + {`http://localhost/stats`, ""}, + {`localhost/stats`, ""}, + {`http://localhost:8080/stats`, ""}, + {`localhost:8080/stats`, ""}, + {`http://1.2.3.4/stats`, ""}, + {`http://1.2.3.4:5678/stats`, ""}, + {`1.2.3.4:5678/stats`, ""}, + {`http://hithere.com:5678/stats`, ""}, + {`hithere.com:5678/stats`, ""}, } for _, c := range cases { From 40c9418033792710e3a5cdd695a0e0ef340eeaa4 Mon Sep 17 00:00:00 2001 From: Michal Pristas Date: Tue, 28 Apr 2020 20:02:21 +0200 Subject: [PATCH 6/7] logs-output --- .../pkg/core/plugin/app/monitoring/beats/monitoring.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/x-pack/elastic-agent/pkg/core/plugin/app/monitoring/beats/monitoring.go b/x-pack/elastic-agent/pkg/core/plugin/app/monitoring/beats/monitoring.go index 6049c9995b93..22e089ebea1d 100644 --- a/x-pack/elastic-agent/pkg/core/plugin/app/monitoring/beats/monitoring.go +++ b/x-pack/elastic-agent/pkg/core/plugin/app/monitoring/beats/monitoring.go @@ -12,9 +12,9 @@ import ( const ( // args: data path, pipeline name, application name - logFileFormat = "%s/%s/logs/%s" + logFileFormat = "%s/logs/%s/%s" // args: data path, install path, pipeline name, application name - logFileFormatWin = "%s\\%s\\logs\\%s" + logFileFormatWin = "%s\\logs\\%s\\%s" // args: pipeline name, application name mbEndpointFileFormat = "unix:///var/run/elastic-agent/%s/%s/%s.sock" From 83cec32fef9df20fb489fdcac826506252ea267f Mon Sep 17 00:00:00 2001 From: Michal Pristas Date: Wed, 29 Apr 2020 16:17:26 +0200 Subject: [PATCH 7/7] var run to data path --- .../pkg/core/plugin/app/monitoring/beats/monitoring.go | 4 ++-- x-pack/elastic-agent/pkg/core/plugin/app/start.go | 8 ++------ 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/x-pack/elastic-agent/pkg/core/plugin/app/monitoring/beats/monitoring.go b/x-pack/elastic-agent/pkg/core/plugin/app/monitoring/beats/monitoring.go index 22e089ebea1d..7e6b820611c2 100644 --- a/x-pack/elastic-agent/pkg/core/plugin/app/monitoring/beats/monitoring.go +++ b/x-pack/elastic-agent/pkg/core/plugin/app/monitoring/beats/monitoring.go @@ -17,7 +17,7 @@ const ( logFileFormatWin = "%s\\logs\\%s\\%s" // args: pipeline name, application name - mbEndpointFileFormat = "unix:///var/run/elastic-agent/%s/%s/%s.sock" + mbEndpointFileFormat = "unix://%s/run/%s/%s/%s.sock" // args: pipeline name, application name mbEndpointFileFormatWin = `npipe:///%s-%s` ) @@ -27,7 +27,7 @@ func getMonitoringEndpoint(program, operatingSystem, pipelineID string) string { return fmt.Sprintf(mbEndpointFileFormatWin, pipelineID, program) } - return fmt.Sprintf(mbEndpointFileFormat, pipelineID, program, program) + return fmt.Sprintf(mbEndpointFileFormat, paths.Data(), pipelineID, program, program) } func getLoggingFile(program, operatingSystem, installPath, pipelineID string) string { diff --git a/x-pack/elastic-agent/pkg/core/plugin/app/start.go b/x-pack/elastic-agent/pkg/core/plugin/app/start.go index 00684753a0d3..9bfc40781e22 100644 --- a/x-pack/elastic-agent/pkg/core/plugin/app/start.go +++ b/x-pack/elastic-agent/pkg/core/plugin/app/start.go @@ -15,6 +15,7 @@ import ( "gopkg.in/yaml.v2" + "github.com/elastic/beats/v7/x-pack/elastic-agent/pkg/agent/application/paths" "github.com/elastic/beats/v7/x-pack/elastic-agent/pkg/agent/errors" "github.com/elastic/beats/v7/x-pack/elastic-agent/pkg/core/plugin/authority" "github.com/elastic/beats/v7/x-pack/elastic-agent/pkg/core/plugin/process" @@ -210,12 +211,7 @@ func (a *Application) checkGrpcHTTP(ctx context.Context, address string, ca *aut } func injectDataPath(args []string, pipelineID, id string) []string { - wd := "" - if w, err := os.Getwd(); err == nil { - wd = w - } - - dataPath := filepath.Join(wd, "data", pipelineID, id) + dataPath := filepath.Join(paths.Data(), pipelineID, id) return append(args, "-E", "path.data="+dataPath) }