Backport stats flush interval 1.16.x (#19849)

* 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

(cherry picked from commit bfb3a43648634e117c8405d6a6e3cc837fb8e3dc)

* fix pr labeller

---------

Co-authored-by: Ashvitha <ashvitha.sridharan@hashicorp.com>
This commit is contained in:
John Buonassisi 2023-12-06 13:18:36 -08:00 committed by GitHub
parent 236ceb3b40
commit 1a9f2944eb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 61 additions and 47 deletions

3
.changelog/19663.txt Normal file
View File

@ -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.
```

View File

@ -1,6 +1,6 @@
# Copyright (c) HashiCorp, Inc. # Copyright (c) HashiCorp, Inc.
# SPDX-License-Identifier: MPL-2.0 # SPDX-License-Identifier: MPL-2.0
name: "Pull Request Labeler" name: "Pull Request Labeler"
on: on:
pull_request_target: pull_request_target:
@ -10,8 +10,8 @@ jobs:
triage: triage:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/labeler@main - uses: actions/labeler@0967ca812e7fdc8f5f71402a1b486d5bd061fe20 # v4.2.0
with: with:
repo-token: "${{ secrets.GITHUB_TOKEN }}" repo-token: "${{ secrets.GITHUB_TOKEN }}"
configuration-path: .github/pr-labeler.yml configuration-path: .github/pr-labeler.yml
sync-labels: false sync-labels: false

View File

@ -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 // Setup telemetry collector if needed. This MUST happen after the Static*JSON is set above
if c.TelemetryCollectorBindSocketDir != "" { 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) appendTelemetryCollectorConfig(args, c.TelemetryCollectorBindSocketDir)
} }

View File

@ -5,6 +5,7 @@ package envoy
import ( import (
"encoding/json" "encoding/json"
"fmt"
"reflect" "reflect"
"regexp" "regexp"
"strings" "strings"
@ -628,47 +629,50 @@ func TestBootstrapConfig_ConfigureArgs(t *testing.T) {
TelemetryCollectorBindSocketDir: "/tmp/consul/telemetry-collector", TelemetryCollectorBindSocketDir: "/tmp/consul/telemetry-collector",
}, },
wantArgs: BootstrapTplArgs{ wantArgs: BootstrapTplArgs{
ProxyID: "web-sidecar-proxy", StatsFlushInterval: "60s",
StatsConfigJSON: defaultStatsConfigJSON, ProxyID: "web-sidecar-proxy",
StatsSinksJSON: `{ StatsConfigJSON: defaultStatsConfigJSON,
"name": "envoy.stat_sinks.metrics_service", StatsSinksJSON: expectedTelemetryCollectorStatsSink,
"typed_config": { StaticClustersJSON: expectedTelemetryCollectorCluster,
"@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"
}
}
}
}
]
}
]
}
}`,
}, },
wantErr: false, 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", name: "simple-statsd-sink",
input: BootstrapConfig{ input: BootstrapConfig{

View File

@ -219,6 +219,7 @@
], ],
"use_all_default_tags": true "use_all_default_tags": true
}, },
"stats_flush_interval": "60s",
"dynamic_resources": { "dynamic_resources": {
"lds_config": { "lds_config": {
"ads": {}, "ads": {},

View File

@ -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_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. 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. The [Advanced Configuration](#advanced-configuration) section describes additional configurations that allow incremental or complete control over the bootstrap configuration generated.