This is an automated email from the ASF dual-hosted git repository.
ocket8888 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 8aabc45 Store the result of GET
/api/2.0/cdns/{{name}}/configs/monitoring to tmconfig.backup (#4991)
8aabc45 is described below
commit 8aabc452c1316c880f53cf7490d3805e84d252d6
Author: Zach Hoffman <[email protected]>
AuthorDate: Wed Sep 2 00:29:38 2020 -0600
Store the result of GET /api/2.0/cdns/{{name}}/configs/monitoring to
tmconfig.backup (#4991)
* - Move MonitorConfigValid and Legacy to tc package
- Return tc.MonitorConfigValid() as the error of
tc.TrafficMonitorTransformToMap() instead of always returning a
nil error
* Store the result of GET /api/2.0/cdns/{{name}}/configs/monitoring to
tmconfig.backup instead of a transformed map
* client.GetTrafficMonitorConfigMap(): Return the result with an err if
validation failed
---
CHANGELOG.md | 1 +
docs/source/development/traffic_monitor.rst | 2 +-
lib/go-tc/traffic_monitor.go | 79 +++++++++++++++++++++-
.../go-tc/traffic_monitor_test.go | 46 ++++++++++---
traffic_monitor/towrap/towrap.go | 47 ++-----------
traffic_ops/testing/api/v2/monitoring_test.go | 4 +-
traffic_ops/testing/api/v3/monitoring_test.go | 2 +-
traffic_ops/v2-client/traffic_monitor.go | 2 +-
traffic_ops/v3-client/traffic_monitor.go | 2 +-
9 files changed, 125 insertions(+), 60 deletions(-)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 14ea89c..044ece7 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -69,6 +69,7 @@ The format is based on [Keep a
Changelog](http://keepachangelog.com/en/1.0.0/).
- Changed ORT Config Generation to be deterministic, which will prevent
spurious diffs when nothing actually changed.
- Changed ORT to find the local ATS config directory and use it when location
Parameters don't exist for many required configs, including all Delivery
Service files (Header Rewrites, Regex Remap, URL Sig, URI Signing).
- Changed the access logs in Traffic Ops to now show the route ID with every
API endpoint call. The Route ID is appended to the end of the access log line.
+- Changed Traffic Monitor's `tmconfig.backup` to store the result of `GET
/api/2.0/cdns/{{name}}/configs/monitoring` instead of a transformed map
- [Multiple Interface
Servers](https://github.com/apache/trafficcontrol/blob/master/blueprints/multi-interface-servers.md)
- Interface data is constructed from IP Address/Gateway/Netmask (and their
IPv6 counterparts) and Interface Name and Interface MTU fields on services.
These **MUST** have proper, valid data before attempting to upgrade or the
upgrade **WILL** fail. In particular IP fields need to be valid IP
addresses/netmasks, and MTU must only be positive integers of at least 1280.
- The `/servers` and `/servers/{{ID}}}` TO API endpoints have been updated
to use and reflect multi-interface servers.
diff --git a/docs/source/development/traffic_monitor.rst
b/docs/source/development/traffic_monitor.rst
index 143706e..422d53a 100644
--- a/docs/source/development/traffic_monitor.rst
+++ b/docs/source/development/traffic_monitor.rst
@@ -193,7 +193,7 @@ Processed and aggregated data must be shared between the
end of the stat and hea
Disk Backup
------------
-The Traffic Monitor configuration and CDN :term:`Snapshot` are both stored as
backup files (:file:`tmconfig.backup` and :file:`crconfig.backup` or whatever
you set the values to in the configuration file). This allows the monitor to
come up and continue serving even if Traffic Ops is down. These files are
updated any time a valid configuration is received from Traffic Ops, so if
Traffic Ops goes down and Traffic Monitor is restarted it can still serve the
previous data. These files can a [...]
+The :ref:`Traffic Monitor configuration <to-api-cdns-name-snapshot>` and
:ref:`CDN Snapshot <to-api-cdns-name-snapshot>` (see :term:`Snapshots`) are
both stored as backup files (:file:`tmconfig.backup` and
:file:`crconfig.backup` or whatever you set the values to in the configuration
file). This allows the monitor to come up and continue serving even if Traffic
Ops is down. These files are updated any time a valid configuration is received
from Traffic Ops, so if Traffic Ops goes down an [...]
Formatting Conventions
======================
diff --git a/lib/go-tc/traffic_monitor.go b/lib/go-tc/traffic_monitor.go
index 3f16a12..0a06afb 100644
--- a/lib/go-tc/traffic_monitor.go
+++ b/lib/go-tc/traffic_monitor.go
@@ -2,6 +2,7 @@ package tc
import (
"encoding/json"
+ "errors"
"fmt"
"strconv"
"strings"
@@ -270,7 +271,44 @@ func TrafficMonitorTransformToMap(tmConfig
*TrafficMonitorConfig) (*TrafficMonit
tm.Profile[profile.Name] = profile
}
- return &tm, nil
+ return &tm, MonitorConfigValid(&tm)
+}
+
+func MonitorConfigValid(cfg *TrafficMonitorConfigMap) error {
+ if cfg == nil {
+ return errors.New("MonitorConfig is nil")
+ }
+ if len(cfg.TrafficServer) == 0 {
+ return errors.New("MonitorConfig.TrafficServer empty (is the
monitoring.json an empty object?)")
+ }
+ if len(cfg.CacheGroup) == 0 {
+ return errors.New("MonitorConfig.CacheGroup empty")
+ }
+ if len(cfg.TrafficMonitor) == 0 {
+ return errors.New("MonitorConfig.TrafficMonitor empty")
+ }
+ // TODO uncomment this, when TO is fixed to include DeliveryServices.
+ // See https://github.com/apache/trafficcontrol/issues/3528
+ // if len(cfg.DeliveryService) == 0 {
+ // return errors.New("MonitorConfig.DeliveryService empty")
+ // }
+ if len(cfg.Profile) == 0 {
+ return errors.New("MonitorConfig.Profile empty")
+ }
+
+ if intervalI, ok := cfg.Config["peers.polling.interval"]; !ok {
+ return
errors.New(`MonitorConfig.Config["peers.polling.interval"] missing,
peers.polling.interval parameter required`)
+ } else if _, ok := intervalI.(float64); !ok {
+ return
fmt.Errorf(`MonitorConfig.Config["peers.polling.interval"] '%v' not a number,
parameter peers.polling.interval must be a number`, intervalI)
+ }
+
+ if intervalI, ok := cfg.Config["health.polling.interval"]; !ok {
+ return
errors.New(`MonitorConfig.Config["health.polling.interval"] missing,
health.polling.interval parameter required`)
+ } else if _, ok := intervalI.(float64); !ok {
+ return
fmt.Errorf(`MonitorConfig.Config["health.polling.interval"] '%v' not a number,
parameter health.polling.interval must be a number`, intervalI)
+ }
+
+ return nil
}
func LegacyTrafficMonitorTransformToMap(tmConfig *LegacyTrafficMonitorConfig)
(*LegacyTrafficMonitorConfigMap, error) {
@@ -309,7 +347,44 @@ func LegacyTrafficMonitorTransformToMap(tmConfig
*LegacyTrafficMonitorConfig) (*
tm.Profile[profile.Name] = profile
}
- return &tm, nil
+ return &tm, LegacyMonitorConfigValid(&tm)
+}
+
+func LegacyMonitorConfigValid(cfg *LegacyTrafficMonitorConfigMap) error {
+ if cfg == nil {
+ return errors.New("MonitorConfig is nil")
+ }
+ if len(cfg.TrafficServer) == 0 {
+ return errors.New("MonitorConfig.TrafficServer empty (is the
monitoring.json an empty object?)")
+ }
+ if len(cfg.CacheGroup) == 0 {
+ return errors.New("MonitorConfig.CacheGroup empty")
+ }
+ if len(cfg.TrafficMonitor) == 0 {
+ return errors.New("MonitorConfig.TrafficMonitor empty")
+ }
+ // TODO uncomment this, when TO is fixed to include DeliveryServices.
+ // See https://github.com/apache/trafficcontrol/issues/3528
+ // if len(cfg.DeliveryService) == 0 {
+ // return errors.New("MonitorConfig.DeliveryService empty")
+ // }
+ if len(cfg.Profile) == 0 {
+ return errors.New("MonitorConfig.Profile empty")
+ }
+
+ if intervalI, ok := cfg.Config["peers.polling.interval"]; !ok {
+ return
errors.New(`MonitorConfig.Config["peers.polling.interval"] missing,
peers.polling.interval parameter required`)
+ } else if _, ok := intervalI.(float64); !ok {
+ return
fmt.Errorf(`MonitorConfig.Config["peers.polling.interval"] '%v' not a number,
parameter peers.polling.interval must be a number`, intervalI)
+ }
+
+ if intervalI, ok := cfg.Config["health.polling.interval"]; !ok {
+ return
errors.New(`MonitorConfig.Config["health.polling.interval"] missing,
health.polling.interval parameter required`)
+ } else if _, ok := intervalI.(float64); !ok {
+ return
fmt.Errorf(`MonitorConfig.Config["health.polling.interval"] '%v' not a number,
parameter health.polling.interval must be a number`, intervalI)
+ }
+
+ return nil
}
type HealthData struct {
diff --git a/traffic_monitor/towrap/towrap_test.go
b/lib/go-tc/traffic_monitor_test.go
similarity index 50%
rename from traffic_monitor/towrap/towrap_test.go
rename to lib/go-tc/traffic_monitor_test.go
index 6761a30..01da451 100644
--- a/traffic_monitor/towrap/towrap_test.go
+++ b/lib/go-tc/traffic_monitor_test.go
@@ -1,4 +1,4 @@
-package towrap
+package tc
/*
* Licensed to the Apache Software Foundation (ASF) under one
@@ -21,26 +21,24 @@ package towrap
import (
"testing"
-
- "github.com/apache/trafficcontrol/lib/go-tc"
)
func TestMonitorConfigValid(t *testing.T) {
- mc := (*tc.LegacyTrafficMonitorConfigMap)(nil)
+ mc := (*TrafficMonitorConfigMap)(nil)
if MonitorConfigValid(mc) == nil {
t.Errorf("MonitorCopnfigValid(nil) expected: error, actual:
nil")
}
- mc = &tc.LegacyTrafficMonitorConfigMap{}
+ mc = &TrafficMonitorConfigMap{}
if MonitorConfigValid(mc) == nil {
t.Errorf("MonitorConfigValid({}) expected: error, actual: nil")
}
- validMC := &tc.LegacyTrafficMonitorConfigMap{
- TrafficServer: map[string]tc.LegacyTrafficServer{"a": {}},
- CacheGroup: map[string]tc.TMCacheGroup{"a": {}},
- TrafficMonitor: map[string]tc.TrafficMonitor{"a": {}},
- DeliveryService: map[string]tc.TMDeliveryService{"a": {}},
- Profile: map[string]tc.TMProfile{"a": {}},
+ validMC := &TrafficMonitorConfigMap{
+ TrafficServer: map[string]TrafficServer{"a": {}},
+ CacheGroup: map[string]TMCacheGroup{"a": {}},
+ TrafficMonitor: map[string]TrafficMonitor{"a": {}},
+ DeliveryService: map[string]TMDeliveryService{"a": {}},
+ Profile: map[string]TMProfile{"a": {}},
Config: map[string]interface{}{
"peers.polling.interval": 42.0,
"health.polling.interval": 24.0,
@@ -50,3 +48,29 @@ func TestMonitorConfigValid(t *testing.T) {
t.Errorf("MonitorConfigValid(%++v) expected: nil, actual: %+v",
validMC, err)
}
}
+
+func TestLegacyMonitorConfigValid(t *testing.T) {
+ mc := (*LegacyTrafficMonitorConfigMap)(nil)
+ if LegacyMonitorConfigValid(mc) == nil {
+ t.Errorf("MonitorCopnfigValid(nil) expected: error, actual:
nil")
+ }
+ mc = &LegacyTrafficMonitorConfigMap{}
+ if LegacyMonitorConfigValid(mc) == nil {
+ t.Errorf("MonitorConfigValid({}) expected: error, actual: nil")
+ }
+
+ validMC := &LegacyTrafficMonitorConfigMap{
+ TrafficServer: map[string]LegacyTrafficServer{"a": {}},
+ CacheGroup: map[string]TMCacheGroup{"a": {}},
+ TrafficMonitor: map[string]TrafficMonitor{"a": {}},
+ DeliveryService: map[string]TMDeliveryService{"a": {}},
+ Profile: map[string]TMProfile{"a": {}},
+ Config: map[string]interface{}{
+ "peers.polling.interval": 42.0,
+ "health.polling.interval": 24.0,
+ },
+ }
+ if err := LegacyMonitorConfigValid(validMC); err != nil {
+ t.Errorf("MonitorConfigValid(%++v) expected: nil, actual: %+v",
validMC, err)
+ }
+}
\ No newline at end of file
diff --git a/traffic_monitor/towrap/towrap.go b/traffic_monitor/towrap/towrap.go
index ebd0ccd..33c8a58 100644
--- a/traffic_monitor/towrap/towrap.go
+++ b/traffic_monitor/towrap/towrap.go
@@ -221,42 +221,6 @@ func (s *TrafficOpsSessionThreadsafe) CRConfigValid(crc
*tc.CRConfig, cdn string
return nil
}
-func MonitorConfigValid(cfg *tc.LegacyTrafficMonitorConfigMap) error {
- if cfg == nil {
- return errors.New("MonitorConfig is nil")
- }
- if len(cfg.TrafficServer) == 0 {
- return errors.New("MonitorConfig.TrafficServer empty (is the
monitoring.json an empty object?)")
- }
- if len(cfg.CacheGroup) == 0 {
- return errors.New("MonitorConfig.CacheGroup empty")
- }
- if len(cfg.TrafficMonitor) == 0 {
- return errors.New("MonitorConfig.TrafficMonitor empty")
- }
- // TODO uncomment this, when TO is fixed to include DeliveryServices.
- // See https://github.com/apache/trafficcontrol/issues/3528
- // if len(cfg.DeliveryService) == 0 {
- // return errors.New("MonitorConfig.DeliveryService empty")
- // }
- if len(cfg.Profile) == 0 {
- return errors.New("MonitorConfig.Profile empty")
- }
-
- if intervalI, ok := cfg.Config["peers.polling.interval"]; !ok {
- return
errors.New(`MonitorConfig.Config["peers.polling.interval"] missing,
peers.polling.interval parameter required`)
- } else if _, ok := intervalI.(float64); !ok {
- return
fmt.Errorf(`MonitorConfig.Config["peers.polling.interval"] '%v' not a number,
parameter peers.polling.interval must be a number`, intervalI)
- }
-
- if intervalI, ok := cfg.Config["health.polling.interval"]; !ok {
- return
errors.New(`MonitorConfig.Config["health.polling.interval"] missing,
health.polling.interval parameter required`)
- } else if _, ok := intervalI.(float64); !ok {
- return
fmt.Errorf(`MonitorConfig.Config["health.polling.interval"] '%v' not a number,
parameter health.polling.interval must be a number`, intervalI)
- }
-
- return nil
-}
// CRConfigRaw returns the CRConfig from the Traffic Ops. This is safe for
multiple goroutines.
func (s TrafficOpsSessionThreadsafe) CRConfigRaw(cdn string) ([]byte, error) {
@@ -326,15 +290,16 @@ func (s TrafficOpsSessionThreadsafe) LastCRConfig(cdn
string) ([]byte, time.Time
// TrafficMonitorConfigMapRaw returns the Traffic Monitor config map from the
Traffic Ops, directly from the monitoring.json endpoint. This is not usually
what is needed, rather monitoring needs the snapshotted CRConfig data, which is
filled in by `LegacyTrafficMonitorConfigMap`. This is safe for multiple
goroutines.
func (s TrafficOpsSessionThreadsafe) trafficMonitorConfigMapRaw(cdn string)
(*tc.LegacyTrafficMonitorConfigMap, error) {
+ var configMap *tc.LegacyTrafficMonitorConfigMap
ss := s.get()
if ss == nil {
return nil, ErrNilSession
}
- configMap, _, err := ss.GetTrafficMonitorConfigMap(cdn)
+ tmConfig, _, err := ss.GetTrafficMonitorConfig(cdn)
if err == nil {
- err = MonitorConfigValid(configMap)
+ configMap, err = tc.LegacyTrafficMonitorTransformToMap(tmConfig)
}
if err != nil {
@@ -350,14 +315,14 @@ func (s TrafficOpsSessionThreadsafe)
trafficMonitorConfigMapRaw(cdn string) (*tc
log.Errorln("Error getting configMap from traffic_ops, backup
file exists, reading from file")
json := jsoniter.ConfigFastest
- if err := json.Unmarshal(b, &configMap); err != nil {
+ if err := json.Unmarshal(b, &tmConfig); err != nil {
return nil, errors.New("unmarhsalling backup file
monitoring.json: " + err.Error())
}
- return configMap, err
+ return tc.LegacyTrafficMonitorTransformToMap(tmConfig)
}
json := jsoniter.ConfigFastest
- data, err := json.Marshal(*configMap)
+ data, err := json.Marshal(*tmConfig)
if err == nil {
ioutil.WriteFile(s.TMConfigBackupFile, data, 0644)
}
diff --git a/traffic_ops/testing/api/v2/monitoring_test.go
b/traffic_ops/testing/api/v2/monitoring_test.go
index ecc50cb..4bdf40b 100644
--- a/traffic_ops/testing/api/v2/monitoring_test.go
+++ b/traffic_ops/testing/api/v2/monitoring_test.go
@@ -42,8 +42,8 @@ func AllCDNsCanSnapshot(t *testing.T) {
continue
}
- _, _, err = TOSession.GetTrafficMonitorConfigMap(cdn.Name)
- if err != nil {
+ tmConfig, _, err :=
TOSession.GetTrafficMonitorConfigMap(cdn.Name)
+ if err != nil && tmConfig == nil {
t.Error(err)
continue
}
diff --git a/traffic_ops/testing/api/v3/monitoring_test.go
b/traffic_ops/testing/api/v3/monitoring_test.go
index 746fb41..4a81f03 100644
--- a/traffic_ops/testing/api/v3/monitoring_test.go
+++ b/traffic_ops/testing/api/v3/monitoring_test.go
@@ -43,7 +43,7 @@ func AllCDNsCanSnapshot(t *testing.T) {
}
tmConfig, _, err :=
TOSession.GetTrafficMonitorConfigMap(cdn.Name)
- if err != nil {
+ if err != nil && tmConfig == nil {
t.Error(err)
continue
}
diff --git a/traffic_ops/v2-client/traffic_monitor.go
b/traffic_ops/v2-client/traffic_monitor.go
index bafccf5..52804a5 100644
--- a/traffic_ops/v2-client/traffic_monitor.go
+++ b/traffic_ops/v2-client/traffic_monitor.go
@@ -41,7 +41,7 @@ func (to *Session) GetTrafficMonitorConfigMap(cdn string)
(*tc.LegacyTrafficMoni
}
tmConfigMap, err := tc.LegacyTrafficMonitorTransformToMap(tmConfig)
if err != nil {
- return nil, reqInf, err
+ return tmConfigMap, reqInf, err
}
return tmConfigMap, reqInf, nil
}
diff --git a/traffic_ops/v3-client/traffic_monitor.go
b/traffic_ops/v3-client/traffic_monitor.go
index 81c96b1..5d9e268 100644
--- a/traffic_ops/v3-client/traffic_monitor.go
+++ b/traffic_ops/v3-client/traffic_monitor.go
@@ -41,7 +41,7 @@ func (to *Session) GetTrafficMonitorConfigMap(cdn string)
(*tc.TrafficMonitorCon
}
tmConfigMap, err := tc.TrafficMonitorTransformToMap(tmConfig)
if err != nil {
- return nil, reqInf, err
+ return tmConfigMap, reqInf, err
}
return tmConfigMap, reqInf, nil
}