Fix TM2 symbol names to be idiomatic
Project: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/commit/32358a6a Tree: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/tree/32358a6a Diff: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/diff/32358a6a Branch: refs/heads/master Commit: 32358a6a77380c2175beedbe3a2eba79f3f1b3c0 Parents: 95ab789 Author: Robert Butts <robert.o.bu...@gmail.com> Authored: Thu Oct 20 15:57:05 2016 -0600 Committer: Jeremy Mitchell <mitchell...@gmail.com> Committed: Fri Oct 28 15:04:12 2016 -0600 ---------------------------------------------------------------------- .../experimental/traffic_monitor/cache/cache.go | 32 +++++------ .../traffic_monitor/config/config.go | 14 ++--- .../traffic_monitor/health/cache_health.go | 10 ++-- .../traffic_monitor/manager/datarequest.go | 10 ++-- .../traffic_monitor/manager/healthresult.go | 20 +++---- .../traffic_monitor/manager/manager.go | 2 +- .../traffic_monitor/manager/monitorconfig.go | 24 ++++----- .../traffic_monitor/manager/peer.go | 2 +- .../traffic_monitor/manager/polledcaches.go | 2 +- .../traffic_monitor/manager/stathistory.go | 24 ++++----- .../traffic_monitor/peer/crstates.go | 56 ++++++++++---------- .../experimental/traffic_monitor/peer/peer.go | 8 +-- 12 files changed, 102 insertions(+), 102 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/32358a6a/traffic_monitor/experimental/traffic_monitor/cache/cache.go ---------------------------------------------------------------------- diff --git a/traffic_monitor/experimental/traffic_monitor/cache/cache.go b/traffic_monitor/experimental/traffic_monitor/cache/cache.go index 20eb2a5..f679cf5 100644 --- a/traffic_monitor/experimental/traffic_monitor/cache/cache.go +++ b/traffic_monitor/experimental/traffic_monitor/cache/cache.go @@ -6,8 +6,8 @@ import ( "github.com/apache/incubator-trafficcontrol/traffic_monitor/experimental/common/log" dsdata "github.com/apache/incubator-trafficcontrol/traffic_monitor/experimental/traffic_monitor/deliveryservicedata" "github.com/apache/incubator-trafficcontrol/traffic_monitor/experimental/traffic_monitor/enum" - "github.com/apache/incubator-trafficcontrol/traffic_monitor/experimental/traffic_monitor/srvhttp" "github.com/apache/incubator-trafficcontrol/traffic_monitor/experimental/traffic_monitor/peer" + "github.com/apache/incubator-trafficcontrol/traffic_monitor/experimental/traffic_monitor/srvhttp" todata "github.com/apache/incubator-trafficcontrol/traffic_monitor/experimental/traffic_monitor/trafficopsdata" "io" "net/url" @@ -35,8 +35,8 @@ func NewPrecomputeHandler(toData todata.TODataThreadsafe, peerStates peer.CRStat return Handler{ResultChannel: make(chan Result), MultipleSpaceRegex: regexp.MustCompile(" +"), ToData: &toData, PeerStates: &peerStates} } -func (h Handler) Precompute() bool { - return h.ToData != nil && h.PeerStates != nil +func (handler Handler) Precompute() bool { + return handler.ToData != nil && handler.PeerStates != nil } type PrecomputedData struct { @@ -48,7 +48,7 @@ type PrecomputedData struct { } type Result struct { - Id enum.CacheName + ID enum.CacheName Available bool Error error Astats Astats @@ -126,12 +126,12 @@ func StatsMarshall(statHistory map[enum.CacheName][]Result, filter Filter, param return json.Marshal(stats) } -func (handler Handler) Handle(id string, r io.Reader, err error, pollId uint64, pollFinished chan<- uint64) { - log.Debugf("poll %v %v handle start\n", pollId, time.Now()) +func (handler Handler) Handle(id string, r io.Reader, err error, pollID uint64, pollFinished chan<- uint64) { + log.Debugf("poll %v %v handle start\n", pollID, time.Now()) result := Result{ - Id: enum.CacheName(id), + ID: enum.CacheName(id), Time: time.Now(), // TODO change this to be computed the instant we get the result back, to minimise inaccuracy - PollID: pollId, + PollID: pollID, PollFinished: pollFinished, } @@ -166,7 +166,7 @@ func (handler Handler) Handle(id string, r io.Reader, err error, pollId uint64, log.Warnf("addkbps %s inf.speed empty\n", id) } - log.Debugf("poll %v %v handle decode end\n", pollId, time.Now()) + log.Debugf("poll %v %v handle decode end\n", pollID, time.Now()) if err != nil { result.Error = err @@ -176,13 +176,13 @@ func (handler Handler) Handle(id string, r io.Reader, err error, pollId uint64, } if handler.Precompute() { - log.Debugf("poll %v %v handle precompute start\n", pollId, time.Now()) + log.Debugf("poll %v %v handle precompute start\n", pollID, time.Now()) result = handler.precompute(result) - log.Debugf("poll %v %v handle precompute end\n", pollId, time.Now()) + log.Debugf("poll %v %v handle precompute end\n", pollID, time.Now()) } - log.Debugf("poll %v %v handle write start\n", pollId, time.Now()) + log.Debugf("poll %v %v handle write start\n", pollID, time.Now()) handler.ResultChannel <- result - log.Debugf("poll %v %v handle end\n", pollId, time.Now()) + log.Debugf("poll %v %v handle end\n", pollID, time.Now()) } // outBytes takes the proc.net.dev string, and the interface name, and returns the bytes field @@ -218,7 +218,7 @@ func (handler Handler) precompute(result Result) Result { var err error if result.PrecomputedData.OutBytes, err = outBytes(result.Astats.System.ProcNetDev, result.Astats.System.InfName, handler.MultipleSpaceRegex); err != nil { result.PrecomputedData.OutBytes = 0 - log.Errorf("addkbps %s handle precomputing outbytes '%v'\n", result.Id, err) + log.Errorf("addkbps %s handle precomputing outbytes '%v'\n", result.ID, err) } kbpsInMbps := int64(1000) @@ -226,9 +226,9 @@ func (handler Handler) precompute(result Result) Result { for stat, value := range result.Astats.Ats { var err error - stats, err = processStat(result.Id, stats, todata, stat, value, result.Time) + stats, err = processStat(result.ID, stats, todata, stat, value, result.Time) if err != nil && err != dsdata.ErrNotProcessedStat { - log.Errorf("precomputing cache %v stat %v value %v error %v", result.Id, stat, value, err) + log.Errorf("precomputing cache %v stat %v value %v error %v", result.ID, stat, value, err) result.PrecomputedData.Errors = append(result.PrecomputedData.Errors, err) } } http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/32358a6a/traffic_monitor/experimental/traffic_monitor/config/config.go ---------------------------------------------------------------------- diff --git a/traffic_monitor/experimental/traffic_monitor/config/config.go b/traffic_monitor/experimental/traffic_monitor/config/config.go index 316651a..f8bbe30 100644 --- a/traffic_monitor/experimental/traffic_monitor/config/config.go +++ b/traffic_monitor/experimental/traffic_monitor/config/config.go @@ -16,7 +16,7 @@ type Config struct { CacheHealthPollingInterval time.Duration `json:"-"` CacheStatPollingInterval time.Duration `json:"-"` MonitorConfigPollingInterval time.Duration `json:"-"` - HttpTimeout time.Duration `json:"-"` + HTTPTimeout time.Duration `json:"-"` PeerPollingInterval time.Duration `json:"-"` MaxEvents uint64 `json:"max_events"` MaxStatHistory uint64 `json:"max_stat_history"` @@ -35,7 +35,7 @@ var DefaultConfig = Config{ CacheHealthPollingInterval: 6 * time.Second, CacheStatPollingInterval: 6 * time.Second, MonitorConfigPollingInterval: 5 * time.Second, - HttpTimeout: 2 * time.Second, + HTTPTimeout: 2 * time.Second, PeerPollingInterval: 5 * time.Second, MaxEvents: 200, MaxStatHistory: 5, @@ -57,7 +57,7 @@ func (c *Config) MarshalJSON() ([]byte, error) { CacheHealthPollingIntervalMs uint64 `json:"cache_health_polling_interval_ms"` CacheStatPollingIntervalMs uint64 `json:"cache_stat_polling_interval_ms"` MonitorConfigPollingIntervalMs uint64 `json:"monitor_config_polling_interval_ms"` - HttpTimeoutMs uint64 `json:"http_timeout_ms"` + HTTPTimeoutMS uint64 `json:"http_timeout_ms"` PeerPollingIntervalMs uint64 `json:"peer_polling_interval_ms"` HealthFlushIntervalMs uint64 `json:"health_flush_interval_ms"` StatFlushIntervalMs uint64 `json:"stat_flush_interval_ms"` @@ -68,7 +68,7 @@ func (c *Config) MarshalJSON() ([]byte, error) { CacheHealthPollingIntervalMs: uint64(c.CacheHealthPollingInterval / time.Millisecond), CacheStatPollingIntervalMs: uint64(c.CacheStatPollingInterval / time.Millisecond), MonitorConfigPollingIntervalMs: uint64(c.MonitorConfigPollingInterval / time.Millisecond), - HttpTimeoutMs: uint64(c.HttpTimeout / time.Millisecond), + HTTPTimeoutMS: uint64(c.HTTPTimeout / time.Millisecond), PeerPollingIntervalMs: uint64(c.PeerPollingInterval / time.Millisecond), HealthFlushIntervalMs: uint64(c.HealthFlushInterval / time.Millisecond), StatFlushIntervalMs: uint64(c.StatFlushInterval / time.Millisecond), @@ -82,7 +82,7 @@ func (c *Config) UnmarshalJSON(data []byte) error { CacheHealthPollingIntervalMs *uint64 `json:"cache_health_polling_interval_ms"` CacheStatPollingIntervalMs *uint64 `json:"cache_stat_polling_interval_ms"` MonitorConfigPollingIntervalMs *uint64 `json:"monitor_config_polling_interval_ms"` - HttpTimeoutMs *uint64 `json:"http_timeout_ms"` + HTTPTimeoutMS *uint64 `json:"http_timeout_ms"` PeerPollingIntervalMs *uint64 `json:"peer_polling_interval_ms"` HealthFlushIntervalMs *uint64 `json:"health_flush_interval_ms"` StatFlushIntervalMs *uint64 `json:"stat_flush_interval_ms"` @@ -105,8 +105,8 @@ func (c *Config) UnmarshalJSON(data []byte) error { if aux.MonitorConfigPollingIntervalMs != nil { c.MonitorConfigPollingInterval = time.Duration(*aux.MonitorConfigPollingIntervalMs) * time.Millisecond } - if aux.HttpTimeoutMs != nil { - c.HttpTimeout = time.Duration(*aux.HttpTimeoutMs) * time.Millisecond + if aux.HTTPTimeoutMS != nil { + c.HTTPTimeout = time.Duration(*aux.HTTPTimeoutMS) * time.Millisecond } if aux.PeerPollingIntervalMs != nil { c.PeerPollingInterval = time.Duration(*aux.PeerPollingIntervalMs) * time.Millisecond http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/32358a6a/traffic_monitor/experimental/traffic_monitor/health/cache_health.go ---------------------------------------------------------------------- diff --git a/traffic_monitor/experimental/traffic_monitor/health/cache_health.go b/traffic_monitor/experimental/traffic_monitor/health/cache_health.go index cf1acff..11e746e 100644 --- a/traffic_monitor/experimental/traffic_monitor/health/cache_health.go +++ b/traffic_monitor/experimental/traffic_monitor/health/cache_health.go @@ -32,7 +32,7 @@ func GetVitals(newResult *cache.Result, prevResult *cache.Result, mc *traffic_op } newResult.Vitals.LoadAvg = oneMinAvg } else { - setError(newResult, fmt.Errorf("Can't make sense of '%s' as a load average for %s", newResult.Astats.System.ProcLoadavg, newResult.Id)) + setError(newResult, fmt.Errorf("Can't make sense of '%s' as a load average for %s", newResult.Astats.System.ProcLoadavg, newResult.ID)) return } @@ -68,14 +68,14 @@ func GetVitals(newResult *cache.Result, prevResult *cache.Result, mc *traffic_op // inf.speed -- value looks like "10000" (without the quotes) so it is in Mbps. // TODO JvD: Should we really be running this code every second for every cache polled????? I don't think so. interfaceBandwidth := newResult.Astats.System.InfSpeed - newResult.Vitals.MaxKbpsOut = int64(interfaceBandwidth)*1000 - mc.Profile[mc.TrafficServer[string(newResult.Id)].Profile].Parameters.MinFreeKbps + newResult.Vitals.MaxKbpsOut = int64(interfaceBandwidth)*1000 - mc.Profile[mc.TrafficServer[string(newResult.ID)].Profile].Parameters.MinFreeKbps // log.Infoln(newResult.Id, "BytesOut", newResult.Vitals.BytesOut, "BytesIn", newResult.Vitals.BytesIn, "Kbps", newResult.Vitals.KbpsOut, "max", newResult.Vitals.MaxKbpsOut) } // EvalCache returns whether the given cache should be marked available, and a string describing why func EvalCache(result cache.Result, mc *traffic_ops.TrafficMonitorConfigMap) (bool, string) { - status := mc.TrafficServer[string(result.Id)].Status + status := mc.TrafficServer[string(result.ID)].Status switch { case status == "ADMIN_DOWN": return false, "set to ADMIN_DOWN" @@ -85,8 +85,8 @@ func EvalCache(result cache.Result, mc *traffic_ops.TrafficMonitorConfigMap) (bo return true, "set to ONLINE" case result.Error != nil: return false, fmt.Sprintf("error: %v", result.Error) - case result.Vitals.LoadAvg > mc.Profile[mc.TrafficServer[string(result.Id)].Profile].Parameters.HealthThresholdLoadAvg: - return false, fmt.Sprintf("load average %f exceeds threshold %f", result.Vitals.LoadAvg, mc.Profile[mc.TrafficServer[string(result.Id)].Profile].Parameters.HealthThresholdLoadAvg) + case result.Vitals.LoadAvg > mc.Profile[mc.TrafficServer[string(result.ID)].Profile].Parameters.HealthThresholdLoadAvg: + return false, fmt.Sprintf("load average %f exceeds threshold %f", result.Vitals.LoadAvg, mc.Profile[mc.TrafficServer[string(result.ID)].Profile].Parameters.HealthThresholdLoadAvg) case result.Vitals.MaxKbpsOut < result.Vitals.KbpsOut: return false, fmt.Sprintf("%dkbps exceeds max %dkbps", result.Vitals.KbpsOut, result.Vitals.MaxKbpsOut) default: http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/32358a6a/traffic_monitor/experimental/traffic_monitor/manager/datarequest.go ---------------------------------------------------------------------- diff --git a/traffic_monitor/experimental/traffic_monitor/manager/datarequest.go b/traffic_monitor/experimental/traffic_monitor/manager/datarequest.go index 52d2d17..e754f89 100644 --- a/traffic_monitor/experimental/traffic_monitor/manager/datarequest.go +++ b/traffic_monitor/experimental/traffic_monitor/manager/datarequest.go @@ -16,8 +16,8 @@ import ( ds "github.com/apache/incubator-trafficcontrol/traffic_monitor/experimental/traffic_monitor/deliveryservice" dsdata "github.com/apache/incubator-trafficcontrol/traffic_monitor/experimental/traffic_monitor/deliveryservicedata" "github.com/apache/incubator-trafficcontrol/traffic_monitor/experimental/traffic_monitor/enum" - "github.com/apache/incubator-trafficcontrol/traffic_monitor/experimental/traffic_monitor/srvhttp" "github.com/apache/incubator-trafficcontrol/traffic_monitor/experimental/traffic_monitor/peer" + "github.com/apache/incubator-trafficcontrol/traffic_monitor/experimental/traffic_monitor/srvhttp" todata "github.com/apache/incubator-trafficcontrol/traffic_monitor/experimental/traffic_monitor/trafficopsdata" towrap "github.com/apache/incubator-trafficcontrol/traffic_monitor/experimental/traffic_monitor/trafficopswrapper" ) @@ -30,7 +30,7 @@ type CacheState struct { Value bool `json:"value"` } -type ApiPeerStates struct { +type APIPeerStates struct { srvhttp.CommonAPIData Peers map[enum.TrafficMonitorName]map[enum.CacheName][]CacheState `json:"peers"` } @@ -487,7 +487,7 @@ func DataRequest( return []byte(err.Error()), http.StatusBadRequest } - body, err = json.Marshal(createApiPeerStates(peerStates.Get(), filter, req.Parameters)) + body, err = json.Marshal(createAPIPeerStates(peerStates.Get(), filter, req.Parameters)) return commonReturn(body, err) case srvhttp.StatSummary: return nil, http.StatusNotImplemented @@ -671,8 +671,8 @@ func cacheAvailableCount(caches map[enum.CacheName]peer.IsAvailable) int { return len(caches) - cacheDownCount(caches) } -func createApiPeerStates(peerStates map[enum.TrafficMonitorName]peer.Crstates, filter *PeerStateFilter, params url.Values) ApiPeerStates { - apiPeerStates := ApiPeerStates{ +func createAPIPeerStates(peerStates map[enum.TrafficMonitorName]peer.Crstates, filter *PeerStateFilter, params url.Values) APIPeerStates { + apiPeerStates := APIPeerStates{ CommonAPIData: srvhttp.GetCommonAPIData(params, time.Now()), Peers: map[enum.TrafficMonitorName]map[enum.CacheName][]CacheState{}, } http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/32358a6a/traffic_monitor/experimental/traffic_monitor/manager/healthresult.go ---------------------------------------------------------------------- diff --git a/traffic_monitor/experimental/traffic_monitor/manager/healthresult.go b/traffic_monitor/experimental/traffic_monitor/manager/healthresult.go index dda4d27..5074f26 100644 --- a/traffic_monitor/experimental/traffic_monitor/manager/healthresult.go +++ b/traffic_monitor/experimental/traffic_monitor/manager/healthresult.go @@ -189,7 +189,7 @@ func processHealthResult( log.Debugf("poll %v %v healthresultman start\n", healthResult.PollID, time.Now()) fetchCount.Inc() var prevResult cache.Result - healthResultHistory := healthHistory[enum.CacheName(healthResult.Id)] + healthResultHistory := healthHistory[enum.CacheName(healthResult.ID)] if len(healthResultHistory) != 0 { prevResult = healthResultHistory[len(healthResultHistory)-1] } @@ -198,16 +198,16 @@ func processHealthResult( health.GetVitals(&healthResult, &prevResult, &monitorConfigCopy) } - healthHistory[enum.CacheName(healthResult.Id)] = pruneHistory(append(healthHistory[enum.CacheName(healthResult.Id)], healthResult), cfg.MaxHealthHistory) + healthHistory[enum.CacheName(healthResult.ID)] = pruneHistory(append(healthHistory[enum.CacheName(healthResult.ID)], healthResult), cfg.MaxHealthHistory) isAvailable, whyAvailable := health.EvalCache(healthResult, &monitorConfigCopy) - if localStates.Get().Caches[healthResult.Id].IsAvailable != isAvailable { - log.Infof("Changing state for %s was: %t now: %t because %s error: %v", healthResult.Id, prevResult.Available, isAvailable, whyAvailable, healthResult.Error) - events.Add(Event{Time: time.Now().Unix(), Description: whyAvailable, Name: healthResult.Id, Hostname: healthResult.Id, Type: toDataCopy.ServerTypes[healthResult.Id].String(), Available: isAvailable}) + if localStates.Get().Caches[healthResult.ID].IsAvailable != isAvailable { + log.Infof("Changing state for %s was: %t now: %t because %s error: %v", healthResult.ID, prevResult.Available, isAvailable, whyAvailable, healthResult.Error) + events.Add(Event{Time: time.Now().Unix(), Description: whyAvailable, Name: healthResult.ID, Hostname: healthResult.ID, Type: toDataCopy.ServerTypes[healthResult.ID].String(), Available: isAvailable}) } - localCacheStatus[healthResult.Id] = CacheAvailableStatus{Available: isAvailable, Status: monitorConfigCopy.TrafficServer[string(healthResult.Id)].Status} // TODO move within localStates? - localStates.SetCache(healthResult.Id, peer.IsAvailable{IsAvailable: isAvailable}) + localCacheStatus[healthResult.ID] = CacheAvailableStatus{Available: isAvailable, Status: monitorConfigCopy.TrafficServer[string(healthResult.ID)].Status} // TODO move within localStates? + localStates.SetCache(healthResult.ID, peer.IsAvailable{IsAvailable: isAvailable}) log.Debugf("poll %v %v calculateDeliveryServiceState start\n", healthResult.PollID, time.Now()) calculateDeliveryServiceState(toDataCopy.DeliveryServiceServers, localStates) log.Debugf("poll %v %v calculateDeliveryServiceState end\n", healthResult.PollID, time.Now()) @@ -217,11 +217,11 @@ func processHealthResult( lastHealthDurations := lastHealthDurationsThreadsafe.Get().Copy() for _, healthResult := range results { - if lastHealthStart, ok := lastHealthEndTimes[enum.CacheName(healthResult.Id)]; ok { + if lastHealthStart, ok := lastHealthEndTimes[enum.CacheName(healthResult.ID)]; ok { d := time.Since(lastHealthStart) - lastHealthDurations[enum.CacheName(healthResult.Id)] = d + lastHealthDurations[enum.CacheName(healthResult.ID)] = d } - lastHealthEndTimes[enum.CacheName(healthResult.Id)] = time.Now() + lastHealthEndTimes[enum.CacheName(healthResult.ID)] = time.Now() log.Debugf("poll %v %v finish\n", healthResult.PollID, time.Now()) healthResult.PollFinished <- healthResult.PollID http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/32358a6a/traffic_monitor/experimental/traffic_monitor/manager/manager.go ---------------------------------------------------------------------- diff --git a/traffic_monitor/experimental/traffic_monitor/manager/manager.go b/traffic_monitor/experimental/traffic_monitor/manager/manager.go index fe87d90..ea4b106 100644 --- a/traffic_monitor/experimental/traffic_monitor/manager/manager.go +++ b/traffic_monitor/experimental/traffic_monitor/manager/manager.go @@ -41,7 +41,7 @@ func Start(opsConfigFile string, cfg config.Config, staticAppData StaticAppData) // TODO investigate whether a unique client per cache to be polled is faster sharedClient := &http.Client{ - Timeout: cfg.HttpTimeout, + Timeout: cfg.HTTPTimeout, Transport: &http.Transport{TLSClientConfig: &tls.Config{InsecureSkipVerify: true}}, } http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/32358a6a/traffic_monitor/experimental/traffic_monitor/manager/monitorconfig.go ---------------------------------------------------------------------- diff --git a/traffic_monitor/experimental/traffic_monitor/manager/monitorconfig.go b/traffic_monitor/experimental/traffic_monitor/manager/monitorconfig.go index 2e39771..fa24f04 100644 --- a/traffic_monitor/experimental/traffic_monitor/manager/monitorconfig.go +++ b/traffic_monitor/experimental/traffic_monitor/manager/monitorconfig.go @@ -67,9 +67,9 @@ func (t *TrafficMonitorConfigMapThreadsafe) Set(c to.TrafficMonitorConfigMap) { func StartMonitorConfigManager( monitorConfigPollChan <-chan to.TrafficMonitorConfigMap, localStates peer.CRStatesThreadsafe, - statUrlSubscriber chan<- poller.HttpPollerConfig, - healthUrlSubscriber chan<- poller.HttpPollerConfig, - peerUrlSubscriber chan<- poller.HttpPollerConfig, + statURLSubscriber chan<- poller.HttpPollerConfig, + healthURLSubscriber chan<- poller.HttpPollerConfig, + peerURLSubscriber chan<- poller.HttpPollerConfig, cachesChangeSubscriber chan<- struct{}, cfg config.Config, staticAppData StaticAppData, @@ -78,9 +78,9 @@ func StartMonitorConfigManager( go monitorConfigListen(monitorConfig, monitorConfigPollChan, localStates, - statUrlSubscriber, - healthUrlSubscriber, - peerUrlSubscriber, + statURLSubscriber, + healthURLSubscriber, + peerURLSubscriber, cachesChangeSubscriber, cfg, staticAppData, @@ -94,9 +94,9 @@ func monitorConfigListen( monitorConfigTS TrafficMonitorConfigMapThreadsafe, monitorConfigPollChan <-chan to.TrafficMonitorConfigMap, localStates peer.CRStatesThreadsafe, - statUrlSubscriber chan<- poller.HttpPollerConfig, - healthUrlSubscriber chan<- poller.HttpPollerConfig, - peerUrlSubscriber chan<- poller.HttpPollerConfig, + statURLSubscriber chan<- poller.HttpPollerConfig, + healthURLSubscriber chan<- poller.HttpPollerConfig, + peerURLSubscriber chan<- poller.HttpPollerConfig, cachesChangeSubscriber chan<- struct{}, cfg config.Config, staticAppData StaticAppData, @@ -152,9 +152,9 @@ func monitorConfigListen( peerUrls[srv.HostName] = url } - statUrlSubscriber <- poller.HttpPollerConfig{Urls: statUrls, Interval: cfg.CacheStatPollingInterval} - healthUrlSubscriber <- poller.HttpPollerConfig{Urls: healthUrls, Interval: cfg.CacheHealthPollingInterval} - peerUrlSubscriber <- poller.HttpPollerConfig{Urls: peerUrls, Interval: cfg.PeerPollingInterval} + statURLSubscriber <- poller.HttpPollerConfig{Urls: statUrls, Interval: cfg.CacheStatPollingInterval} + healthURLSubscriber <- poller.HttpPollerConfig{Urls: healthUrls, Interval: cfg.CacheHealthPollingInterval} + peerURLSubscriber <- poller.HttpPollerConfig{Urls: peerUrls, Interval: cfg.PeerPollingInterval} for cacheName := range localStates.GetCaches() { if _, exists := monitorConfig.TrafficServer[string(cacheName)]; !exists { http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/32358a6a/traffic_monitor/experimental/traffic_monitor/manager/peer.go ---------------------------------------------------------------------- diff --git a/traffic_monitor/experimental/traffic_monitor/manager/peer.go b/traffic_monitor/experimental/traffic_monitor/manager/peer.go index 111ffc6..2bca917 100644 --- a/traffic_monitor/experimental/traffic_monitor/manager/peer.go +++ b/traffic_monitor/experimental/traffic_monitor/manager/peer.go @@ -17,7 +17,7 @@ func StartPeerManager( combinedStates := peer.NewCRStatesThreadsafe() go func() { for crStatesResult := range peerChan { - peerStates.Set(crStatesResult.Id, crStatesResult.PeerStats) + peerStates.Set(crStatesResult.ID, crStatesResult.PeerStats) combinedStates.Set(combineCrStates(peerStates.Get(), localStates.Get())) crStatesResult.PollFinished <- crStatesResult.PollID } http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/32358a6a/traffic_monitor/experimental/traffic_monitor/manager/polledcaches.go ---------------------------------------------------------------------- diff --git a/traffic_monitor/experimental/traffic_monitor/manager/polledcaches.go b/traffic_monitor/experimental/traffic_monitor/manager/polledcaches.go index 48e4f71..9b66a8d 100644 --- a/traffic_monitor/experimental/traffic_monitor/manager/polledcaches.go +++ b/traffic_monitor/experimental/traffic_monitor/manager/polledcaches.go @@ -96,7 +96,7 @@ func (t *UnpolledCachesThreadsafe) SetPolled(results []cache.Result, lastStatsTh for cache, _ := range unpolledCaches { innerLoop: for _, result := range results { - if result.Id != cache { + if result.ID != cache { continue } if !result.Available || len(result.Errors) > 0 { http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/32358a6a/traffic_monitor/experimental/traffic_monitor/manager/stathistory.go ---------------------------------------------------------------------- diff --git a/traffic_monitor/experimental/traffic_monitor/manager/stathistory.go b/traffic_monitor/experimental/traffic_monitor/manager/stathistory.go index 9cf0fdc..ac1c7a6 100644 --- a/traffic_monitor/experimental/traffic_monitor/manager/stathistory.go +++ b/traffic_monitor/experimental/traffic_monitor/manager/stathistory.go @@ -47,17 +47,17 @@ func NewStatHistoryThreadsafe(maxHistory uint64) StatHistoryThreadsafe { } // Get returns the StatHistory. Callers MUST NOT modify. If mutation is necessary, call StatHistory.Copy() -func (t *StatHistoryThreadsafe) Get() StatHistory { - t.m.RLock() - defer t.m.RUnlock() - return *t.statHistory +func (h *StatHistoryThreadsafe) Get() StatHistory { + h.m.RLock() + defer h.m.RUnlock() + return *h.statHistory } // Set sets the internal StatHistory. This is only safe for one thread of execution. This MUST NOT be called from multiple threads. -func (t *StatHistoryThreadsafe) Set(v StatHistory) { - t.m.Lock() - *t.statHistory = v - t.m.Unlock() +func (h *StatHistoryThreadsafe) Set(v StatHistory) { + h.m.Lock() + *h.statHistory = v + h.m.Unlock() } func pruneHistory(history []cache.Result, limit uint64) []cache.Result { @@ -151,7 +151,7 @@ func processStatResults( maxStats := statHistoryThreadsafe.Max() for _, result := range results { // TODO determine if we want to add results with errors, or just print the errors now and don't add them. - statHistory[enum.CacheName(result.Id)] = pruneHistory(append(statHistory[enum.CacheName(result.Id)], result), maxStats) + statHistory[enum.CacheName(result.ID)] = pruneHistory(append(statHistory[enum.CacheName(result.ID)], result), maxStats) } statHistoryThreadsafe.Set(statHistory) @@ -176,11 +176,11 @@ func processStatResults( endTime := time.Now() lastStatDurations := lastStatDurationsThreadsafe.Get().Copy() for _, result := range results { - if lastStatStart, ok := lastStatEndTimes[enum.CacheName(result.Id)]; ok { + if lastStatStart, ok := lastStatEndTimes[enum.CacheName(result.ID)]; ok { d := time.Since(lastStatStart) - lastStatDurations[enum.CacheName(result.Id)] = d + lastStatDurations[enum.CacheName(result.ID)] = d } - lastStatEndTimes[enum.CacheName(result.Id)] = endTime + lastStatEndTimes[enum.CacheName(result.ID)] = endTime // log.Debugf("poll %v %v statfinish\n", result.PollID, endTime) result.PollFinished <- result.PollID http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/32358a6a/traffic_monitor/experimental/traffic_monitor/peer/crstates.go ---------------------------------------------------------------------- diff --git a/traffic_monitor/experimental/traffic_monitor/peer/crstates.go b/traffic_monitor/experimental/traffic_monitor/peer/crstates.go index 6f4bda7..1aaf314 100644 --- a/traffic_monitor/experimental/traffic_monitor/peer/crstates.go +++ b/traffic_monitor/experimental/traffic_monitor/peer/crstates.go @@ -110,40 +110,40 @@ func (t *CRStatesThreadsafe) GetDeliveryService(name enum.DeliveryServiceName) D return t.crStates.Deliveryservice[name] } -func (o *CRStatesThreadsafe) Set(newCRStates Crstates) { - o.m.Lock() - *o.crStates = newCRStates - o.m.Unlock() +func (t *CRStatesThreadsafe) Set(newCRStates Crstates) { + t.m.Lock() + *t.crStates = newCRStates + t.m.Unlock() } -func (o *CRStatesThreadsafe) SetCache(cacheName enum.CacheName, available IsAvailable) { - o.m.Lock() - o.crStates.Caches[cacheName] = available - o.m.Unlock() +func (t *CRStatesThreadsafe) SetCache(cacheName enum.CacheName, available IsAvailable) { + t.m.Lock() + t.crStates.Caches[cacheName] = available + t.m.Unlock() } -func (o *CRStatesThreadsafe) DeleteCache(name enum.CacheName) { - o.m.Lock() - delete(o.crStates.Caches, name) - o.m.Unlock() +func (t *CRStatesThreadsafe) DeleteCache(name enum.CacheName) { + t.m.Lock() + delete(t.crStates.Caches, name) + t.m.Unlock() } -func (o *CRStatesThreadsafe) SetDeliveryService(name enum.DeliveryServiceName, ds Deliveryservice) { - o.m.Lock() - o.crStates.Deliveryservice[name] = ds - o.m.Unlock() +func (t *CRStatesThreadsafe) SetDeliveryService(name enum.DeliveryServiceName, ds Deliveryservice) { + t.m.Lock() + t.crStates.Deliveryservice[name] = ds + t.m.Unlock() } -func (o *CRStatesThreadsafe) SetDeliveryServices(deliveryServices map[enum.DeliveryServiceName]Deliveryservice) { - o.m.Lock() - o.crStates.Deliveryservice = deliveryServices - o.m.Unlock() +func (t *CRStatesThreadsafe) SetDeliveryServices(deliveryServices map[enum.DeliveryServiceName]Deliveryservice) { + t.m.Lock() + t.crStates.Deliveryservice = deliveryServices + t.m.Unlock() } -func (o *CRStatesThreadsafe) DeleteDeliveryService(name enum.DeliveryServiceName) { - o.m.Lock() - delete(o.crStates.Deliveryservice, name) - o.m.Unlock() +func (t *CRStatesThreadsafe) DeleteDeliveryService(name enum.DeliveryServiceName) { + t.m.Lock() + delete(t.crStates.Deliveryservice, name) + t.m.Unlock() } // This could be made lock-free, if the performance was necessary @@ -166,8 +166,8 @@ func (t *CRStatesPeersThreadsafe) Get() map[enum.TrafficMonitorName]Crstates { return m } -func (o *CRStatesPeersThreadsafe) Set(peerName enum.TrafficMonitorName, peerState Crstates) { - o.m.Lock() - o.crStates[peerName] = peerState - o.m.Unlock() +func (t *CRStatesPeersThreadsafe) Set(peerName enum.TrafficMonitorName, peerState Crstates) { + t.m.Lock() + t.crStates[peerName] = peerState + t.m.Unlock() } http://git-wip-us.apache.org/repos/asf/incubator-trafficcontrol/blob/32358a6a/traffic_monitor/experimental/traffic_monitor/peer/peer.go ---------------------------------------------------------------------- diff --git a/traffic_monitor/experimental/traffic_monitor/peer/peer.go b/traffic_monitor/experimental/traffic_monitor/peer/peer.go index f1788d9..ae898eb 100644 --- a/traffic_monitor/experimental/traffic_monitor/peer/peer.go +++ b/traffic_monitor/experimental/traffic_monitor/peer/peer.go @@ -17,7 +17,7 @@ func NewHandler() Handler { } type Result struct { - Id enum.TrafficMonitorName + ID enum.TrafficMonitorName Available bool Errors []error PeerStats Crstates @@ -25,12 +25,12 @@ type Result struct { PollFinished chan<- uint64 } -func (handler Handler) Handle(id string, r io.Reader, err error, pollId uint64, pollFinished chan<- uint64) { +func (handler Handler) Handle(id string, r io.Reader, err error, pollID uint64, pollFinished chan<- uint64) { result := Result{ - Id: enum.TrafficMonitorName(id), + ID: enum.TrafficMonitorName(id), Available: false, Errors: []error{}, - PollID: pollId, + PollID: pollID, PollFinished: pollFinished, }