diff --git a/CHANGELOG.md b/CHANGELOG.md index 0b24e6bba9..af6f8ff4b0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -29,6 +29,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/). - [#7021](https://github.com/apache/trafficcontrol/issues/7021) *Cache Config* Fixed cache config for Delivery Services with IP Origins. - [#7043](https://github.com/apache/trafficcontrol/issues/7043) Fixed cache config missing retry parameters for non-topology MSO Delivery Services going direct from edge to origin. - [#7047](https://github.com/apache/trafficcontrol/issues/7047) *Traffic Ops* allow `apply_time` query parameters on the `servers/{id-name}/update` when the CDN is locked. +- [#7048](https://github.com/apache/trafficcontrol/issues/7048) *Traffic Stats* Add configuration value to set the client request timeout for calls to Traffic Ops. - Updated Apache Tomcat from 9.0.43 to 9.0.67 ## [7.0.0] - 2022-07-19 diff --git a/docs/source/admin/traffic_stats.rst b/docs/source/admin/traffic_stats.rst index 525c001b35..1593f94959 100644 --- a/docs/source/admin/traffic_stats.rst +++ b/docs/source/admin/traffic_stats.rst @@ -50,6 +50,7 @@ Traffic Stats's configuration file can be found in :file:`/opt/traffic_stats/con :toUser: The username of the user as whom to connect to Traffic Ops :toPasswd: The password to use when authenticating with Traffic Ops :toUrl: The URL of the Traffic Ops server used by Traffic Stats +:toRequestTimeout: The time, in seconds, before a client request to Traffic Ops is canceled. Defaults to 10 if no value provided :influxUser: Optionally specify the user to use when connecting to InfluxDB (if InfluxDB is not configured to require authentication, has no effect) :influxPassword: Optionally specify the password to use when connecting to InfluxDB (if InfluxDB is not configured to require authentication, has no effect) :pollingInterval: The interval in seconds for which Traffic Monitor will wait between polling for stats and storing them in InfluxDB diff --git a/infrastructure/ansible/roles/traffic_stats/defaults/main.yml b/infrastructure/ansible/roles/traffic_stats/defaults/main.yml index b007ec3d64..7f7eff66b4 100644 --- a/infrastructure/ansible/roles/traffic_stats/defaults/main.yml +++ b/infrastructure/ansible/roles/traffic_stats/defaults/main.yml @@ -28,6 +28,7 @@ ts_install_logdir: "{{ ts_install_basedir }}/var/log/traffic_stats" ts_toUser: ts_toPasswd: ts_toUrl: https://kabletown.invalid +ts_toRequestTimeout: 10 # InfluxDB credentials ts_influxUser: influxUser diff --git a/infrastructure/ansible/roles/traffic_stats/templates/traffic_stats.cfg.j2 b/infrastructure/ansible/roles/traffic_stats/templates/traffic_stats.cfg.j2 index ed0c2d9cf7..a094f5fb2e 100644 --- a/infrastructure/ansible/roles/traffic_stats/templates/traffic_stats.cfg.j2 +++ b/infrastructure/ansible/roles/traffic_stats/templates/traffic_stats.cfg.j2 @@ -15,6 +15,7 @@ "toUser": "{{ ts_toUser }}", "toPasswd": "{{ ts_toPasswd }}", "toUrl": "{{ ts_toUrl }}", + "toRequestTimeout": "{{ ts_toRequestTimeout }}", "influxUser": "{{ ts_influxUser }}", "influxPassword": "{{ ts_influxPassword }}", "pollingInterval": {{ ts_pollingInterval }}, diff --git a/infrastructure/cdn-in-a-box/traffic_stats/run.sh b/infrastructure/cdn-in-a-box/traffic_stats/run.sh index c8bfb9a476..2b68d95744 100755 --- a/infrastructure/cdn-in-a-box/traffic_stats/run.sh +++ b/infrastructure/cdn-in-a-box/traffic_stats/run.sh @@ -75,6 +75,7 @@ cat <<-EOF >$TSCONF "toUser": "$TO_ADMIN_USER", "toPasswd": "$TO_ADMIN_PASSWORD", "toUrl": "$TO_URL", + "toRequestTimeout": 10, "influxUser": "$INFLUXDB_ADMIN_USER", "influxPassword": "$INFLUXDB_ADMIN_PASSWORD", "pollingInterval": 10, diff --git a/traffic_stats/traffic_stats.cfg b/traffic_stats/traffic_stats.cfg index db24e37fe6..753fb1661e 100644 --- a/traffic_stats/traffic_stats.cfg +++ b/traffic_stats/traffic_stats.cfg @@ -2,6 +2,7 @@ "toUser": "admin", "toPasswd": "", "toUrl": "https://localhost", + "toRequestTimeout": 10, "disableInflux": false, "influxUser": "influxUser", "influxPassword": "", diff --git a/traffic_stats/traffic_stats.go b/traffic_stats/traffic_stats.go index f6bd3fc2d3..ed1c694469 100644 --- a/traffic_stats/traffic_stats.go +++ b/traffic_stats/traffic_stats.go @@ -48,9 +48,9 @@ import ( ) const UserAgent = "traffic-stats" -const TrafficOpsRequestTimeout = time.Second * time.Duration(10) const ( + defaultTrafficOpsRequestTimeout = 10 defaultPollingInterval = 10 defaultDailySummaryPollingInterval = 60 defaultConfigInterval = 300 @@ -95,6 +95,7 @@ type StartupConfig struct { ToUser string `json:"toUser"` ToPasswd string `json:"toPasswd"` ToURL string `json:"toUrl"` + ToRequestTimeoutSeconds int `json:"toRequestTimeout"` DisableInflux bool `json:"disableInflux"` InfluxUser string `json:"influxUser"` InfluxPassword string `json:"influxPassword"` @@ -516,6 +517,10 @@ func loadStartupConfig(configFile string, oldConfig StartupConfig) (StartupConfi config.MaxPublishSize = defaultMaxPublishSize } + if config.ToRequestTimeoutSeconds <= 0 { + config.ToRequestTimeoutSeconds = defaultTrafficOpsRequestTimeout + } + if config.LogConfig != nil { if err = log.InitCfg(config.LogConfig); err != nil { return config, fmt.Errorf("initializing logging configuration: %w", err) @@ -721,7 +726,7 @@ func queryDB(con influx.Client, cmd string, database string) (res []influx.Resul } func writeSummaryStats(config StartupConfig, statsSummary tc.StatsSummary) { - to, _, err := client.LoginWithAgent(config.ToURL, config.ToUser, config.ToPasswd, true, UserAgent, false, TrafficOpsRequestTimeout) + to, _, err := client.LoginWithAgent(config.ToURL, config.ToUser, config.ToPasswd, true, UserAgent, false, time.Duration(config.ToRequestTimeoutSeconds)*time.Second) if err != nil { newErr := fmt.Errorf("Could not store summary stats! Error logging in to %v: %v", config.ToURL, err) errorln(newErr) @@ -735,7 +740,7 @@ func writeSummaryStats(config StartupConfig, statsSummary tc.StatsSummary) { func getToData(config StartupConfig, init bool, configChan chan RunningConfig) { var runningConfig RunningConfig - to, _, err := client.LoginWithAgent(config.ToURL, config.ToUser, config.ToPasswd, true, UserAgent, false, TrafficOpsRequestTimeout) + to, _, err := client.LoginWithAgent(config.ToURL, config.ToUser, config.ToPasswd, true, UserAgent, false, time.Duration(config.ToRequestTimeoutSeconds)*time.Second) if err != nil { msg := fmt.Sprintf("Error logging in to %v: %v", config.ToURL, err) if init {