-
Notifications
You must be signed in to change notification settings - Fork 138
/
config.go
187 lines (161 loc) · 5.92 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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
// Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
// or more contributor license agreements. Licensed under the Elastic License;
// you may not use this file except in compliance with the Elastic License.
package config
import (
"strings"
"time"
c "github.com/elastic/elastic-agent-libs/config"
)
const (
defaultPort = 6791
defaultNamespace = "default"
// DefaultHost is used when host is not defined or empty
DefaultHost = "localhost"
)
// MonitoringConfig describes a configuration of a monitoring
type MonitoringConfig struct {
Enabled bool `yaml:"enabled" config:"enabled"`
MonitorLogs bool `yaml:"logs" config:"logs"`
MonitorMetrics bool `yaml:"metrics" config:"metrics"`
MetricsPeriod string `yaml:"metrics_period" config:"metrics_period"`
LogMetrics bool `yaml:"-" config:"-"`
HTTP *MonitoringHTTPConfig `yaml:"http" config:"http"`
Namespace string `yaml:"namespace" config:"namespace"`
Pprof *PprofConfig `yaml:"pprof" config:"pprof"`
MonitorTraces bool `yaml:"traces" config:"traces"`
APM APMConfig `yaml:"apm,omitempty" config:"apm,omitempty" json:"apm,omitempty"`
Diagnostics Diagnostics `yaml:"diagnostics,omitempty" json:"diagnostics,omitempty"`
}
// MonitoringHTTPConfig is a config defining HTTP endpoint published by agent
// for other processes to watch its metrics.
// Processes are only exposed when HTTP is enabled.
type MonitoringHTTPConfig struct {
Enabled bool `yaml:"enabled" config:"enabled"`
Host string `yaml:"host" config:"host"`
Port int `yaml:"port" config:"port" validate:"min=0,max=65535"`
Buffer *BufferConfig `yaml:"buffer" config:"buffer"`
// EnabledIsSet is set during the Unpack() operation, and will be set to true if `Enabled` has been manually set by the incoming yaml
// This is done so we can distinguish between a default value supplied by the code, and a user-supplied value
EnabledIsSet bool `yaml:"-" config:"-"`
}
// Unpack reads a config object into the settings.
func (c *MonitoringHTTPConfig) Unpack(cfg *c.C) error {
// do not use MonitoringHTTPConfig, it will end up in a loop
tmp := struct {
Enabled *bool `yaml:"enabled" config:"enabled"`
Host string `yaml:"host" config:"host"`
Port int `yaml:"port" config:"port" validate:"min=0,max=65535"`
Buffer *BufferConfig `yaml:"buffer" config:"buffer"`
}{
Host: c.Host,
Port: c.Port,
Buffer: c.Buffer,
}
if err := cfg.Unpack(&tmp); err != nil {
return err
}
if strings.TrimSpace(tmp.Host) == "" {
tmp.Host = DefaultHost
}
set := MonitoringHTTPConfig{
Host: tmp.Host,
Port: tmp.Port,
Buffer: tmp.Buffer,
}
// this logic is here to help us distinguish between `http.enabled` being manually set after unpacking,
// and whatever a user-specified default may be.
// This is needed in order to prevent a larger set of breaking changes where fleet doesn't expect the HTTP monitor to be live-reloadable
// see https://github.com/elastic/elastic-agent/issues/4582
if tmp.Enabled == nil {
set.EnabledIsSet = false
set.Enabled = c.Enabled
} else {
set.EnabledIsSet = true
set.Enabled = *tmp.Enabled
}
*c = set
return nil
}
// PprofConfig is a struct for the pprof enablement flag.
// It is a nil struct by default to allow the agent to use the a value that the user has injected into fleet.yml as the source of truth that is passed to beats
// TODO get this value from Kibana?
type PprofConfig struct {
Enabled bool `yaml:"enabled" config:"enabled"`
}
// BufferConfig is a struct for for the metrics buffer endpoint
type BufferConfig struct {
Enabled bool `yaml:"enabled" config:"enabled"`
}
// DefaultConfig creates a config with pre-set default values.
func DefaultConfig() *MonitoringConfig {
return &MonitoringConfig{
Enabled: true,
MonitorLogs: true,
MonitorMetrics: true,
LogMetrics: true,
MonitorTraces: false,
HTTP: &MonitoringHTTPConfig{
Enabled: false,
Host: DefaultHost,
Port: defaultPort,
},
Namespace: defaultNamespace,
APM: defaultAPMConfig(),
Diagnostics: defaultDiagnostics(),
}
}
// APMConfig configures APM Tracing.
type APMConfig struct {
Environment string `config:"environment"`
APIKey string `config:"api_key"`
SecretToken string `config:"secret_token"`
Hosts []string `config:"hosts"`
GlobalLabels map[string]string `config:"global_labels"`
TLS APMTLS `config:"tls"`
}
// APMTLS contains the configuration options necessary for configuring TLS in
// apm-agent-go.
type APMTLS struct {
SkipVerify bool `config:"skip_verify"`
ServerCertificate string `config:"server_certificate"`
ServerCA string `config:"server_ca"`
}
func defaultAPMConfig() APMConfig {
return APMConfig{}
}
// Uploader contains the configuration for retries when uploading a file (diagnostics bundle) to fleet-server.
type Uploader struct {
MaxRetries int `config:"max_retries"`
InitDur time.Duration `config:"init_duration"`
MaxDur time.Duration `config:"max_duration"`
}
func defaultUploader() Uploader {
return Uploader{
MaxRetries: 10,
InitDur: time.Second,
MaxDur: time.Minute * 10,
}
}
// Limit contains the configuration for rate-limiting operations
type Limit struct {
Interval time.Duration `config:"interval"`
Burst int `config:"burst"`
}
func defaultLimit() Limit {
return Limit{
Interval: time.Minute,
Burst: 1,
}
}
// Diagnostics contains the configuration needed to configure the diagnostics handler.
type Diagnostics struct {
Uploader Uploader `config:"uploader"`
Limit Limit `config:"limit"`
}
func defaultDiagnostics() Diagnostics {
return Diagnostics{
Uploader: defaultUploader(),
Limit: defaultLimit(),
}
}