From b3277391750ca85eb2e0f57032e483e5f3160faf Mon Sep 17 00:00:00 2001 From: Taylor Frey Date: Fri, 15 Oct 2021 15:27:43 -0600 Subject: [PATCH 1/2] Removed duplicate event message. Clarify event message to account for all availability scenarios. Minor formatting for readability. Add const for consistency and clarity --- traffic_monitor/ds/stat.go | 36 ++++++------------------ traffic_monitor/health/event.go | 4 +++ traffic_monitor/manager/peer.go | 9 +++++- traffic_monitor/manager/statecombiner.go | 11 +++++++- 4 files changed, 30 insertions(+), 30 deletions(-) diff --git a/traffic_monitor/ds/stat.go b/traffic_monitor/ds/stat.go index 56c88591a3..95f3b684b4 100644 --- a/traffic_monitor/ds/stat.go +++ b/traffic_monitor/ds/stat.go @@ -105,30 +105,6 @@ func addAvailableData(dsStats *dsdata.Stats, crStates tc.CRStates, serverCachegr } } - for dsName, stat := range dsStats.DeliveryService { - lastStat, lastStatExists := lastStats.DeliveryServices[dsName] - if !lastStatExists { - continue - } - - getEvent := func(desc string) health.Event { - // TODO sync.Pool? - return health.Event{ - Time: health.Time(time.Now()), - Description: desc, - Name: dsName.String(), - Hostname: dsName.String(), - Type: "Delivery Service", - Available: stat.CommonStats.IsAvailable.Value, - } - } - if stat.CommonStats.IsAvailable.Value == false && lastStat.Available == true { - events.Add(getEvent("no available caches")) - } else if stat.CommonStats.IsAvailable.Value == true && lastStat.Available == false { - events.Add(getEvent("available caches")) - } - } - // TODO move to its own func? for dsName := range crStates.DeliveryService { stat, ok := dsStats.DeliveryService[dsName] @@ -325,14 +301,18 @@ func addDSPerSecStats(lastStats *dsdata.LastStats, dsStats *dsdata.Stats, dsName Description: desc, Name: dsName.String(), Hostname: dsName.String(), - Type: "DELIVERYSERVICE", + Type: health.DeliveryServiceEventType, Available: stat.CommonStats.IsAvailable.Value, } } - if stat.CommonStats.IsAvailable.Value == false && lastStat.Available == true && dsErr != nil { - events.Add(getEvent(dsErr.Error())) // TODO change events.Add to not allocate new memory, after the limit is reached. + if stat.CommonStats.IsAvailable.Value == false && lastStat.Available == true { + eventDesc := "Unavailable" + if dsErr != nil { + eventDesc = eventDesc + " err: " + dsErr.Error() + } + events.Add(getEvent(eventDesc)) // TODO change events.Add to not allocate new memory, after the limit is reached. } else if stat.CommonStats.IsAvailable.Value == true && lastStat.Available == false { - events.Add(getEvent("REPORTED - available")) + events.Add(getEvent("Available caches")) } lastStat.Available = stat.CommonStats.IsAvailable.Value diff --git a/traffic_monitor/health/event.go b/traffic_monitor/health/event.go index 4afec867b6..7aa27bfc49 100644 --- a/traffic_monitor/health/event.go +++ b/traffic_monitor/health/event.go @@ -29,6 +29,10 @@ import ( "github.com/apache/trafficcontrol/lib/go-log" ) +const ( + DeliveryServiceEventType = "DELIVERYSERVICE" +) + type Time time.Time func (t Time) MarshalJSON() ([]byte, error) { diff --git a/traffic_monitor/manager/peer.go b/traffic_monitor/manager/peer.go index e73327234a..9c384cc9b4 100644 --- a/traffic_monitor/manager/peer.go +++ b/traffic_monitor/manager/peer.go @@ -52,6 +52,13 @@ func comparePeerState(events health.ThreadsafeEvents, result peer.Result, peerSt description = "Peer is unreachable" } - events.Add(health.Event{Time: health.Time(result.Time), Description: description, Name: result.ID.String(), Hostname: result.ID.String(), Type: "PEER", Available: result.Available}) + events.Add( + health.Event{ + Time: health.Time(result.Time), + Description: description, + Name: result.ID.String(), + Hostname: result.ID.String(), + Type: "PEER", + Available: result.Available}) } } diff --git a/traffic_monitor/manager/statecombiner.go b/traffic_monitor/manager/statecombiner.go index 922b69689f..23611dec83 100644 --- a/traffic_monitor/manager/statecombiner.go +++ b/traffic_monitor/manager/statecombiner.go @@ -131,7 +131,16 @@ func combineCacheState( } if overrideCondition != "" { - events.Add(health.Event{Time: health.Time(time.Now()), Description: fmt.Sprintf("Health protocol override condition %s", overrideCondition), Name: cacheName.String(), Hostname: cacheName.String(), Type: toData.ServerTypes[cacheName].String(), Available: available, IPv4Available: ipv4Available, IPv6Available: ipv6Available}) + events.Add( + health.Event{ + Time: health.Time(time.Now()), + Description: fmt.Sprintf("Health protocol override condition %s", overrideCondition), + Name: cacheName.String(), + Hostname: cacheName.String(), + Type: toData.ServerTypes[cacheName].String(), + Available: available, + IPv4Available: ipv4Available, + IPv6Available: ipv6Available}) } combinedStates.AddCache(cacheName, tc.IsAvailable{IsAvailable: available, Ipv4Available: ipv4Available, Ipv6Available: ipv6Available}) From eddfc0927654c58e917c3de91db37042e917264f Mon Sep 17 00:00:00 2001 From: Taylor Frey Date: Fri, 15 Oct 2021 15:39:29 -0600 Subject: [PATCH 2/2] Add changelog entry --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 095a7699e0..27c2067ef1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -21,6 +21,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/). - [#6259](https://github.com/apache/trafficcontrol/issues/6259) - Traffic Portal No Longer Allows Spaces in Server Object "Router Port Name" - [#6175](https://github.com/apache/trafficcontrol/issues/6175) - POST request to /api/4.0/phys_locations accepts mismatch values for regionName. - [#6283](https://github.com/apache/trafficcontrol/issues/6283) - The Traffic Ops Postinstall script will work in CentOS 7, even if Python 3 is installed +- [#5373](https://github.com/apache/trafficcontrol/issues/5373) - Traffic Monitor logs not consistent ### Changed - Updated `t3c` to request less unnecessary deliveryservice-server assignment and invalidation jobs data via new query params supported by Traffic Ops