From bfb3a43648634e117c8405d6a6e3cc837fb8e3dc Mon Sep 17 00:00:00 2001 From: Ashvitha Date: Mon, 20 Nov 2023 16:18:30 -0500 Subject: [PATCH] Default "stats_flush_interval" to 1 minute for Consul Telemetry Collector (#19663) * Set default of 1m for StatsFlushInterval when the collector is setup * Add documentation on the stats_flush_interval value * Do not default in two conditions 1) preconfigured sinks exist 2) preconfigured flush interval exists * Fix wording of docs * Add changelog * Fix docs --- .changelog/19663.txt | 3 + command/connect/envoy/bootstrap_config.go | 5 ++ .../connect/envoy/bootstrap_config_test.go | 80 ++++++++++--------- .../envoy/testdata/telemetry-collector.golden | 1 + .../content/docs/connect/proxies/envoy.mdx | 3 +- 5 files changed, 53 insertions(+), 39 deletions(-) create mode 100644 .changelog/19663.txt diff --git a/.changelog/19663.txt b/.changelog/19663.txt new file mode 100644 index 0000000000..d3b338dfdf --- /dev/null +++ b/.changelog/19663.txt @@ -0,0 +1,3 @@ +```release-note:improvement +connect: Default `stats_flush_interval` to 60 seconds when using the Consul Telemetry Collector, unless custom stats sink are present or an explicit flush interval is configured. +``` \ No newline at end of file diff --git a/command/connect/envoy/bootstrap_config.go b/command/connect/envoy/bootstrap_config.go index 452d3679d6..fa3b317255 100644 --- a/command/connect/envoy/bootstrap_config.go +++ b/command/connect/envoy/bootstrap_config.go @@ -251,6 +251,11 @@ func (c *BootstrapConfig) ConfigureArgs(args *BootstrapTplArgs, omitDeprecatedTa // Setup telemetry collector if needed. This MUST happen after the Static*JSON is set above if c.TelemetryCollectorBindSocketDir != "" { + // Override StatsFlushInterval as 60 seconds (1 minute) to reduce number of metric flushes. + // Only perform this override if there is no custom configuration for stats sinks and flush interval. + if c.StatsFlushInterval == "" && args.StatsSinksJSON == "" { + args.StatsFlushInterval = "60s" + } appendTelemetryCollectorConfig(args, c.TelemetryCollectorBindSocketDir) } diff --git a/command/connect/envoy/bootstrap_config_test.go b/command/connect/envoy/bootstrap_config_test.go index ef05786347..c3bc04c201 100644 --- a/command/connect/envoy/bootstrap_config_test.go +++ b/command/connect/envoy/bootstrap_config_test.go @@ -5,6 +5,7 @@ package envoy import ( "encoding/json" + "fmt" "reflect" "regexp" "strings" @@ -628,47 +629,50 @@ func TestBootstrapConfig_ConfigureArgs(t *testing.T) { TelemetryCollectorBindSocketDir: "/tmp/consul/telemetry-collector", }, wantArgs: BootstrapTplArgs{ - ProxyID: "web-sidecar-proxy", - StatsConfigJSON: defaultStatsConfigJSON, - StatsSinksJSON: `{ - "name": "envoy.stat_sinks.metrics_service", - "typed_config": { - "@type": "type.googleapis.com/envoy.config.metrics.v3.MetricsServiceConfig", - "transport_api_version": "V3", - "grpc_service": { - "envoy_grpc": { - "cluster_name": "consul_telemetry_collector_loopback" - } - }, - "emit_tags_as_labels": true - } - }`, - StaticClustersJSON: `{ - "name": "consul_telemetry_collector_loopback", - "type": "STATIC", - "http2_protocol_options": {}, - "loadAssignment": { - "clusterName": "consul_telemetry_collector_loopback", - "endpoints": [ - { - "lbEndpoints": [ - { - "endpoint": { - "address": { - "pipe": { - "path": "/tmp/consul/telemetry-collector/gqmuzdHCUPAEY5mbF8vgkZCNI14.sock" - } - } - } - } - ] - } - ] - } - }`, + StatsFlushInterval: "60s", + ProxyID: "web-sidecar-proxy", + StatsConfigJSON: defaultStatsConfigJSON, + StatsSinksJSON: expectedTelemetryCollectorStatsSink, + StaticClustersJSON: expectedTelemetryCollectorCluster, }, wantErr: false, }, + { + name: "telemetry-collector-no-default-flush-interval-when-interval-preconfigured", + baseArgs: BootstrapTplArgs{ + ProxyID: "web-sidecar-proxy", + }, + input: BootstrapConfig{ + // Explicitly defined StatsFlushInterval by end user should not be overriden. + StatsFlushInterval: "10s", + TelemetryCollectorBindSocketDir: "/tmp/consul/telemetry-collector", + }, + wantArgs: BootstrapTplArgs{ + StatsFlushInterval: "10s", + ProxyID: "web-sidecar-proxy", + StatsConfigJSON: defaultStatsConfigJSON, + StatsSinksJSON: expectedTelemetryCollectorStatsSink, + StaticClustersJSON: expectedTelemetryCollectorCluster, + }, + }, + { + name: "telemetry-collector-no-default-flush-interval-when-sinks-preconfigured", + baseArgs: BootstrapTplArgs{ + ProxyID: "web-sidecar-proxy", + }, + input: BootstrapConfig{ + // If stats sinks are explicitly defined by end user, do not default StatsFlushInterval. + StatsdURL: "udp://127.0.0.1:9125", + TelemetryCollectorBindSocketDir: "/tmp/consul/telemetry-collector", + }, + wantArgs: BootstrapTplArgs{ + StatsFlushInterval: "", + ProxyID: "web-sidecar-proxy", + StatsConfigJSON: defaultStatsConfigJSON, + StatsSinksJSON: fmt.Sprintf(`%s,%s`, expectedStatsdSink, expectedTelemetryCollectorStatsSink), + StaticClustersJSON: expectedTelemetryCollectorCluster, + }, + }, { name: "simple-statsd-sink", input: BootstrapConfig{ diff --git a/command/connect/envoy/testdata/telemetry-collector.golden b/command/connect/envoy/testdata/telemetry-collector.golden index 81ef486622..5992029c2b 100644 --- a/command/connect/envoy/testdata/telemetry-collector.golden +++ b/command/connect/envoy/testdata/telemetry-collector.golden @@ -219,6 +219,7 @@ ], "use_all_default_tags": true }, + "stats_flush_interval": "60s", "dynamic_resources": { "lds_config": { "ads": {}, diff --git a/website/content/docs/connect/proxies/envoy.mdx b/website/content/docs/connect/proxies/envoy.mdx index 890d980f4c..c060346229 100644 --- a/website/content/docs/connect/proxies/envoy.mdx +++ b/website/content/docs/connect/proxies/envoy.mdx @@ -193,7 +193,8 @@ the [`sidecar_service`](/consul/docs/connect/proxies/deploy-sidecar-services) bl - `envoy_telemetry_collector_bind_socket_dir` - Specifies the directory where Envoy creates a Unix socket. Envoy sends metrics to the socket where a Consul telemetry collector can collect them. - The socket is not configured by default. + The socket is not configured by default. + Enabling this sets Envoy's [`stats_flush_interval`](https://www.envoyproxy.io/docs/envoy/v1.17.2/api-v3/config/bootstrap/v3/bootstrap.proto#envoy-v3-api-field-config-bootstrap-v3-bootstrap-stats-flush-interval) to one minute if `envoy_stats_flush_interval` is unset and if no other stats sinks are configured, like `envoy_dogstats_url`, for instance. The [Advanced Configuration](#advanced-configuration) section describes additional configurations that allow incremental or complete control over the bootstrap configuration generated.