From fd292ffcc71822303212b4b32b972a1a80bf5acf Mon Sep 17 00:00:00 2001 From: zandrewitte Date: Wed, 10 Feb 2021 11:01:47 +0100 Subject: [PATCH 1/3] fix logging --- config/config.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/config/config.go b/config/config.go index 1f342b688..a4300c6fc 100644 --- a/config/config.go +++ b/config/config.go @@ -454,18 +454,21 @@ func NewAgentConfig(agentIni *File, agentYaml *YamlAgentConfig, networkYaml *Yam // sanity check. This element is used with the modulo operator (%), so it can't be zero. // if it is, log the error, and assume the config was attempting to disable if cfg.Windows.ArgsRefreshInterval == 0 { - log.Warnf("invalid configuration: windows_collect_skip_new_args was set to 0. Disabling argument collection") + log.Warnf("invalid configuration: windows_collect_skip_new_args was set to 0. " + + "Disabling argument collection") cfg.Windows.ArgsRefreshInterval = -1 } if cfg.EnableShortLivedProcessFilter { - log.Infof("Process ShortLived filter enabled for processes younger than %s", cfg.ShortLivedProcessQualifierSecs) + log.Infof("Process ShortLived filter enabled for processes younger than %s", + cfg.ShortLivedProcessQualifierSecs) } else { log.Info("Process ShortLived filter disabled") } if cfg.EnableShortLivedNetworkRelationFilter { - log.Infof("Relation ShortLived filter enabled for connections that are once off and were observed for less than %d seconds", cfg.ShortLivedNetworkRelationQualifierSecs) + log.Infof("Relation ShortLived filter enabled for connections that are once off and were observed for " + + "less than %s seconds", cfg.ShortLivedNetworkRelationQualifierSecs) } else { log.Infof("Relation ShortLived filter disabled") } From 45dd09fca4a54e9e674551e21a61bae84d7ec110 Mon Sep 17 00:00:00 2001 From: zandrewitte Date: Thu, 25 Feb 2021 14:56:58 +0100 Subject: [PATCH 2/3] fix logging for failure --- Gopkg.lock | 24 ++++++++++++++---------- Gopkg.toml | 2 +- checks/container.go | 3 ++- checks/net_linux.go | 4 ++-- checks/net_windows.go | 5 ++--- cmd/agent/main_common.go | 6 +----- conf-dev.yaml | 6 +++--- 7 files changed, 25 insertions(+), 25 deletions(-) diff --git a/Gopkg.lock b/Gopkg.lock index b2b37d10f..0cafde28a 100644 --- a/Gopkg.lock +++ b/Gopkg.lock @@ -31,6 +31,14 @@ pruneopts = "" revision = "771928d86fa878b9d62f073a7a6f91ee0a358105" +[[projects]] + digest = "1:e9ca79fa28ff0fe0271b63d2d30f4118643746610cd0d75603c7b4255a44f161" + name = "github.com/DataDog/viper" + packages = ["."] + pruneopts = "" + revision = "23ced3bc6b3751855704445e48da2c53075ade86" + version = "v1.4.0" + [[projects]] digest = "1:874c0d49e5c272ae160b7c26d2ad2a1e21b54565fc3a84efb8014a0afcf4e63f" name = "github.com/DataDog/zstd" @@ -55,7 +63,7 @@ version = "1.0.0" [[projects]] - digest = "1:4eb5a7d274cc64b02f46f232e4ba0ac777ffde9d84e9fc08726e3cbf44f7d653" + digest = "1:1894a9ff4e26f0a89e56540d50ed15e8e622efb2cef17b6121c09d932c7d6839" name = "github.com/StackVista/stackstate-agent" packages = [ "cmd/agent/api/response", @@ -77,6 +85,7 @@ "pkg/util", "pkg/util/cache", "pkg/util/clusteragent", + "pkg/util/common", "pkg/util/containers", "pkg/util/containers/collectors", "pkg/util/containers/metrics", @@ -93,10 +102,12 @@ "pkg/util/kubernetes/kubelet", "pkg/util/log", "pkg/util/retry", + "pkg/util/tmplvar", + "pkg/util/winutil", "pkg/version", ] pruneopts = "" - revision = "3185a432dfed61437a6c62ed5622006d9027f513" + revision = "bcfb39d79bc7cd7ad5742b6d62837062af8d62a9" [[projects]] digest = "1:8ec2e6106f7fe0214a16033f2df75760f348e103cf4588217d30e5742d5aaa69" @@ -662,14 +673,6 @@ revision = "298182f68c66c05229eb03ac171abe6e309ee79a" version = "v1.0.3" -[[projects]] - digest = "1:3dab237cd3263a290d771d133fed777bb56c22e380b00ebe92e6531d5c8d3d0c" - name = "github.com/spf13/viper" - packages = ["."] - pruneopts = "" - revision = "b5e8006cbee93ec955a89ab31e0e3ce3204f3736" - version = "v1.0.2" - [[projects]] digest = "1:c587772fb8ad29ad4db67575dad25ba17a51f072ff18a22b4f0257a4d9c24f75" name = "github.com/stretchr/testify" @@ -1124,6 +1127,7 @@ "github.com/StackVista/stackstate-agent/pkg/config", "github.com/StackVista/stackstate-agent/pkg/pidfile", "github.com/StackVista/stackstate-agent/pkg/tagger", + "github.com/StackVista/stackstate-agent/pkg/tagger/collectors", "github.com/StackVista/stackstate-agent/pkg/util", "github.com/StackVista/stackstate-agent/pkg/util/cache", "github.com/StackVista/stackstate-agent/pkg/util/containers", diff --git a/Gopkg.toml b/Gopkg.toml index 9ce5714f4..7f2777c63 100644 --- a/Gopkg.toml +++ b/Gopkg.toml @@ -1,6 +1,6 @@ [[constraint]] name = "github.com/StackVista/stackstate-agent" - revision = "3185a432dfed61437a6c62ed5622006d9027f513" + revision = "bcfb39d79bc7cd7ad5742b6d62837062af8d62a9" [[constraint]] name = "github.com/DataDog/gopsutil" diff --git a/checks/container.go b/checks/container.go index 9b3259230..b1977581e 100644 --- a/checks/container.go +++ b/checks/container.go @@ -4,6 +4,7 @@ package checks import ( "fmt" + "github.com/StackVista/stackstate-agent/pkg/tagger/collectors" "github.com/StackVista/stackstate-process-agent/cmd/agent/features" "runtime" "strings" @@ -110,7 +111,7 @@ func fmtContainers( sys2, sys1 := ctr.CPU.SystemUsage, lastCtr.CPU.SystemUsage // Retrieves metadata tags - tags, err := tagger.Tag(ctr.EntityID, true) + tags, err := tagger.Tag(ctr.EntityID, collectors.HighCardinality) if err != nil { log.Errorf("unable to retrieve tags for container: %s", err) tags = []string{} diff --git a/checks/net_linux.go b/checks/net_linux.go index 5c7164e1b..b536f3f9d 100644 --- a/checks/net_linux.go +++ b/checks/net_linux.go @@ -27,7 +27,7 @@ func (c *ConnectionsCheck) Init(cfg *config.AgentConfig, sysInfo *model.SystemIn if _, err = tracer.IsTracerSupportedByOS(); err != nil { // err is always returned when false, so the above catches the !ok case as well log.Errorf("network tracer unsupported by OS: %s. Set the environment STS_NETWORK_TRACING_ENABLED to false to disable network connections reporting", err) - os.Exit(1) + return } conf := tracerConfig.DefaultConfig @@ -42,7 +42,7 @@ func (c *ConnectionsCheck) Init(cfg *config.AgentConfig, sysInfo *model.SystemIn t, err := tracer.NewTracer(conf) if err != nil { log.Errorf("failed to create network tracer: %s. Set the environment STS_NETWORK_TRACING_ENABLED to false to disable network connections reporting", err) - os.Exit(1) + return } c.localTracer = t diff --git a/checks/net_windows.go b/checks/net_windows.go index 3842da4bf..7493d05c6 100644 --- a/checks/net_windows.go +++ b/checks/net_windows.go @@ -9,7 +9,6 @@ import ( tracerConfig "github.com/StackVista/tcptracer-bpf/pkg/tracer/config" log "github.com/cihub/seelog" "github.com/patrickmn/go-cache" - "os" ) // Init initializes a ConnectionsCheck instance. @@ -24,7 +23,7 @@ func (c *ConnectionsCheck) Init(cfg *config.AgentConfig, sysInfo *model.SystemIn if _, err = tracer.IsTracerSupportedByOS(); err != nil { // err is always returned when false, so the above catches the !ok case as well log.Errorf("network tracer unsupported by OS: %s. Set the environment STS_NETWORK_TRACING_ENABLED to false to disable network connections reporting", err) - os.Exit(1) + return } conf := tracerConfig.DefaultConfig @@ -33,7 +32,7 @@ func (c *ConnectionsCheck) Init(cfg *config.AgentConfig, sysInfo *model.SystemIn t, err := tracer.NewTracer(conf) if err != nil { log.Errorf("failed to create network tracer: %s. Set the environment STS_NETWORK_TRACING_ENABLED to false to disable network connections reporting", err) - os.Exit(1) + return } c.localTracer = t diff --git a/cmd/agent/main_common.go b/cmd/agent/main_common.go index f84256af1..44ab8b89c 100644 --- a/cmd/agent/main_common.go +++ b/cmd/agent/main_common.go @@ -113,11 +113,7 @@ func runAgent(exit chan bool) { } // Tagger must be initialized after agent config has been setup (via config.SetupDDAgentConfig) - if err := tagger.Init(); err == nil { - defer tagger.Stop() - } else { - log.Errorf("unable to initialize StackState entity tagger: %s", err) - } + tagger.Init() networkConf, err := config.NewYamlIfExists(opts.netConfigPath) if err != nil { diff --git a/conf-dev.yaml b/conf-dev.yaml index 6da3f91e4..05a6870a0 100644 --- a/conf-dev.yaml +++ b/conf-dev.yaml @@ -1,10 +1,10 @@ -log_level: TRACE +log_level: INFO log_to_console: true # Use this when running process agent locally -#sts_url: http://localhost:7077/stsAgent +sts_url: http://localhost:7077/stsAgent # Use this when running process agent in the vagrant vms -sts_url: http://192.168.56.1:7077/stsAgent +#sts_url: http://192.168.56.1:7077/stsAgent # Use this when running process agent with branch deploy #sts_url: https://.test.stackstate.io/stsAgent From 55e9a58ffc0d4d082143a20489db5402017b1872 Mon Sep 17 00:00:00 2001 From: zandrewitte Date: Thu, 25 Feb 2021 14:58:26 +0100 Subject: [PATCH 3/3] log when tracer is not supported, keep running --- checks/net.go | 1 + config/config.go | 2 +- config/yaml_config.go | 4 ++-- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/checks/net.go b/checks/net.go index 159ccbbc8..5124d362f 100644 --- a/checks/net.go +++ b/checks/net.go @@ -54,6 +54,7 @@ func (c *ConnectionsCheck) RealTime() bool { return false } func (c *ConnectionsCheck) Run(cfg *config.AgentConfig, features features.Features, groupID int32) ([]model.MessageBody, error) { // If local tracer failed to initialize, so we shouldn't be doing any checks if c.useLocalTracer && c.localTracer == nil { + log.Errorf("failed to create network tracer. Set the environment STS_NETWORK_TRACING_ENABLED to false to disable network connections reporting") return nil, nil } diff --git a/config/config.go b/config/config.go index a4300c6fc..db99b31e9 100644 --- a/config/config.go +++ b/config/config.go @@ -467,7 +467,7 @@ func NewAgentConfig(agentIni *File, agentYaml *YamlAgentConfig, networkYaml *Yam } if cfg.EnableShortLivedNetworkRelationFilter { - log.Infof("Relation ShortLived filter enabled for connections that are once off and were observed for " + + log.Infof("Relation ShortLived filter enabled for connections that are once off and were observed for "+ "less than %s seconds", cfg.ShortLivedNetworkRelationQualifierSecs) } else { log.Infof("Relation ShortLived filter disabled") diff --git a/config/yaml_config.go b/config/yaml_config.go index a564aff00..283c5a430 100644 --- a/config/yaml_config.go +++ b/config/yaml_config.go @@ -18,8 +18,8 @@ import ( // YamlAgentConfig is a structure used for marshaling the datadog.yaml configuration // available in Agent versions >= 6 type YamlAgentConfig struct { - APIKey string `yaml:"api_key"` - Site string `yaml:"site"` + APIKey string `yaml:"api_key"` + Site string `yaml:"site"` StsURL string `yaml:"sts_url"` // Whether or not the process-agent should output logs to console LogToConsole bool `yaml:"log_to_console"`