This is an automated email from the ASF dual-hosted git repository.

zrhoffman pushed a commit to branch 6.0.x
in repository https://gitbox.apache.org/repos/asf/trafficcontrol.git

commit 173560a7613e2a17195ac240f14fed0ca52729eb
Author: Taylor Clayton Frey <[email protected]>
AuthorDate: Fri Oct 22 14:46:38 2021 -0600

    Bugfix/5373 tm log inconsistency (#6292)
    
    * Removed duplicate event message.
    
    Clarify event message to account for all availability scenarios.
    
    Minor formatting for readability.
    
    Add const for consistency and clarity
    
    * Add changelog entry
    
    Co-authored-by: Taylor Frey <[email protected]>
---
 CHANGELOG.md                             |  1 +
 traffic_monitor/ds/stat.go               | 36 +++++++-------------------------
 traffic_monitor/health/event.go          |  4 ++++
 traffic_monitor/manager/peer.go          |  9 +++++++-
 traffic_monitor/manager/statecombiner.go | 11 +++++++++-
 5 files changed, 31 insertions(+), 30 deletions(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index 3cf6d75..6fda29d 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -7,6 +7,7 @@ The format is based on [Keep a 
Changelog](http://keepachangelog.com/en/1.0.0/).
 ### Fixed
 - [#6125](https://github.com/apache/trafficcontrol/issues/6125) - Fix 
`/cdns/{name}/federations?id=#` to search for CDN.
 - [#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
 - [#5927](https://github.com/apache/trafficcontrol/issues/5927) Updated 
CDN-in-a-Box to not run a Riak container by default but instead only run it if 
the optional flag is provided.
diff --git a/traffic_monitor/ds/stat.go b/traffic_monitor/ds/stat.go
index 56c8859..95f3b68 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 4afec86..7aa27bf 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 e733272..9c384cc 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 922b696..23611de 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})

Reply via email to