You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficcontrol.apache.org by ne...@apache.org on 2017/04/12 21:43:55 UTC

[05/13] incubator-trafficcontrol git commit: Add TM2 validator checking all TMs in TO

Add TM2 validator checking all TMs in TO


Project: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/commit/e252d4c9
Tree: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/tree/e252d4c9
Diff: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/diff/e252d4c9

Branch: refs/heads/master
Commit: e252d4c9cb502c7cdd90688f9b6b69f5129cd997
Parents: 83b58d9
Author: Robert Butts <ro...@gmail.com>
Authored: Fri Mar 3 08:05:11 2017 -0700
Committer: Dave Neuman <ne...@apache.org>
Committed: Wed Apr 12 15:43:31 2017 -0600

----------------------------------------------------------------------
 .../traffic_monitor/tmcheck/tmcheck.go          |  6 +-
 .../traffic_monitor/tools/validate-offline.go   | 89 +++++++++++++++-----
 2 files changed, 69 insertions(+), 26 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/e252d4c9/traffic_monitor_golang/traffic_monitor/tmcheck/tmcheck.go
----------------------------------------------------------------------
diff --git a/traffic_monitor_golang/traffic_monitor/tmcheck/tmcheck.go b/traffic_monitor_golang/traffic_monitor/tmcheck/tmcheck.go
index 1178721..0fdab61 100644
--- a/traffic_monitor_golang/traffic_monitor/tmcheck/tmcheck.go
+++ b/traffic_monitor_golang/traffic_monitor/tmcheck/tmcheck.go
@@ -209,10 +209,8 @@ func ValidateAllMonitorsOfflineStates(toClient *to.Session, includeOffline bool)
 			continue
 		}
 
-		fqdn := fmt.Sprintf("%s.%s", server.HostName, server.DomainName)
-		if err := ValidateOfflineStatesWithCRConfig(fqdn, crConfig.CRConfig, toClient); err != nil {
-			errs[enum.TrafficMonitorName(server.HostName)] = err
-		}
+		uri := fmt.Sprintf("http://%s.%s", server.HostName, server.DomainName)
+		errs[enum.TrafficMonitorName(server.HostName)] = ValidateOfflineStatesWithCRConfig(uri, crConfig.CRConfig, toClient)
 	}
 	return errs, nil
 }

http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/e252d4c9/traffic_monitor_golang/traffic_monitor/tools/validate-offline.go
----------------------------------------------------------------------
diff --git a/traffic_monitor_golang/traffic_monitor/tools/validate-offline.go b/traffic_monitor_golang/traffic_monitor/tools/validate-offline.go
index 07eee78..d031007 100644
--- a/traffic_monitor_golang/traffic_monitor/tools/validate-offline.go
+++ b/traffic_monitor_golang/traffic_monitor/tools/validate-offline.go
@@ -24,6 +24,7 @@ package main
 import (
 	"flag"
 	"fmt"
+	"github.com/apache/incubator-trafficcontrol/traffic_monitor_golang/traffic_monitor/enum"
 	"github.com/apache/incubator-trafficcontrol/traffic_monitor_golang/traffic_monitor/tmcheck"
 	to "github.com/apache/incubator-trafficcontrol/traffic_ops/client"
 	"net/http"
@@ -33,7 +34,7 @@ import (
 
 const UserAgent = "tm-offline-validator/0.1"
 
-const LogLimit = 100000
+const LogLimit = 10000
 
 type Log struct {
 	log     *[]string
@@ -76,18 +77,46 @@ func NewLog() Log {
 	return Log{log: &log, errored: &errored, m: &sync.RWMutex{}, limit: limit}
 }
 
+type Logs struct {
+	logs map[enum.TrafficMonitorName]Log
+	m    *sync.RWMutex
+}
+
+func NewLogs() Logs {
+	return Logs{logs: map[enum.TrafficMonitorName]Log{}, m: &sync.RWMutex{}}
+}
+
+func (l Logs) Get(name enum.TrafficMonitorName) Log {
+	l.m.Lock()
+	defer l.m.Unlock()
+	if _, ok := l.logs[name]; !ok {
+		l.logs[name] = NewLog()
+	}
+	return l.logs[name]
+}
+
+func (l Logs) GetMonitors() []enum.TrafficMonitorName {
+	l.m.RLock()
+	defer l.m.RUnlock()
+	monitors := []enum.TrafficMonitorName{}
+	for name, _ := range l.logs {
+		monitors = append(monitors, name)
+	}
+	return monitors
+}
+
 func main() {
 	toURI := flag.String("to", "", "The Traffic Ops URI, whose CRConfig to validate")
 	toUser := flag.String("touser", "", "The Traffic Ops user")
 	toPass := flag.String("topass", "", "The Traffic Ops password")
-	tmURI := flag.String("tm", "", "The Traffic Monitor URI whose CRStates to validate")
 	interval := flag.Duration("interval", time.Second*time.Duration(5), "The interval to validate")
 	grace := flag.Duration("grace", time.Second*time.Duration(30), "The grace period before invalid states are reported")
+	includeOffline := flag.Bool("includeOffline", false, "Whether to include Offline Monitors")
 	help := flag.Bool("help", false, "Usage info")
 	helpBrief := flag.Bool("h", false, "Usage info")
 	flag.Parse()
 	if *help || *helpBrief {
-		fmt.Printf("Usage: go run validate-offline -to https://traffic-ops.example.net -touser bill -topass thelizard -tm http://traffic-monitor.example.net -interval 5s -grace 30s\n")
+		fmt.Printf("Usage: go run validate-offline -to https://traffic-ops.example.net -touser bill -topass thelizard -tm http://traffic-monitor.example.net -interval 5s -grace 30s -includeOffline true\n")
 		return
 	}
 
@@ -97,19 +126,22 @@ func main() {
 		return
 	}
 
-	log := NewLog()
+	logs := NewLogs()
 
-	onErr := func(err error) {
+	onErr := func(name enum.TrafficMonitorName, err error) {
+		log := logs.Get(name)
 		log.Add(fmt.Sprintf("%v ERROR %v\n", time.Now(), err))
 		log.SetErrored(true)
 	}
 
-	onResumeSuccess := func() {
+	onResumeSuccess := func(name enum.TrafficMonitorName) {
+		log := logs.Get(name)
 		log.Add(fmt.Sprintf("%v INFO State Valid\n", time.Now()))
 		log.SetErrored(false)
 	}
 
-	onCheck := func(err error) {
+	onCheck := func(name enum.TrafficMonitorName, err error) {
+		log := logs.Get(name)
 		if err != nil {
 			log.Add(fmt.Sprintf("%v DEBUG invalid: %v\n", time.Now(), err))
 		} else {
@@ -117,14 +149,14 @@ func main() {
 		}
 	}
 
-	go tmcheck.CRStatesOfflineValidator(*tmURI, toClient, *interval, *grace, onErr, onResumeSuccess, onCheck)
+	go tmcheck.AllMonitorsCRStatesOfflineValidator(toClient, *interval, *includeOffline, *grace, onErr, onResumeSuccess, onCheck)
 
-	if err := serve(log, *toURI, *tmURI); err != nil {
+	if err := serve(logs, *toURI); err != nil {
 		fmt.Printf("Serve error: %v\n", err)
 	}
 }
 
-func serve(log Log, toURI string, tmURI string) error {
+func serve(logs Logs, toURI string) error {
 	http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
 		w.Header().Set("Access-Control-Allow-Origin", "*")
 		w.Header().Set("Content-Type", "text/html")
@@ -133,23 +165,36 @@ func serve(log Log, toURI string, tmURI string) error {
 <meta charset="utf-8">
 <meta name="viewport" content="width=device-width, initial-scale=1">
 <title>Traffic Monitor Offline Validator</title>
-<style type="text/css">body{margin:40px auto;max-width:650px;line-height:1.6;font-size:18px;color:#444;padding:0 10px}h1,h2,h3{line-height:1.2}</style>`)
+<style type="text/css">body{margin:40px auto;line-height:1.6;font-size:18px;color:#444;padding:0 2px}h1,h2,h3{line-height:1.2}</style>`)
 
 		fmt.Fprintf(w, `<p>%s`, toURI)
-		fmt.Fprintf(w, `<p>%s`, tmURI)
-		if log.GetErrored() {
-			fmt.Fprintf(w, `<h1 style="color:red">Invalid</h1>`)
-		} else {
-			fmt.Fprintf(w, `<h1 style="color:limegreen">Valid</h1>`)
-		}
 
-		fmt.Fprintf(w, `<pre>`)
-		logCopy := log.Get()
-		for _, msg := range logCopy {
-			fmt.Fprintf(w, "%s\n", msg)
+		fmt.Fprintf(w, `<table style="width:100%%"><tr>`)
+
+		monitors := logs.GetMonitors()
+		for _, monitor := range monitors {
+			fmt.Fprintf(w, `<td>`)
+
+			log := logs.Get(monitor)
+
+			fmt.Fprintf(w, `<p>%s`, monitor)
+			if log.GetErrored() {
+				fmt.Fprintf(w, `<h1 style="color:red">Invalid</h1>`)
+			} else {
+				fmt.Fprintf(w, `<h1 style="color:limegreen">Valid</h1>`)
+			}
+
+			fmt.Fprintf(w, `<pre>`)
+			logCopy := log.Get()
+			for _, msg := range logCopy {
+				fmt.Fprintf(w, "%s\n", msg)
+			}
+			fmt.Fprintf(w, `</pre>`)
+
+			fmt.Fprintf(w, `</td>`)
 		}
-		fmt.Fprintf(w, `</pre>`)
 
+		fmt.Fprintf(w, `</tr></table>`)
 	})
 	return http.ListenAndServe(":80", nil)
 }