Skip to content

Commit 8d15e82

Browse files
authored
fix logging (#66)
* fix logging * fix logging for failure * log when tracer is not supported, keep running
1 parent 04daf16 commit 8d15e82

10 files changed

Lines changed: 34 additions & 30 deletions

File tree

Gopkg.lock

Lines changed: 14 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Gopkg.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[[constraint]]
22
name = "github.com/StackVista/stackstate-agent"
3-
revision = "3185a432dfed61437a6c62ed5622006d9027f513"
3+
revision = "bcfb39d79bc7cd7ad5742b6d62837062af8d62a9"
44

55
[[constraint]]
66
name = "github.com/DataDog/gopsutil"

checks/container.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ package checks
44

55
import (
66
"fmt"
7+
"github.com/StackVista/stackstate-agent/pkg/tagger/collectors"
78
"github.com/StackVista/stackstate-process-agent/cmd/agent/features"
89
"runtime"
910
"strings"
@@ -110,7 +111,7 @@ func fmtContainers(
110111
sys2, sys1 := ctr.CPU.SystemUsage, lastCtr.CPU.SystemUsage
111112

112113
// Retrieves metadata tags
113-
tags, err := tagger.Tag(ctr.EntityID, true)
114+
tags, err := tagger.Tag(ctr.EntityID, collectors.HighCardinality)
114115
if err != nil {
115116
log.Errorf("unable to retrieve tags for container: %s", err)
116117
tags = []string{}

checks/net.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ func (c *ConnectionsCheck) RealTime() bool { return false }
5454
func (c *ConnectionsCheck) Run(cfg *config.AgentConfig, features features.Features, groupID int32) ([]model.MessageBody, error) {
5555
// If local tracer failed to initialize, so we shouldn't be doing any checks
5656
if c.useLocalTracer && c.localTracer == nil {
57+
log.Errorf("failed to create network tracer. Set the environment STS_NETWORK_TRACING_ENABLED to false to disable network connections reporting")
5758
return nil, nil
5859
}
5960

checks/net_linux.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ func (c *ConnectionsCheck) Init(cfg *config.AgentConfig, sysInfo *model.SystemIn
2727
if _, err = tracer.IsTracerSupportedByOS(); err != nil {
2828
// err is always returned when false, so the above catches the !ok case as well
2929
log.Errorf("network tracer unsupported by OS: %s. Set the environment STS_NETWORK_TRACING_ENABLED to false to disable network connections reporting", err)
30-
os.Exit(1)
30+
return
3131
}
3232

3333
conf := tracerConfig.DefaultConfig
@@ -42,7 +42,7 @@ func (c *ConnectionsCheck) Init(cfg *config.AgentConfig, sysInfo *model.SystemIn
4242
t, err := tracer.NewTracer(conf)
4343
if err != nil {
4444
log.Errorf("failed to create network tracer: %s. Set the environment STS_NETWORK_TRACING_ENABLED to false to disable network connections reporting", err)
45-
os.Exit(1)
45+
return
4646
}
4747

4848
c.localTracer = t

checks/net_windows.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99
tracerConfig "github.com/StackVista/tcptracer-bpf/pkg/tracer/config"
1010
log "github.com/cihub/seelog"
1111
"github.com/patrickmn/go-cache"
12-
"os"
1312
)
1413

1514
// Init initializes a ConnectionsCheck instance.
@@ -24,7 +23,7 @@ func (c *ConnectionsCheck) Init(cfg *config.AgentConfig, sysInfo *model.SystemIn
2423
if _, err = tracer.IsTracerSupportedByOS(); err != nil {
2524
// err is always returned when false, so the above catches the !ok case as well
2625
log.Errorf("network tracer unsupported by OS: %s. Set the environment STS_NETWORK_TRACING_ENABLED to false to disable network connections reporting", err)
27-
os.Exit(1)
26+
return
2827
}
2928

3029
conf := tracerConfig.DefaultConfig
@@ -33,7 +32,7 @@ func (c *ConnectionsCheck) Init(cfg *config.AgentConfig, sysInfo *model.SystemIn
3332
t, err := tracer.NewTracer(conf)
3433
if err != nil {
3534
log.Errorf("failed to create network tracer: %s. Set the environment STS_NETWORK_TRACING_ENABLED to false to disable network connections reporting", err)
36-
os.Exit(1)
35+
return
3736
}
3837

3938
c.localTracer = t

cmd/agent/main_common.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -113,11 +113,7 @@ func runAgent(exit chan bool) {
113113
}
114114

115115
// Tagger must be initialized after agent config has been setup (via config.SetupDDAgentConfig)
116-
if err := tagger.Init(); err == nil {
117-
defer tagger.Stop()
118-
} else {
119-
log.Errorf("unable to initialize StackState entity tagger: %s", err)
120-
}
116+
tagger.Init()
121117

122118
networkConf, err := config.NewYamlIfExists(opts.netConfigPath)
123119
if err != nil {

conf-dev.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
log_level: TRACE
1+
log_level: INFO
22
log_to_console: true
33
# Use this when running process agent locally
4-
#sts_url: http://localhost:7077/stsAgent
4+
sts_url: http://localhost:7077/stsAgent
55

66
# Use this when running process agent in the vagrant vms
7-
sts_url: http://192.168.56.1:7077/stsAgent
7+
#sts_url: http://192.168.56.1:7077/stsAgent
88

99
# Use this when running process agent with branch deploy
1010
#sts_url: https://<branch-name>.test.stackstate.io/stsAgent

config/config.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -454,18 +454,21 @@ func NewAgentConfig(agentIni *File, agentYaml *YamlAgentConfig, networkYaml *Yam
454454
// sanity check. This element is used with the modulo operator (%), so it can't be zero.
455455
// if it is, log the error, and assume the config was attempting to disable
456456
if cfg.Windows.ArgsRefreshInterval == 0 {
457-
log.Warnf("invalid configuration: windows_collect_skip_new_args was set to 0. Disabling argument collection")
457+
log.Warnf("invalid configuration: windows_collect_skip_new_args was set to 0. " +
458+
"Disabling argument collection")
458459
cfg.Windows.ArgsRefreshInterval = -1
459460
}
460461

461462
if cfg.EnableShortLivedProcessFilter {
462-
log.Infof("Process ShortLived filter enabled for processes younger than %s", cfg.ShortLivedProcessQualifierSecs)
463+
log.Infof("Process ShortLived filter enabled for processes younger than %s",
464+
cfg.ShortLivedProcessQualifierSecs)
463465
} else {
464466
log.Info("Process ShortLived filter disabled")
465467
}
466468

467469
if cfg.EnableShortLivedNetworkRelationFilter {
468-
log.Infof("Relation ShortLived filter enabled for connections that are once off and were observed for less than %d seconds", cfg.ShortLivedNetworkRelationQualifierSecs)
470+
log.Infof("Relation ShortLived filter enabled for connections that are once off and were observed for "+
471+
"less than %s seconds", cfg.ShortLivedNetworkRelationQualifierSecs)
469472
} else {
470473
log.Infof("Relation ShortLived filter disabled")
471474
}

config/yaml_config.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ import (
1818
// YamlAgentConfig is a structure used for marshaling the datadog.yaml configuration
1919
// available in Agent versions >= 6
2020
type YamlAgentConfig struct {
21-
APIKey string `yaml:"api_key"`
22-
Site string `yaml:"site"`
21+
APIKey string `yaml:"api_key"`
22+
Site string `yaml:"site"`
2323
StsURL string `yaml:"sts_url"`
2424
// Whether or not the process-agent should output logs to console
2525
LogToConsole bool `yaml:"log_to_console"`

0 commit comments

Comments
 (0)