shamrickus commented on a change in pull request #4916:
URL: https://github.com/apache/trafficcontrol/pull/4916#discussion_r466687951



##########
File path: traffic_monitor/towrap/towrap.go
##########
@@ -124,59 +157,114 @@ func (h CRConfigHistoryThreadsafe) Add(i *CRConfigStat) {
 
        (*h.hist)[*h.pos] = *i
        *h.pos = (*h.pos + 1) % *h.limit
-       if *h.len < *h.limit {
-               *h.len++
+       if *h.length < *h.limit {
+               *h.length++
        }
 }
 
+// Get retrieves the stored history of CRConfigStat entries.
 func (h CRConfigHistoryThreadsafe) Get() []CRConfigStat {
        h.m.RLock()
        defer h.m.RUnlock()
-       if *h.len < *h.limit {
-               return CopyCRConfigStat((*h.hist)[:*h.len])
+       if *h.length < *h.limit {
+               return CopyCRConfigStat((*h.hist)[:*h.length])
        }
-       new := make([]CRConfigStat, *h.limit)
-       copy(new, (*h.hist)[*h.pos:])
-       copy(new[*h.len-*h.pos:], (*h.hist)[:*h.pos])
-       return new
-}
-
-func CopyCRConfigStat(old []CRConfigStat) []CRConfigStat {
-       new := make([]CRConfigStat, len(old))
-       copy(new, old)
-       return new
+       newStats := make([]CRConfigStat, *h.limit)
+       copy(newStats, (*h.hist)[*h.pos:])
+       copy(newStats[*h.length-*h.pos:], (*h.hist)[:*h.pos])
+       return newStats
 }
 
-type CRConfigStat struct {
-       ReqTime time.Time        `json:"request_time"`
-       ReqAddr string           `json:"request_address"`
-       Stats   tc.CRConfigStats `json:"stats"`
-       Err     error            `json:"error"`
+// Len gives the number of currently stored items in the buffer.
+//
+// An uninitialized buffer has zero length.
+func (h CRConfigHistoryThreadsafe) Len() uint64 {
+       if h.length == nil {
+               return 0
+       }
+       return *h.length
 }
 
-// TrafficOpsSessionThreadsafe provides access to the Traffic Ops client safe 
for multiple goroutines. This fulfills the ITrafficOpsSession interface.
+// TrafficOpsSessionThreadsafe provides access to the Traffic Ops client safe
+// for multiple goroutines. This fulfills the ITrafficOpsSession interface.
 type TrafficOpsSessionThreadsafe struct {
        session            **client.Session // pointer-to-pointer, because 
we're given a pointer from the Traffic Ops package, and we don't want to copy 
it.
+       legacySession      **legacyClient.Session
        m                  *sync.Mutex
        lastCRConfig       ByteMapCache
        crConfigHist       CRConfigHistoryThreadsafe
+       useLegacy          bool

Review comment:
       You are correct, originally I thought there were no code paths where 
legacy would be used, but after a second look it can.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to