forked from DataDog/datadog-agent
-
Notifications
You must be signed in to change notification settings - Fork 2
/
config.go
78 lines (67 loc) · 2.69 KB
/
config.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
// Unless explicitly stated otherwise all files in this repository are licensed
// under the Apache License Version 2.0.
// This product includes software developed at Datadog (https://www.datadoghq.com/).
// Copyright 2016-present Datadog, Inc.
package app
import (
"fmt"
"github.com/StackVista/stackstate-agent/cmd/agent/app/settings"
"github.com/StackVista/stackstate-agent/cmd/agent/common"
cmdconfig "github.com/StackVista/stackstate-agent/cmd/agent/common/commands/config"
"github.com/StackVista/stackstate-agent/pkg/api/util"
"github.com/StackVista/stackstate-agent/pkg/config"
commonsettings "github.com/StackVista/stackstate-agent/pkg/config/settings"
"github.com/spf13/cobra"
"github.com/fatih/color"
)
func init() {
AgentCmd.AddCommand(cmdconfig.Config(getSettingsClient))
}
func setupConfig() error {
if flagNoColor {
color.NoColor = true
}
err := common.SetupConfigWithoutSecrets(confFilePath, "")
if err != nil {
return fmt.Errorf("unable to set up global agent configuration: %v", err)
}
err = config.SetupLogger(loggerName, config.GetEnvDefault("DD_LOG_LEVEL", "off"), "", "", false, true, false)
if err != nil {
fmt.Printf("Cannot setup logger, exiting: %v\n", err)
return err
}
return util.SetAuthToken()
}
func getSettingsClient(_ *cobra.Command, _ []string) (commonsettings.Client, error) {
err := setupConfig()
if err != nil {
return nil, err
}
return common.NewSettingsClient()
}
// initRuntimeSettings builds the map of runtime settings configurable at runtime.
func initRuntimeSettings() error {
// Runtime-editable settings must be registered here to dynamically populate command-line information
if err := commonsettings.RegisterRuntimeSetting(commonsettings.LogLevelRuntimeSetting{}); err != nil {
return err
}
if err := commonsettings.RegisterRuntimeSetting(commonsettings.RuntimeMutexProfileFraction("runtime_mutex_profile_fraction")); err != nil {
return err
}
if err := commonsettings.RegisterRuntimeSetting(commonsettings.RuntimeBlockProfileRate("runtime_block_profile_rate")); err != nil {
return err
}
if err := commonsettings.RegisterRuntimeSetting(settings.DsdStatsRuntimeSetting("dogstatsd_stats")); err != nil {
return err
}
if err := commonsettings.RegisterRuntimeSetting(settings.DsdCaptureDurationRuntimeSetting("dogstatsd_capture_duration")); err != nil {
return err
}
if err := commonsettings.RegisterRuntimeSetting(commonsettings.LogPayloadsRuntimeSetting{}); err != nil {
return err
}
if err := commonsettings.RegisterRuntimeSetting(commonsettings.ProfilingGoroutines("internal_profiling_goroutines")); err != nil {
return err
}
return commonsettings.RegisterRuntimeSetting(commonsettings.ProfilingRuntimeSetting("internal_profiling"))
}