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

 ##########
 File path: traffic_monitor/towrap/towrap.go
 ##########
 @@ -277,8 +316,33 @@ func (s TrafficOpsSessionThreadsafe) 
trafficMonitorConfigMapRaw(cdn string) (*tc
        if ss == nil {
                return nil, ErrNilSession
        }
-       configMap, _, error := ss.GetTrafficMonitorConfigMap(cdn)
-       return configMap, error
+
+       configMap, _, err := ss.GetTrafficMonitorConfigMap(cdn)
+       if err != nil {
+               // Default error case, no backup file exists
+               if !s.BackupFileExists() {
+                       return configMap, err
+               }
+
+               b, err := ioutil.ReadFile(s.TMConfigBackupFile)
+               if err != nil {
+                       return nil, errors.New("reading TMConfigBackupFile: " + 
err.Error())
+               }
+
+               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 {
+                       log.Errorln("Error unmarshaling JSON from 
TMConfigBackupFile")
 
 Review comment:
   This is kind of confusing. I thought it was returning the `configMap` and a 
nil error, even if the Unmarshal fails. It took me a bit to realize it's not, 
because it's `if err = json.Unmarshal` not `if err := json.Unmarshal`.
   
   I also think it shouldn't be logging an error, if it returns one. When an 
error is returned, the caller should log it if appropriate, so this will 
probably result in a double-log. 
   
   Also just for the future, the `tc-log` funcs add the word `ERROR:`, 
`DEBUG:`, etc, so it's better to: `log.Errorln("unmarshaling...` not 
`log.Errorln("Error unmarshalling...`.
   
   But, I think this would be more obvious, if it were changed to:
   
   ```
   if err := json.Unmarshal(b, &configMap); err != nil {
        return nil, errors.New("unmarshalling backup file monitoring.json: " + 
err.Error()")
   }  
   return configMap, nil
   ```

----------------------------------------------------------------
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:
[email protected]


With regards,
Apache Git Services

Reply via email to