This is an automated email from the ASF dual-hosted git repository.
rawlin 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 31fc5eb Fix TO to generate monitoring if no snapshot (#5066)
31fc5eb is described below
commit 31fc5eb7ad3201f76762174fd3b11b322b96ac05
Author: Robert O Butts <[email protected]>
AuthorDate: Tue Oct 6 15:53:19 2020 -0600
Fix TO to generate monitoring if no snapshot (#5066)
---
CHANGELOG.md | 1 +
traffic_ops/testing/api/v2/monitoring_test.go | 25 +++++++++++++++++
traffic_ops/testing/api/v2/tc-fixtures.json | 32 ++++++++++++++++++++--
traffic_ops/testing/api/v3/monitoring_test.go | 25 +++++++++++++++++
traffic_ops/testing/api/v3/tc-fixtures.json | 32 ++++++++++++++++++++--
.../traffic_ops_golang/crconfig/snapshot.go | 14 ++++++++--
6 files changed, 122 insertions(+), 7 deletions(-)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index cef9bd2..c324758 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -86,6 +86,7 @@ The format is based on [Keep a
Changelog](http://keepachangelog.com/en/1.0.0/).
- Added an option for `coordinateRange` in the RGB configuration file, so that
in case a client doesn't have a postal code, we can still determine if it
should be allowed or not, based on whether or not the latitude/ longitude of
the client falls within the supplied ranges. [Related github
issue](https://github.com/apache/trafficcontrol/issues/4372)
- Fixed #3548 - Prevents DS regexes with non-consecutive order from generating
invalid CRconfig/snapshot.
- Fixed #5020, #5021 - Creating an ASN with the same number and same cache
group should not be allowed.
+- Fixed #5006 - Traffic Ops now generates the Monitoring on-the-fly if the
snapshot doesn't exist, and logs an error. This fixes upgrading to 4.x to not
break the CDN until a Snapshot is done.
- Fixed #4680 - Change Content-Type to application/json for TR auth calls
### Changed
diff --git a/traffic_ops/testing/api/v2/monitoring_test.go
b/traffic_ops/testing/api/v2/monitoring_test.go
index 4bdf40b..60ae8d7 100644
--- a/traffic_ops/testing/api/v2/monitoring_test.go
+++ b/traffic_ops/testing/api/v2/monitoring_test.go
@@ -23,10 +23,35 @@ import (
func TestMonitoring(t *testing.T) {
WithObjs(t, []TCObj{CDNs, Types, Tenants, Parameters, Profiles,
Statuses, Divisions, Regions, PhysLocations, CacheGroups, Servers,
DeliveryServices}, func() {
+ GetTestMonitoringConfigNoSnapshotOnTheFly(t) // MUST run first
AllCDNsCanSnapshot(t)
})
}
+// GetTestMonitoringConfigNoSnapshotOnTheFly verifies that Traffic Ops
generates a monitoring.json on-the-fly rather than returning "" or "{}" if no
snapshot exists.
+// This MUST NOT be run after a different function in the same Test creates a
Snapshot, or the test will be invalid.
+// This prevents a critical bug of upgrading to 4.x bringing a CDN down until
a Snapshot is performed.
+func GetTestMonitoringConfigNoSnapshotOnTheFly(t *testing.T) {
+ server := tc.Server{}
+ for _, sv := range testData.Servers {
+ if sv.Type != "EDGE" {
+ continue
+ }
+ server = sv
+ break
+ }
+ if server.CDNName == "" {
+ t.Fatal("No edge server found in test data, cannot test")
+ }
+
+ tmConfig, _, err := TOSession.GetTrafficMonitorConfigMap(server.CDNName)
+ if err != nil {
+ t.Error("getting monitoring: " + err.Error())
+ } else if len(tmConfig.TrafficServer) == 0 {
+ t.Error("Expected Monitoring without a snapshot to generate
on-the-fly, actual: empty monitoring object for cdn '" + server.CDNName + "'")
+ }
+}
+
func AllCDNsCanSnapshot(t *testing.T) {
serversByHost := make(map[string]tc.Server)
diff --git a/traffic_ops/testing/api/v2/tc-fixtures.json
b/traffic_ops/testing/api/v2/tc-fixtures.json
index 677617a..e8046de 100644
--- a/traffic_ops/testing/api/v2/tc-fixtures.json
+++ b/traffic_ops/testing/api/v2/tc-fixtures.json
@@ -1450,7 +1450,35 @@
"lastUpdated": "2018-03-02T17:27:11.813052+00:00",
"name": "RASCAL1",
"routing_disabled": false,
- "type": "TM_PROFILE"
+ "type": "TM_PROFILE",
+ "params": [
+ {
+ "configFile": "rascal.properties",
+ "name": "health.threshold.queryTime",
+ "secure": false,
+ "value": "1000"
+ },
+ {
+ "configFile": "rascal.properties",
+ "name": "health.polling.url",
+ "secure": false,
+ "value":
"http://${hostname}/_astats?application=&inf.name=${interface_name}"
+ },
+ {
+ "configFile": "rascal-config.txt",
+ "lastUpdated": "2018-01-19T19:01:21.472279+00:00",
+ "name": "peers.polling.interval",
+ "secure": false,
+ "value": "60"
+ },
+ {
+ "configFile": "rascal-config.txt",
+ "lastUpdated": "2018-01-19T19:01:21.472279+00:00",
+ "name": "health.polling.interval",
+ "secure": false,
+ "value": "30"
+ }
+ ]
},
{
"cdnName": "cdn1",
@@ -1938,7 +1966,7 @@
"mgmtIpNetmask": "",
"offlineReason": null,
"physLocation": "Denver",
- "profile": "EDGE1",
+ "profile": "RASCAL1",
"rack": "RR 119.02",
"revalPending": false,
"routerHostName": "",
diff --git a/traffic_ops/testing/api/v3/monitoring_test.go
b/traffic_ops/testing/api/v3/monitoring_test.go
index 4a81f03..e624960 100644
--- a/traffic_ops/testing/api/v3/monitoring_test.go
+++ b/traffic_ops/testing/api/v3/monitoring_test.go
@@ -23,10 +23,35 @@ import (
func TestMonitoring(t *testing.T) {
WithObjs(t, []TCObj{CDNs, Types, Tenants, Parameters, Profiles,
Statuses, Divisions, Regions, PhysLocations, CacheGroups, Servers, Topologies,
DeliveryServices}, func() {
+ GetTestMonitoringConfigNoSnapshotOnTheFly(t) // MUST run first
AllCDNsCanSnapshot(t)
})
}
+// GetTestMonitoringConfigNoSnapshotOnTheFly verifies that Traffic Ops
generates a monitoring.json on-the-fly rather than returning "" or "{}" if no
snapshot exists.
+// This MUST NOT be run after a different function in the same Test creates a
Snapshot, or the test will be invalid.
+// This prevents a critical bug of upgrading to 4.x bringing a CDN down until
a Snapshot is performed.
+func GetTestMonitoringConfigNoSnapshotOnTheFly(t *testing.T) {
+ server := tc.ServerNullable{}
+ for _, sv := range testData.Servers {
+ if sv.Type != "EDGE" {
+ continue
+ }
+ server = sv
+ break
+ }
+ if server.CDNName == nil || *server.CDNName == "" {
+ t.Fatal("No edge server found in test data, cannot test")
+ }
+
+ tmConfig, _, err :=
TOSession.GetTrafficMonitorConfigMap(*server.CDNName)
+ if err != nil {
+ t.Error("getting monitoring: " + err.Error())
+ } else if len(tmConfig.TrafficServer) == 0 {
+ t.Error("Expected Monitoring without a snapshot to generate
on-the-fly, actual: empty monitoring object for cdn '" + *server.CDNName + "'")
+ }
+}
+
func AllCDNsCanSnapshot(t *testing.T) {
serversByHost := make(map[string]tc.ServerNullable)
diff --git a/traffic_ops/testing/api/v3/tc-fixtures.json
b/traffic_ops/testing/api/v3/tc-fixtures.json
index 3e9c359..c86f5cb 100644
--- a/traffic_ops/testing/api/v3/tc-fixtures.json
+++ b/traffic_ops/testing/api/v3/tc-fixtures.json
@@ -1828,7 +1828,35 @@
"lastUpdated": "2018-03-02T17:27:11.813052+00:00",
"name": "RASCAL1",
"routing_disabled": false,
- "type": "TM_PROFILE"
+ "type": "TM_PROFILE",
+ "params": [
+ {
+ "configFile": "rascal.properties",
+ "name": "health.threshold.queryTime",
+ "secure": false,
+ "value": "1000"
+ },
+ {
+ "configFile": "rascal.properties",
+ "name": "health.polling.url",
+ "secure": false,
+ "value":
"http://${hostname}/_astats?application=&inf.name=${interface_name}"
+ },
+ {
+ "configFile": "rascal-config.txt",
+ "lastUpdated": "2018-01-19T19:01:21.472279+00:00",
+ "name": "peers.polling.interval",
+ "secure": false,
+ "value": "60"
+ },
+ {
+ "configFile": "rascal-config.txt",
+ "lastUpdated": "2018-01-19T19:01:21.472279+00:00",
+ "name": "health.polling.interval",
+ "secure": false,
+ "value": "30"
+ }
+ ]
},
{
"cdnName": "cdn1",
@@ -2463,7 +2491,7 @@
"mgmtIpNetmask": "",
"offlineReason": null,
"physLocation": "Denver",
- "profile": "EDGE1",
+ "profile": "RASCAL1",
"rack": "RR 119.02",
"revalPending": false,
"routerHostName": "",
diff --git a/traffic_ops/traffic_ops_golang/crconfig/snapshot.go
b/traffic_ops/traffic_ops_golang/crconfig/snapshot.go
index 3c2e4d5..7aa6918 100644
--- a/traffic_ops/traffic_ops_golang/crconfig/snapshot.go
+++ b/traffic_ops/traffic_ops_golang/crconfig/snapshot.go
@@ -109,9 +109,17 @@ WHERE c.name = $1
}
return "", false, errors.New("Error querying monitor snapshot:
" + err.Error())
}
- if !monitorSnapshot.Valid {
- // CDN exists, but snapshot doesn't
- return `{}`, true, nil
+ if !monitorSnapshot.Valid || monitorSnapshot.String == "{}" {
+ log.Errorln("Monitoring Snapshot didn't exist! Generating
on-the-fly! This will cause race conditions in Traffic Monitor until a Snapshot
is created!")
+ monitoringJSON, err := monitoring.GetMonitoringJSON(tx, cdn)
+ if err != nil {
+ return "", false, errors.New("creating monitor snapshot
(none existed): " + err.Error())
+ }
+ bts, err := json.Marshal(monitoringJSON)
+ if err != nil {
+ return "", false, errors.New("marshalling monitor
snapshot (none existed): " + err.Error())
+ }
+ return string(bts), true, nil
}
return monitorSnapshot.String, true, nil
}