You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficcontrol.apache.org by ma...@apache.org on 2021/10/06 20:40:01 UTC

[trafficcontrol] branch master updated: Add TM config option to override server hostname (#6246)

This is an automated email from the ASF dual-hosted git repository.

mattjackson pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficcontrol.git


The following commit(s) were added to refs/heads/master by this push:
     new 73e3efd  Add TM config option to override server hostname (#6246)
73e3efd is described below

commit 73e3efd5245546f051dcccae00619182bbd33f1c
Author: Rawlin Peters <ra...@apache.org>
AuthorDate: Wed Oct 6 14:39:46 2021 -0600

    Add TM config option to override server hostname (#6246)
    
    * Add TM config option to override server hostname
    
    This is primarily to allow running multiple instances of TM on the same
    host for development purposes. Without this, each instance of TM running
    on the same host will poll itself, thinking it is its own peer.
    
    * Fix indentation in test data
---
 CHANGELOG.md                          |  1 +
 traffic_monitor/config/config.go      | 33 ++++-----------------------------
 traffic_monitor/config/config_test.go | 30 ++++++++++++++++++++++++++++--
 traffic_monitor/traffic_monitor.go    |  4 ++++
 4 files changed, 37 insertions(+), 31 deletions(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index c11cc52..98a9939 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -8,6 +8,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
 - [#5674](https://github.com/apache/trafficcontrol/issues/5674) Added new query parameters `cdn` and `maxRevalDurationDays` to the `GET /api/x/jobs` Traffic Ops API to filter by CDN name and within the start_time window defined by the `maxRevalDurationDays` GLOBAL profile parameter, respectively.
 - Added a new Traffic Ops cdn.conf option -- `disable_auto_cert_deletion` -- in order to optionally prevent the automatic deletion of certificates for delivery services that no longer exist whenever a CDN snapshot is taken.
 - [#6034](https://github.com/apache/trafficcontrol/issues/6034) Added new query parameter `cdn` to the `GET /api/x/deliveryserviceserver` Traffic Ops API to filter by CDN name
+- Added a new Traffic Monitor configuration option -- `short_hostname_override` -- to traffic_monitor.cfg to allow overriding the system hostname that Traffic Monitor uses.
 - A new Traffic Portal server command-line option `-c` to specify a configuration file, and the ability to set `log: null` to log to stdout (consult documentation for details).
 
 ### Fixed
diff --git a/traffic_monitor/config/config.go b/traffic_monitor/config/config.go
index a105ded..152359f 100644
--- a/traffic_monitor/config/config.go
+++ b/traffic_monitor/config/config.go
@@ -118,10 +118,12 @@ type Config struct {
 	TrafficOpsMaxRetryInterval   time.Duration   `json:"-"`
 	CRConfigBackupFile           string          `json:"crconfig_backup_file"`
 	TMConfigBackupFile           string          `json:"tmconfig_backup_file"`
-	TrafficOpsDiskRetryMax       uint64          `json:"-"`
+	TrafficOpsDiskRetryMax       uint64          `json:"traffic_ops_disk_retry_max"`
 	CachePollingProtocol         PollingProtocol `json:"cache_polling_protocol"`
 	PeerPollingProtocol          PollingProtocol `json:"peer_polling_protocol"`
 	HTTPPollingFormat            string          `json:"http_polling_format"`
+	// ShortHostnameOverride is for explicitly setting a hostname rather than using the output of `hostname -s`.
+	ShortHostnameOverride string `json:"short_hostname_override"`
 }
 
 func (c Config) ErrorLog() log.LogLocation   { return log.LogLocation(c.LogLocationError) }
@@ -157,6 +159,7 @@ var DefaultConfig = Config{
 	CachePollingProtocol:         Both,
 	PeerPollingProtocol:          Both,
 	HTTPPollingFormat:            HTTPPollingFormat,
+	ShortHostnameOverride:        "",
 }
 
 // MarshalJSON marshals custom millisecond durations. Aliasing inspired by http://choly.ca/post/go-json-marshalling/
@@ -166,8 +169,6 @@ func (c *Config) MarshalJSON() ([]byte, error) {
 	return json.Marshal(&struct {
 		MonitorConfigPollingIntervalMs uint64 `json:"monitor_config_polling_interval_ms"`
 		HTTPTimeoutMS                  uint64 `json:"http_timeout_ms"`
-		PeerOptimistic                 bool   `json:"peer_optimistic"`
-		PeerOptimisticQuorumMin        int    `json:"peer_optimistic_quorum_min"`
 		HealthFlushIntervalMs          uint64 `json:"health_flush_interval_ms"`
 		StatFlushIntervalMs            uint64 `json:"stat_flush_interval_ms"`
 		StatBufferIntervalMs           uint64 `json:"stat_buffer_interval_ms"`
@@ -177,8 +178,6 @@ func (c *Config) MarshalJSON() ([]byte, error) {
 	}{
 		MonitorConfigPollingIntervalMs: uint64(c.MonitorConfigPollingInterval / time.Millisecond),
 		HTTPTimeoutMS:                  uint64(c.HTTPTimeout / time.Millisecond),
-		PeerOptimistic:                 bool(true),
-		PeerOptimisticQuorumMin:        int(c.PeerOptimisticQuorumMin),
 		HealthFlushIntervalMs:          uint64(c.HealthFlushInterval / time.Millisecond),
 		StatFlushIntervalMs:            uint64(c.StatFlushInterval / time.Millisecond),
 		StatBufferIntervalMs:           uint64(c.StatBufferInterval / time.Millisecond),
@@ -192,8 +191,6 @@ func (c *Config) UnmarshalJSON(data []byte) error {
 	aux := &struct {
 		MonitorConfigPollingIntervalMs *uint64 `json:"monitor_config_polling_interval_ms"`
 		HTTPTimeoutMS                  *uint64 `json:"http_timeout_ms"`
-		PeerOptimistic                 *bool   `json:"peer_optimistic"`
-		PeerOptimisticQuorumMin        *int    `json:"peer_optimistic_quorum_min"`
 		HealthFlushIntervalMs          *uint64 `json:"health_flush_interval_ms"`
 		StatFlushIntervalMs            *uint64 `json:"stat_flush_interval_ms"`
 		StatBufferIntervalMs           *uint64 `json:"stat_buffer_interval_ms"`
@@ -201,10 +198,6 @@ func (c *Config) UnmarshalJSON(data []byte) error {
 		ServeWriteTimeoutMs            *uint64 `json:"serve_write_timeout_ms"`
 		TrafficOpsMinRetryIntervalMs   *uint64 `json:"traffic_ops_min_retry_interval_ms"`
 		TrafficOpsMaxRetryIntervalMs   *uint64 `json:"traffic_ops_max_retry_interval_ms"`
-		TrafficOpsDiskRetryMax         *uint64 `json:"traffic_ops_disk_retry_max"`
-		CRConfigBackupFile             *string `json:"crconfig_backup_file"`
-		TMConfigBackupFile             *string `json:"tmconfig_backup_file"`
-		HTTPPollingFormat              *string `json:"http_polling_format"`
 		*Alias
 	}{
 		Alias: (*Alias)(c),
@@ -235,30 +228,12 @@ func (c *Config) UnmarshalJSON(data []byte) error {
 	if aux.ServeWriteTimeoutMs != nil {
 		c.ServeWriteTimeout = time.Duration(*aux.ServeWriteTimeoutMs) * time.Millisecond
 	}
-	if aux.PeerOptimistic != nil {
-		c.PeerOptimistic = *aux.PeerOptimistic
-	}
-	if aux.PeerOptimisticQuorumMin != nil {
-		c.PeerOptimisticQuorumMin = *aux.PeerOptimisticQuorumMin
-	}
 	if aux.TrafficOpsMinRetryIntervalMs != nil {
 		c.TrafficOpsMinRetryInterval = time.Duration(*aux.TrafficOpsMinRetryIntervalMs) * time.Millisecond
 	}
 	if aux.TrafficOpsMaxRetryIntervalMs != nil {
 		c.TrafficOpsMaxRetryInterval = time.Duration(*aux.TrafficOpsMaxRetryIntervalMs) * time.Millisecond
 	}
-	if aux.TrafficOpsDiskRetryMax != nil {
-		c.TrafficOpsDiskRetryMax = *aux.TrafficOpsDiskRetryMax
-	}
-	if aux.CRConfigBackupFile != nil {
-		c.CRConfigBackupFile = *aux.CRConfigBackupFile
-	}
-	if aux.TMConfigBackupFile != nil {
-		c.TMConfigBackupFile = *aux.TMConfigBackupFile
-	}
-	if aux.HTTPPollingFormat != nil {
-		c.HTTPPollingFormat = *aux.HTTPPollingFormat
-	}
 	return nil
 }
 
diff --git a/traffic_monitor/config/config_test.go b/traffic_monitor/config/config_test.go
index a213e8a..c3df7b2 100644
--- a/traffic_monitor/config/config_test.go
+++ b/traffic_monitor/config/config_test.go
@@ -27,8 +27,8 @@ const exampleTMConfig = `
 {
 	"monitor_config_polling_interval_ms": 5000,
 	"http_timeout_ms": 30000,
-	"peer_optimistic": true,
-	"peer_optimistic_quorum_min": 0,
+	"peer_optimistic": false,
+	"peer_optimistic_quorum_min": 3,
 	"max_events": 200,
 	"health_flush_interval_ms": 1000,
 	"stat_flush_interval_ms": 1000,
@@ -40,6 +40,11 @@ const exampleTMConfig = `
 	"serve_read_timeout_ms": 10000,
 	"serve_write_timeout_ms": 10000,
 	"stat_buffer_interval_ms": 20000,
+	"short_hostname_override": "foobar",
+	"traffic_ops_disk_retry_max": 35,
+	"crconfig_backup_file": "crconfig.asdf",
+	"tmconfig_backup_file": "tmconfig.asdf",
+	"http_polling_format": "thisformatdoesnotexist",
 	"static_file_dir": "static/"
 }
 `
@@ -64,4 +69,25 @@ func TestLoggingConfig(t *testing.T) {
 	if string(c.DebugLog()) != c.LogLocationDebug {
 		t.Errorf("debug log location - expected: %s, actual: %s\n", c.LogLocationDebug, string(c.DebugLog()))
 	}
+	if c.ShortHostnameOverride != "foobar" {
+		t.Errorf("ShortHostnameOverride - expected: foobar, actual: %s", c.ShortHostnameOverride)
+	}
+	if c.PeerOptimistic != false {
+		t.Errorf("PeerOmptimistic - expected: false, actual: %t", c.PeerOptimistic)
+	}
+	if c.PeerOptimisticQuorumMin != 3 {
+		t.Errorf("PeerOmptimisticQuorumMin - expected: 3, actual: %d", c.PeerOptimisticQuorumMin)
+	}
+	if c.TrafficOpsDiskRetryMax != 35 {
+		t.Errorf("TrafficOpsDiskRetryMax - expected: 35, actual: %d", c.TrafficOpsDiskRetryMax)
+	}
+	if c.CRConfigBackupFile != "crconfig.asdf" {
+		t.Errorf("CRConfigBackupFile - expected: crconfig.asdf, actual: %s", c.CRConfigBackupFile)
+	}
+	if c.TMConfigBackupFile != "tmconfig.asdf" {
+		t.Errorf("TMConfigBackupFile - expected: tmconfig.asdf, actual: %s", c.TMConfigBackupFile)
+	}
+	if c.HTTPPollingFormat != "thisformatdoesnotexist" {
+		t.Errorf("HTTPPollingFormat - expected: thisformatdoesnotexist, actual: %s", c.HTTPPollingFormat)
+	}
 }
diff --git a/traffic_monitor/traffic_monitor.go b/traffic_monitor/traffic_monitor.go
index c6af76e..34575e7 100644
--- a/traffic_monitor/traffic_monitor.go
+++ b/traffic_monitor/traffic_monitor.go
@@ -66,6 +66,10 @@ func main() {
 		os.Exit(1)
 	}
 
+	if cfg.ShortHostnameOverride != "" {
+		staticData.Hostname = cfg.ShortHostnameOverride
+	}
+
 	log.Infof("Starting with config %+v\n", cfg)
 
 	err = manager.Start(*opsConfigFile, cfg, staticData, *configFileName)