agent/config: change disable_host_metrics to enable_host_metrics and default to false unless configured /w cloud integration

pull/17038/head
Nick Ethier 2023-05-24 17:01:03 -04:00
parent 2a3dd5066a
commit 50621fa098
10 changed files with 37 additions and 16 deletions

View File

@ -941,7 +941,6 @@ func (b *builder) build() (rt RuntimeConfig, err error) {
CirconusCheckTags: stringVal(c.Telemetry.CirconusCheckTags),
CirconusSubmissionInterval: stringVal(c.Telemetry.CirconusSubmissionInterval),
CirconusSubmissionURL: stringVal(c.Telemetry.CirconusSubmissionURL),
DisableHostMetrics: boolVal(c.Telemetry.DisableHostMetrics),
DisableHostname: boolVal(c.Telemetry.DisableHostname),
DogstatsdAddr: stringVal(c.Telemetry.DogstatsdAddr),
DogstatsdTags: c.Telemetry.DogstatsdTags,
@ -1107,6 +1106,9 @@ func (b *builder) build() (rt RuntimeConfig, err error) {
LocalProxyConfigResyncInterval: 30 * time.Second,
}
// host metrics are enabled by default if consul is configured with HashiCorp Cloud Platform integration
rt.Telemetry.EnableHostMetrics = boolValWithDefault(c.Telemetry.EnableHostMetrics, rt.IsCloudEnabled())
rt.TLS, err = b.buildTLSConfig(rt, c.TLS)
if err != nil {
return RuntimeConfig{}, err

View File

@ -556,3 +556,22 @@ func TestBuilder_parsePrefixFilter(t *testing.T) {
}
})
}
func TestBuidler_hostMetricsWithCloud(t *testing.T) {
devMode := true
builderOpts := LoadOpts{
DevMode: &devMode,
DefaultConfig: FileSource{
Name: "test",
Format: "hcl",
Data: `cloud{ resource_id = "abc" client_id = "abc" client_secret = "abc"}`,
},
}
result, err := Load(builderOpts)
require.NoError(t, err)
require.Empty(t, result.Warnings)
cfg := result.RuntimeConfig
require.NotNil(t, cfg)
require.True(t, cfg.Telemetry.EnableHostMetrics)
}

View File

@ -690,8 +690,8 @@ type Telemetry struct {
CirconusCheckTags *string `mapstructure:"circonus_check_tags" json:"circonus_check_tags,omitempty"`
CirconusSubmissionInterval *string `mapstructure:"circonus_submission_interval" json:"circonus_submission_interval,omitempty"`
CirconusSubmissionURL *string `mapstructure:"circonus_submission_url" json:"circonus_submission_url,omitempty"`
DisableHostMetrics *bool `mapstructure:"disable_host_metrics" json:"disable_host_metrics,omitempty"`
DisableHostname *bool `mapstructure:"disable_hostname" json:"disable_hostname,omitempty"`
EnableHostMetrics *bool `mapstructure:"enable_host_metrics" json:"enable_host_metrics,omitempty"`
DogstatsdAddr *string `mapstructure:"dogstatsd_addr" json:"dogstatsd_addr,omitempty"`
DogstatsdTags []string `mapstructure:"dogstatsd_tags" json:"dogstatsd_tags,omitempty"`
RetryFailedConfiguration *bool `mapstructure:"retry_failed_connection" json:"retry_failed_connection,omitempty"`

View File

@ -6754,7 +6754,7 @@ func TestLoad_FullConfig(t *testing.T) {
Expiration: 15 * time.Second,
Name: "ftO6DySn", // notice this is the same as the metrics prefix
},
DisableHostMetrics: true,
EnableHostMetrics: true,
},
TLS: tlsutil.Config{
InternalRPC: tlsutil.ProtocolConfig{

View File

@ -462,10 +462,10 @@
"CirconusSubmissionInterval": "",
"CirconusSubmissionURL": "",
"Disable": false,
"DisableHostMetrics": false,
"DisableHostname": false,
"DogstatsdAddr": "",
"DogstatsdTags": [],
"EnableHostMetrics": false,
"FilterDefault": false,
"MetricsPrefix": "",
"PrometheusOpts": {
@ -511,4 +511,4 @@
"VersionPrerelease": "",
"Watches": [],
"XDSUpdateRateLimit": 0
}
}

View File

@ -690,7 +690,7 @@ telemetry {
circonus_check_tags = "prvO4uBl"
circonus_submission_interval = "DolzaflP"
circonus_submission_url = "gTcbS93G"
disable_host_metrics = true
enable_host_metrics = true
disable_hostname = true
dogstatsd_addr = "0wSndumK"
dogstatsd_tags = [ "3N81zSUB","Xtj8AnXZ" ]

View File

@ -808,7 +808,7 @@
"circonus_check_tags": "prvO4uBl",
"circonus_submission_interval": "DolzaflP",
"circonus_submission_url": "gTcbS93G",
"disable_host_metrics": true,
"enable_host_metrics": true,
"disable_hostname": true,
"dogstatsd_addr": "0wSndumK",
"dogstatsd_tags": [

View File

@ -120,7 +120,7 @@ func NewBaseDeps(configLoader ConfigLoader, logOut io.Writer, providedLogger hcl
if err != nil {
return d, fmt.Errorf("failed to initialize telemetry: %w", err)
}
if !cfg.Telemetry.Disable && !cfg.Telemetry.DisableHostMetrics {
if !cfg.Telemetry.Disable && cfg.Telemetry.EnableHostMetrics {
ctx, cancel := context.WithCancel(context.Background())
hoststats.NewCollector(ctx, d.Logger, cfg.DataDir)
d.stopHostCollector = cancel

View File

@ -204,17 +204,17 @@ type TelemetryConfig struct {
// hcl: telemetry { statsite_address = string }
StatsiteAddr string `json:"statsite_address,omitempty" mapstructure:"statsite_address"`
// EnableHostMetrics will enable metrics collected about the host system such as cpu memory and disk usage.
//
// hcl: telemetry { enable_host_metrics = (true|false) }
EnableHostMetrics bool `json:"enable_host_metrics,omitempty" mapstructure:"enable_host_metrics"`
// PrometheusOpts provides configuration for the PrometheusSink. Currently the only configuration
// we acquire from hcl is the retention time. We also use definition slices that are set in agent setup
// before being passed to InitTelemmetry.
//
// hcl: telemetry { prometheus_retention_time = "duration" }
PrometheusOpts prometheus.PrometheusOpts
// DisableHostMetrics will disable metrics collected about the host system such as cpu memory and disk usage.
//
// hcl: telemetry { disable_host_metrics = (true|false) }
DisableHostMetrics bool
}
// MetricsHandler provides an http.Handler for displaying metrics.

View File

@ -1817,9 +1817,6 @@ subsystem that provides Consul's service mesh capabilities.
be used based on **where** this particular instance is running (e.g. a specific
geo location or datacenter, dc:sfo). By default, this is left blank and not used.
- `disable_host_metrics` ((#telemetry-disable_host_metrics))
This disables reporting of host metrics about system resources, defaults to false.
- `disable_hostname` ((#telemetry-disable_hostname))
This controls whether or not to prepend runtime telemetry with the machine's
hostname, defaults to false.
@ -1834,6 +1831,9 @@ subsystem that provides Consul's service mesh capabilities.
of global tags that will be added to all telemetry packets sent to DogStatsD.
It is a list of strings, where each string looks like "my_tag_name:my_tag_value".
- `enable_host_metrics` ((#telemetry-enable_host_metrics))
This enables reporting of host metrics about system resources, defaults to false.
- `filter_default` ((#telemetry-filter_default))
This controls whether to allow metrics that have not been specified by the filter.
Defaults to `true`, which will allow all metrics when no filters are provided.