Skip to content

Commit c055030

Browse files
authored
Merge pull request #215 from StackVista/STAC-23272
[STAC-23272] cleanup: remove no more used configs
2 parents 8343e70 + 09a443c commit c055030

11 files changed

Lines changed: 7 additions & 358 deletions

File tree

DockerFiles/agent/stackstate-docker.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
log_level: debug
22

33

4-
process_agent_enabled: true
54
incremental_publishing_enabled: true
65
process_config:
76
enabled: 'true'

build.sh

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@ docker run \\
1919
--privileged \\
2020
-e STS_API_KEY=none \\
2121
-e STS_PROCESS_AGENT_URL=none \\
22-
-e STS_CLUSTER_AGENT_ENABLED=true \\
23-
-e STS_LOG_TO_CONSOLE=true \\
2422
-v /sys/kernel/debug:/sys/kernel/debug \\
2523
-e HOST_ETC=/host/etc \\
2624
-e HOST_SYS=/host/sys \\
@@ -30,8 +28,6 @@ docker run \\
3028
-v /etc:/host/etc \\
3129
-e STS_NETWORK_TRACING_ENABLED=true \\
3230
-e STS_PROTOCOL_INSPECTION_ENABLED=true \\
33-
-e STS_PROCESS_AGENT_ENABLED=true \\
3431
europe-west4-docker.pkg.dev/stackstate-sandbox-390311/dev/stackstate-process-agent:dev
3532
3633
EOF
37-

cmd/agent/main.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ func main() {
1515
flag.StringVar(&opts.pidfilePath, "pid", "", "Path to set pidfile for process")
1616
flag.BoolVar(&opts.info, "info", false, "Show info about running process agent and exit")
1717
flag.BoolVar(&opts.version, "version", false, "Print the version and exit")
18-
flag.StringVar(&opts.check, "check", "", "Run a specific check and print the results. Choose from: process, connections, realtime")
1918
flag.Parse()
2019

2120
// Set up a default config before parsing config so we log errors nicely.

cmd/agent/main_common.go

Lines changed: 1 addition & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"bytes"
55
"compress/gzip"
66
"context"
7-
"encoding/json"
87
"fmt"
98
"net/http"
109
_ "net/http/pprof"
@@ -18,7 +17,6 @@ import (
1817
"github.com/DataDog/datadog-agent/pkg/pidfile"
1918
"github.com/DataDog/datadog-agent/pkg/process/util"
2019
containers "github.com/DataDog/datadog-agent/pkg/process/util/containers"
21-
"github.com/StackVista/stackstate-process-agent/checks"
2220
"github.com/StackVista/stackstate-process-agent/config"
2321
"github.com/StackVista/stackstate-process-agent/pkg/debug"
2422
"github.com/StackVista/stackstate-receiver-go-client/pkg/httpclient"
@@ -34,7 +32,6 @@ var opts struct {
3432
pidfilePath string
3533
debug bool
3634
version bool
37-
check string
3835
info bool
3936
}
4037

@@ -70,22 +67,13 @@ func versionString() string {
7067
return buf.String()
7168
}
7269

73-
const (
74-
agent6DisabledMessage = `process-agent not enabled.
75-
Set env var STS_PROCESS_AGENT_ENABLED=true or add
76-
process_config:
77-
enabled: "true"
78-
to your stackstate.yaml file.
79-
Exiting.`
80-
)
81-
8270
func runAgent(exit chan bool) {
8371
if opts.version {
8472
fmt.Println(versionString())
8573
os.Exit(0)
8674
}
8775

88-
if opts.check == "" && !opts.info && opts.pidfilePath != "" {
76+
if !opts.info && opts.pidfilePath != "" {
8977
err := pidfile.WritePID(opts.pidfilePath)
9078
if err != nil {
9179
log.Errorf("Error while writing PID file, exiting: %v", err)
@@ -143,19 +131,6 @@ func runAgent(exit chan bool) {
143131
batcher := transactionbatcher.NewTransactionalBatcher(
144132
cfg.HostName, cfg.BatcherMaxBufferSize, fwd, manager, cfg.BatcherLogPayloads)
145133

146-
// Exit if agent is not enabled and we're not debugging a check.
147-
if !cfg.Enabled && opts.check == "" {
148-
if yamlConf != nil {
149-
log.Infof(agent6DisabledMessage)
150-
}
151-
152-
// a sleep is necessary to ensure that supervisor registers this process as "STARTED"
153-
// If the exit is "too quick", we enter a BACKOFF->FATAL loop even though this is an expected exit
154-
// http://supervisord.org/subprocess.html#process-states
155-
time.Sleep(5 * time.Second)
156-
return
157-
}
158-
159134
// update docker socket path in info
160135
dockerSock, err := util.GetDockerSocketPath()
161136
if err != nil {
@@ -166,15 +141,6 @@ func runAgent(exit chan bool) {
166141
updateDockerSocket(dockerSock)
167142

168143
log.Debug("Running process-agent with DEBUG logging enabled")
169-
if opts.check != "" {
170-
err := debugCheckResults(cfg, opts.check)
171-
if err != nil {
172-
fmt.Println(err)
173-
os.Exit(1)
174-
}
175-
176-
os.Exit(0)
177-
}
178144

179145
if opts.info {
180146
// using the debug port to get info to work
@@ -245,66 +211,3 @@ func makeClientHost(cfg *config.AgentConfig) *httpclient.ClientHost {
245211

246212
return host
247213
}
248-
249-
func debugCheckResults(cfg *config.AgentConfig, check string) error {
250-
sysInfo, err := checks.CollectSystemInfo()
251-
if err != nil {
252-
return err
253-
}
254-
255-
if check == checks.Connections.Name() {
256-
// Connections check requires process-check to have occurred first (for process creation ts)
257-
checks.Process.Init(cfg, sysInfo)
258-
checks.Process.Run(cfg, 0, time.Now())
259-
}
260-
261-
names := make([]string, 0, len(checks.All))
262-
for _, ch := range checks.All {
263-
if ch.Name() == check {
264-
err = ch.Init(cfg, sysInfo)
265-
if err != nil {
266-
return fmt.Errorf("error initializing check %s: %w", ch.Name(), err)
267-
}
268-
return printResults(cfg, ch)
269-
}
270-
names = append(names, ch.Name())
271-
}
272-
return fmt.Errorf("invalid check '%s', choose from: %v", check, names)
273-
}
274-
275-
func printResults(cfg *config.AgentConfig, ch checks.Check) error {
276-
// Run the check once to prime the cache.
277-
if _, err := ch.Run(cfg, 0, time.Now()); err != nil {
278-
return fmt.Errorf("collection error: %s", err)
279-
}
280-
281-
if ch.Name() == checks.Connections.Name() {
282-
fmt.Printf("Waiting 5 seconds to allow for active connections to transmit data\n")
283-
time.Sleep(5 * time.Second)
284-
}
285-
286-
fmt.Printf("-----------------------------\n\n")
287-
fmt.Printf("\nResults for check %v\n", ch)
288-
fmt.Printf("-----------------------------\n\n")
289-
290-
result, err := ch.Run(cfg, 1, time.Now())
291-
if err != nil {
292-
return fmt.Errorf("collection error: %s", err)
293-
}
294-
295-
for _, m := range result.CollectorMessages {
296-
b, err := json.MarshalIndent(m, "", " ")
297-
if err != nil {
298-
return fmt.Errorf("marshal error: %s", err)
299-
}
300-
fmt.Println(string(b))
301-
}
302-
for _, m := range result.Metrics {
303-
b, err := json.MarshalIndent(m, "", " ")
304-
if err != nil {
305-
return fmt.Errorf("marshal error: %s", err)
306-
}
307-
fmt.Println(string(b))
308-
}
309-
return nil
310-
}

conf-dev.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ sts_url: http://localhost:7077/stsAgent
1313
# Use this when running process agent with branch deploy
1414
#sts_url: https://<branch-name>.test.stackstate.io/stsAgent
1515
api_key: API_KEY
16-
process_agent_enabled: true
1716
incremental_publishing_enabled: true
1817
local_run: true
1918
process_config:

config/config.go

Lines changed: 2 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,12 @@ type APIEndpoint struct {
6060
// AgentConfig is the global config for the process-agent. This information
6161
// is sourced from config files and the environment variables.
6262
type AgentConfig struct {
63-
Enabled bool
6463
HostName string
6564
APIEndpoints []APIEndpoint
6665
SkipSSLValidation bool
6766
SkipKubeletTLSVerify bool
6867
LogFile string
6968
LogLevel string
70-
LogToConsole bool
7169
QueueSize int
7270
Blacklist []*regexp.Regexp
7371
Scrubber *DataScrubber
@@ -183,13 +181,11 @@ func NewDefaultAgentConfig() *AgentConfig {
183181
}
184182

185183
ac := &AgentConfig{
186-
Enabled: true, // We'll always run inside of a container.
187184
APIEndpoints: []APIEndpoint{{Endpoint: u}},
188185
SkipSSLValidation: false,
189186
SkipKubeletTLSVerify: false,
190187
LogFile: defaultLogFilePath,
191188
LogLevel: "info",
192-
LogToConsole: false,
193189
QueueSize: 20,
194190
MaxProcFDs: 200,
195191
MaxPerMessage: maxMessageBatch,
@@ -321,7 +317,8 @@ func NewAgentConfig(agentYaml *YamlAgentConfig) (*AgentConfig, error) {
321317
}
322318

323319
// (Re)configure the logging from our configuration
324-
if err := NewLoggerLevel(cfg.LogLevel, cfg.LogFile, cfg.LogToConsole); err != nil {
320+
// We always log to stdout
321+
if err := NewLoggerLevel(cfg.LogLevel, cfg.LogFile, true); err != nil {
325322
return nil, err
326323
}
327324

@@ -349,13 +346,6 @@ func NewAgentConfig(agentYaml *YamlAgentConfig) (*AgentConfig, error) {
349346
// mergeEnvironmentVariables applies overrides from environment variables to the process agent configuration
350347
func mergeEnvironmentVariables(c *AgentConfig) *AgentConfig {
351348
var err error
352-
if enabled, err := isAffirmative(os.Getenv("STS_PROCESS_AGENT_ENABLED")); enabled {
353-
c.Enabled = true
354-
c.EnabledChecks = processChecks
355-
} else if !enabled && err == nil {
356-
c.Enabled = false
357-
}
358-
359349
if v := os.Getenv("STS_HOSTNAME"); v != "" {
360350
log.Info("overriding hostname from env DD_HOSTNAME value")
361351
c.HostName = v
@@ -379,25 +369,10 @@ func mergeEnvironmentVariables(c *AgentConfig) *AgentConfig {
379369
c.APIEndpoints[0].APIKey = vals[0]
380370
}
381371

382-
// Support LOG_LEVEL and DD_LOG_LEVEL but prefer DD_LOG_LEVEL
383-
if v := os.Getenv("LOG_LEVEL"); v != "" {
384-
c.LogLevel = v
385-
}
386372
if v := os.Getenv("STS_LOG_LEVEL"); v != "" {
387373
c.LogLevel = v
388374
}
389375

390-
// Logging to console
391-
if enabled, err := isAffirmative(os.Getenv("STS_LOGS_STDOUT")); err == nil {
392-
c.LogToConsole = enabled
393-
}
394-
if enabled, err := isAffirmative(os.Getenv("LOG_TO_CONSOLE")); err == nil {
395-
c.LogToConsole = enabled
396-
}
397-
if enabled, err := isAffirmative(os.Getenv("STS_LOG_TO_CONSOLE")); err == nil {
398-
c.LogToConsole = enabled
399-
}
400-
401376
if proxyURL := os.Getenv("HTTPS_PROXY"); proxyURL != "" {
402377
c.HTTPSProxy, err = url.Parse(proxyURL)
403378
if err != nil {
@@ -449,20 +424,7 @@ func mergeEnvironmentVariables(c *AgentConfig) *AgentConfig {
449424
log.Infof("overriding API endpoint from env")
450425
c.APIEndpoints[0].Endpoint = u
451426
}
452-
if site := os.Getenv("STS_SITE"); site != "" {
453-
log.Infof("Using 'process_dd_url' (%s) and ignoring 'site' (%s)", v, site)
454-
}
455427
log.Infof("Overriding process api endpoint with environment variable `STS_PROCESS_AGENT_URL`: %s", u)
456-
} else if v := os.Getenv("STS_STS_URL"); v != "" {
457-
// check if we don't already have a api endpoint configured, specific process configuration takes precedence.
458-
u, err := url.Parse(v)
459-
if err != nil {
460-
log.Warnf("STS_STS_URL is invalid: %s", err)
461-
} else {
462-
log.Infof("overriding API endpoint from env STS_STS_URL")
463-
c.APIEndpoints[0].Endpoint = u
464-
}
465-
log.Infof("Overriding process api endpoint with environment variable `STS_STS_URL`: %s", u)
466428
}
467429

468430
// Process Arguments Scrubbing
@@ -617,10 +579,6 @@ func mergeEnvironmentVariables(c *AgentConfig) *AgentConfig {
617579
}
618580

619581
// STS
620-
if v, err := strconv.Atoi(os.Getenv("STS_CONTAINER_CHECK_INTERVAL")); err == nil {
621-
c.CheckIntervals["container"] = time.Duration(v) * time.Second
622-
}
623-
624582
if v, err := strconv.Atoi(os.Getenv("STS_PROCESS_CHECK_INTERVAL")); err == nil {
625583
c.CheckIntervals["process"] = time.Duration(v) * time.Second
626584
}

0 commit comments

Comments
 (0)