@@ -7,64 +7,48 @@ import (
7
7
"strings"
8
8
9
9
"github.com/spf13/viper"
10
- "gopkg.in/yaml.v3"
11
10
)
12
11
13
12
type HostMonitoringLogsConfig struct {
14
- Enabled bool `yaml:"enabled"`
15
- Include []string `yaml:"include,omitempty"`
13
+ Enabled bool `yaml:"enabled" mapstructure:"enabled" `
14
+ Include []string `yaml:"include,omitempty" mapstructure:"include" `
16
15
}
17
16
18
17
type HostMonitoringHostMetricsConfig struct {
19
- Enabled bool `yaml:"enabled"`
18
+ Enabled bool `yaml:"enabled" mapstructure:"enabled" `
20
19
}
21
20
22
21
type HostMonitoringProcessMetricsConfig struct {
23
- Enabled bool `yaml:"enabled"`
22
+ Enabled bool `yaml:"enabled" mapstructure:"enabled" `
24
23
}
25
24
26
25
type HostMonitoringMetricsConfig struct {
27
- Host HostMonitoringHostMetricsConfig `yaml:"host,omitempty"`
28
- Process HostMonitoringProcessMetricsConfig `yaml:"process,omitempty"`
26
+ Host HostMonitoringHostMetricsConfig `yaml:"host,omitempty" mapstructure:"host" `
27
+ Process HostMonitoringProcessMetricsConfig `yaml:"process,omitempty" mapstructure:"process" `
29
28
}
30
29
31
30
type HostMonitoringConfig struct {
32
- Enabled bool `yaml:"enabled"`
33
- Logs HostMonitoringLogsConfig `yaml:"logs,omitempty"`
34
- Metrics HostMonitoringMetricsConfig `yaml:"metrics,omitempty"`
31
+ Enabled bool `yaml:"enabled" mapstructure:"enabled" `
32
+ Logs HostMonitoringLogsConfig `yaml:"logs,omitempty" mapstructure:"logs" `
33
+ Metrics HostMonitoringMetricsConfig `yaml:"metrics,omitempty" mapstructure:"metrics" `
35
34
}
36
35
37
36
type SelfMonitoringConfig struct {
38
- Enabled bool `yaml:"enabled"`
37
+ Enabled bool `yaml:"enabled" mapstructure:"enabled" `
39
38
}
40
39
41
40
type AgentConfig struct {
42
- Token string `yaml:"token"`
43
- ObserveURL string `yaml:"observe_url"`
44
- CloudResourceDetectors []string `yaml:"cloud_resource_detectors,omitempty"`
45
- SelfMonitoring SelfMonitoringConfig `yaml:"self_monitoring,omitempty"`
46
- HostMonitoring HostMonitoringConfig `yaml:"host_monitoring,omitempty"`
47
- OtelConfigOverrides map [string ]any `yaml:"otel_config_overrides,omitempty"`
48
- }
49
-
50
- func UnmarshalViperThroughYaml (v * viper.Viper , out any ) error {
51
- // First unmarshal viper into a map
52
- var viperConfig map [string ]any
53
- if err := viper .Unmarshal (& viperConfig ); err != nil {
54
- return err
55
- }
56
- // Next convert the map into yaml bytes
57
- viperConfigYaml , err := yaml .Marshal (viperConfig )
58
- if err != nil {
59
- return err
60
- }
61
- // Finally unmarshal the yaml bytes into the out struct
62
- return yaml .Unmarshal (viperConfigYaml , out )
41
+ Token string `yaml:"token" mapstructure:"token"`
42
+ ObserveURL string `yaml:"observe_url" mapstructure:"observe_url"`
43
+ CloudResourceDetectors []string `yaml:"cloud_resource_detectors,omitempty" mapstructure:"cloud_resource_detectors"`
44
+ SelfMonitoring SelfMonitoringConfig `yaml:"self_monitoring,omitempty" mapstructure:"self_monitoring"`
45
+ HostMonitoring HostMonitoringConfig `yaml:"host_monitoring,omitempty" mapstructure:"host_monitoring"`
46
+ OtelConfigOverrides map [string ]any `yaml:"otel_config_overrides,omitempty" mapstructure:"otel_config_overrides"`
63
47
}
64
48
65
49
func AgentConfigFromViper (v * viper.Viper ) (* AgentConfig , error ) {
66
50
var config AgentConfig
67
- err := UnmarshalViperThroughYaml ( v , & config )
51
+ err := v . Unmarshal ( & config )
68
52
if err != nil {
69
53
return nil , err
70
54
}
0 commit comments