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

rshah pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficcontrol.git


The following commit(s) were added to refs/heads/master by this push:
     new 890f3b48fd Improvement to TCHC's logging around TO failure (#7776)
890f3b48fd is described below

commit 890f3b48fde031fc41ca6220945df0240bb5f31b
Author: Tyler Morgan <[email protected]>
AuthorDate: Mon Sep 11 12:45:31 2023 -0400

    Improvement to TCHC's logging around TO failure (#7776)
    
    * Adding status code for TO
    
    * Adding improved logging for TO interaction
    
    * Adding revised Change log.
    
    * Fixing arg issues.
    
    ---------
    
    Co-authored-by: Tyler Morgan <[email protected]>
---
 CHANGELOG.md                                | 1 +
 tc-health-client/tc-health-client.go        | 4 ++--
 tc-health-client/tmagent/tmagent.go         | 5 ++++-
 tc-health-client/tmagent/tmhealthservice.go | 4 ++--
 4 files changed, 9 insertions(+), 5 deletions(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index 40ecb20677..a9ff876fac 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -52,6 +52,7 @@ The format is based on [Keep a 
Changelog](http://keepachangelog.com/en/1.0.0/).
 - [#7784](https://github.com/apache/trafficcontrol/pull/7784) *Traffic Portal* 
Added revert certificate functionality to the ssl-keys page.
 
 ### Changed
+- [#7776](https://github.com/apache/trafficcontrol/pull/7776) 
*tc-health-client* Added error message while issues interacting with Traffic 
Ops.
 - [#7757](https://github.com/apache/trafficcontrol/pull/7757) *Traffic Router* 
Changed Traffic Router to point to api version 5.0 of Traffic Ops.
 - [#7732](https://github.com/apache/trafficcontrol/pull/7732) *Traffic Router* 
Increased negative TTL value to 900 seconds.
 - [#7761](https://github.com/apache/trafficcontrol/pull/7761) *Traffic 
Monitor* Use API v5 for the TM's Traffic Ops client, and use TO API v4 for TM's 
Traffic Ops legacy client
diff --git a/tc-health-client/tc-health-client.go 
b/tc-health-client/tc-health-client.go
index 0b6389e0bd..5a5a8ccc13 100644
--- a/tc-health-client/tc-health-client.go
+++ b/tc-health-client/tc-health-client.go
@@ -206,11 +206,11 @@ func reloadConfig(pi *tmagent.ParentInfo) {
 
        if isNew {
                if err = config.ReadCredentials(newCfg, false); err != nil {
-                       log.Errorln("could not load credentials for config 
updates, keeping the old config")
+                       log.Errorf("could not load credentials for config 
updates, keeping the old config: %v", err.Error())
                        return
                }
                if err = pi.GetTOData(newCfg); err != nil {
-                       log.Errorln("could not update the list of 
trafficmonitors, keeping the old config")
+                       log.Errorf("could not update the list of 
trafficmonitors, keeping the old config: %v", err.Error())
                } else {
                        // TODO this was calling a custom copy func that wasn't 
copying:
                        //      MarkUpPollThreshold, TmProxyURL, 
CredentialFile, ParsedProxyURL
diff --git a/tc-health-client/tmagent/tmagent.go 
b/tc-health-client/tmagent/tmagent.go
index e7355661c2..277cb03d0b 100644
--- a/tc-health-client/tmagent/tmagent.go
+++ b/tc-health-client/tmagent/tmagent.go
@@ -663,12 +663,15 @@ func (pi *ParentInfo) GetTOData(cfg *config.Cfg) error {
                }
        }
 
-       srvs, _, err := toData.TOClient.GetServers(toclient.NewRequestOptions())
+       srvs, reqInf, err := 
toData.TOClient.GetServers(toclient.NewRequestOptions())
        if err != nil {
                // next time we'll login again and get a new session.
                toData.TOClient = nil
                pi.TOData.Set(toData)
                return errors.New("error fetching Trafficmonitor server list: " 
+ err.Error())
+       } else if reqInf.StatusCode >= 300 || reqInf.StatusCode < 200 {
+               // Provide logging around a potential issue
+               return fmt.Errorf("Traffic Ops returned a non 2xx status code. 
Expected 2xx, got %v", reqInf.StatusCode)
        }
 
        toData.Monitors = map[string]struct{}{}
diff --git a/tc-health-client/tmagent/tmhealthservice.go 
b/tc-health-client/tmagent/tmhealthservice.go
index 14cd76ae44..ffe3deb9f2 100644
--- a/tc-health-client/tmagent/tmhealthservice.go
+++ b/tc-health-client/tmagent/tmhealthservice.go
@@ -108,7 +108,7 @@ func doPollAndUpdateCacheStatus(pi *ParentInfo, 
doTrafficOpsReq bool) {
        if err != nil {
                log.Errorf("poll-status %v\n", err.Error())
                if err := pi.GetTOData(cfg); err != nil {
-                       log.Errorln("update event=\"could not update the list 
of trafficmonitors, keeping the old config\"")
+                       log.Errorf("update event=\"could not update the list of 
trafficmonitors, keeping the old config\": %v", err.Error())
                } else {
                        log.Infoln("service-status service=tm-health 
event=\"updated TrafficMonitor statuses from TrafficOps\"")
                }
@@ -132,7 +132,7 @@ func doPollAndUpdateCacheStatus(pi *ParentInfo, 
doTrafficOpsReq bool) {
        if doTrafficOpsReq {
                // TODO move to its own TO poller
                if err = pi.GetTOData(cfg); err != nil {
-                       log.Errorln("update event=\"could not update the list 
of trafficmonitors, keeping the old config\"")
+                       log.Errorf("update event=\"could not update the list of 
trafficmonitors, keeping the old config\": %v", err.Error())
                } else {
                        log.Infoln("service-status service=tm-health 
event=\"updated TrafficMonitor statuses from TrafficOps\"")
                }

Reply via email to