-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathmain.go
81 lines (70 loc) · 2.37 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package main
import (
"flag"
"os"
"os/signal"
"runtime/pprof"
"syscall"
"github.com/DataDog/datadog-firehose-nozzle/internal/config"
"github.com/DataDog/datadog-firehose-nozzle/internal/logger"
"github.com/DataDog/datadog-firehose-nozzle/internal/nozzle"
"github.com/DataDog/datadog-firehose-nozzle/internal/uaatokenfetcher"
)
const flushMinBytes uint32 = 1024
var (
logFilePath = flag.String("logFile", "", "The agent log file, defaults to STDOUT")
logLevel = flag.Bool("debug", false, "Debug logging")
configFile = flag.String("config", "config/datadog-firehose-nozzle.json", "Location of the nozzle config json file")
)
func main() {
flag.Parse()
// Initialize logger
log := logger.NewLogger(*logLevel, *logFilePath, "datadog-firehose-nozzle", "")
// Load Nozzle Config
var err error
config.NozzleConfig, err = config.Parse(*configFile)
if err != nil {
log.Fatalf("Error parsing config: %s", err.Error())
}
if config.NozzleConfig.FlushMaxBytes < flushMinBytes {
log.Fatalf("Config FlushMaxBytes is too low (%d): must be at least %d", config.NozzleConfig.FlushMaxBytes, flushMinBytes)
}
logString, err := config.NozzleConfig.AsLogString()
if err != nil {
log.Warnf("Failed to serialize config for logging: %s", err.Error())
} else {
log.Infof("Running nozzle with following config: %s", logString)
}
// Initialize UAATokenFetcher
tokenFetcher := uaatokenfetcher.New(
config.NozzleConfig.UAAURL,
config.NozzleConfig.Client,
config.NozzleConfig.ClientSecret,
config.NozzleConfig.InsecureSSLSkipVerify,
log,
)
threadDumpChan := registerGoRoutineDumpSignalChannel()
defer close(threadDumpChan)
go dumpGoRoutine(threadDumpChan)
// Initialize and start Nozzle
log.Infof("Targeting datadog API URL: %s \n", config.NozzleConfig.DataDogURL)
log.Infof("Targeting datadog LogIntake URL: %s \n", config.NozzleConfig.DataDogLogIntakeURL)
datadogNozzle := nozzle.NewNozzle(&config.NozzleConfig, tokenFetcher, log)
err = datadogNozzle.Start()
if err != nil {
log.Error(err.Error())
}
}
func registerGoRoutineDumpSignalChannel() chan os.Signal {
threadDumpChan := make(chan os.Signal, 1)
signal.Notify(threadDumpChan, syscall.SIGUSR1)
return threadDumpChan
}
func dumpGoRoutine(dumpChan chan os.Signal) {
for range dumpChan {
goRoutineProfiles := pprof.Lookup("goroutine")
if goRoutineProfiles != nil {
_ = goRoutineProfiles.WriteTo(os.Stdout, 2)
}
}
}