You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@trafficcontrol.apache.org by GitBox <gi...@apache.org> on 2018/12/10 19:10:16 UTC

[GitHub] rob05c commented on a change in pull request #3053: Traffic Monitor Disk Support

rob05c commented on a change in pull request #3053: Traffic Monitor Disk Support
URL: https://github.com/apache/trafficcontrol/pull/3053#discussion_r240338531
 
 

 ##########
 File path: traffic_monitor/towrap/towrap.go
 ##########
 @@ -229,16 +244,36 @@ func (s *TrafficOpsSessionThreadsafe) CRConfigValid(crc *tc.CRConfig, cdn string
 
 // CRConfigRaw returns the CRConfig from the Traffic Ops. This is safe for multiple goroutines.
 func (s TrafficOpsSessionThreadsafe) CRConfigRaw(cdn string) ([]byte, error) {
+
 	ss := s.get()
+
+	var b []byte
+	var err error
+	var remoteAddr string
+	var reqInf client.ReqInf
+
 	if ss == nil {
 		return nil, ErrNilSession
+	} else {
+		b, reqInf, err = ss.GetCRConfig(cdn)
+		if err == nil {
+			remoteAddr = reqInf.RemoteAddr.String()
+			ioutil.WriteFile(s.CrConfigBackupFile, b, 0644)
+		} else {
+			if s.BackupFileExists() {
+				b, _ = ioutil.ReadFile(s.CrConfigBackupFile)
+				remoteAddr = "127.0.0.1"
+				log.Errorln("Error getting CRConfig from traffic_ops, backup file exists, reading from file")
+			} else {
+				return nil, ErrNilSession
+			}
+		}
 	}
-	b, reqInf, err := ss.GetCRConfig(cdn)
 
-	hist := &CRConfigStat{time.Now(), reqInf.RemoteAddr.String(), tc.CRConfigStats{}, err}
+	hist := &CRConfigStat{time.Now(), remoteAddr, tc.CRConfigStats{}, err}
 	defer s.crConfigHist.Add(hist)
 
-	if err != nil {
+	if err != nil && remoteAddr != "127.0.0.1" {
 
 Review comment:
   Not sure I understand this. If there is an error, but the remoteAddr was `127.0.0.1`, we ignore that error? If the above `remoteAddr = "127.0.0.1"` is the only way the remoteAddr can be `127.0.0.1` (what if TO is running on the same machine as TM? That's allowed), then I think this error will never be non-nil if `remoteAddr == "127.0.0.1"`. Even if so, it's still confusing, I think this could be rewritten to be clearer.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services