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-
8270func 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 ("\n Results 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- }
0 commit comments