ocket8888 commented on a change in pull request #4916:
URL: https://github.com/apache/trafficcontrol/pull/4916#discussion_r466568464
##########
File path: traffic_monitor/health/cache.go
##########
@@ -144,177 +191,151 @@ func EvalCache(result cache.ResultInfo, resultStats
*threadsafe.ResultStatValHis
}
if !inThreshold(threshold, resultStatNum) {
- return false, result.UsingIPv4, eventDesc(status,
exceedsThresholdMsg(stat, threshold, resultStatNum)), stat
+ return false, eventDesc(status,
exceedsThresholdMsg(stat, threshold, resultStatNum)), stat
}
}
- return avail, result.UsingIPv4, eventDescVal, eventMsg
+ return avail, eventDescVal, eventMsg
}
-// CalcAvailabilityWithStats calculates the availability of each cache in
results.
-// statResultHistory may be nil, in which case stats won't be used to
calculate availability.
-func CalcAvailability(results []cache.Result, pollerName string,
statResultHistory *threadsafe.ResultStatHistory, mc
tc.LegacyTrafficMonitorConfigMap, toData todata.TOData,
localCacheStatusThreadsafe threadsafe.CacheAvailableStatus, localStates
peer.CRStatesThreadsafe, events ThreadsafeEvents, protocol
config.PollingProtocol) {
- localCacheStatuses := localCacheStatusThreadsafe.Get().Copy()
- statResults := (*threadsafe.ResultStatValHistory)(nil)
- statResultsVal := (*map[string]threadsafe.ResultStatValHistory)(nil)
- processAvailableTuple := func(tuple cache.AvailableTuple, serverInfo
tc.LegacyTrafficServer) bool {
- switch protocol {
- case config.IPv4Only:
+// gets a function to process an availability tuple based on the protocol used.
+func getProcessAvailableTuple(protocol config.PollingProtocol)
func(cache.AvailableTuple, tc.TrafficServer) bool {
+ switch protocol {
+ case config.IPv4Only:
+ return func(tuple cache.AvailableTuple, _ tc.TrafficServer)
bool {
return tuple.IPv4
- case config.IPv6Only:
+ }
+ case config.IPv6Only:
+ return func(tuple cache.AvailableTuple, _ tc.TrafficServer)
bool {
return tuple.IPv6
- case config.Both:
- // only report availability based on defined IP
addresses
- if serverInfo.IP == "" {
+ }
+ case config.Both:
+ return func(tuple cache.AvailableTuple, serverInfo
tc.TrafficServer) bool {
+ if serverInfo.IPv4() == "" {
return tuple.IPv6
- } else if serverInfo.IP6 == "" {
+ } else if serverInfo.IPv6() == "" {
return tuple.IPv4
}
- // if both IP addresses are defined then report
availability based on both
return tuple.IPv4 || tuple.IPv6
- default:
- log.Errorln("received an unknown PollingProtocol: " +
protocol.String())
}
- return false
+ default:
+ log.Errorf("received an unknown Polling Protocol: %s", protocol)
}
+ return func(cache.AvailableTuple, tc.TrafficServer) bool { return false
}
+}
+
+// CalcAvailability calculates the availability of each cache in results.
+// statResultHistory may be nil, in which case stats won't be used to calculate
+// availability.
+func CalcAvailability(
+ results []cache.Result,
+ pollerName string,
+ statResultHistory *threadsafe.ResultStatHistory,
+ mc tc.TrafficMonitorConfigMap,
+ toData todata.TOData,
+ localCacheStatusThreadsafe threadsafe.CacheAvailableStatus,
+ localStates peer.CRStatesThreadsafe,
+ events ThreadsafeEvents,
+ protocol config.PollingProtocol,
+) {
+ localCacheStatuses := localCacheStatusThreadsafe.Get().Copy()
+ var statResultsVal *threadsafe.CacheStatHistory
+ processAvailableTuple := getProcessAvailableTuple(protocol)
for _, result := range results {
if statResultHistory != nil {
- t :=
statResultHistory.LoadOrStore(tc.CacheName(result.ID))
+ t := statResultHistory.LoadOrStore(result.ID)
statResultsVal = &t
}
serverInfo, ok := mc.TrafficServer[result.ID]
if !ok {
log.Errorf("Cache %v missing from from Traffic Ops
Monitor Config - treating as OFFLINE\n", result.ID)
}
- if _, ok := localCacheStatuses[tc.CacheName(result.ID)]; !ok {
- localCacheStatuses[tc.CacheName(result.ID)] =
make(map[string]cache.AvailableStatus)
+ availStatus := cache.AvailableStatus{
+ Available: cache.AvailableTuple{
+ IPv4: result.UsingIPv4,
Review comment:
You'd know better than me, I was never clear on how that's supposed to
work.
----------------------------------------------------------------
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]