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

ocket8888 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 c65ee2e  Fix GET /cdns/routing endpoint (#6363)
c65ee2e is described below

commit c65ee2eb43a5bfb7b65c20b35d0e09ef0920b426
Author: Rawlin Peters <[email protected]>
AuthorDate: Fri Nov 19 16:02:26 2021 -0700

    Fix GET /cdns/routing endpoint (#6363)
    
    Without this, we get the following error:
    
      ERROR: api.go:253: 2021-11-19T21:02:45.081842Z: [::1]:53397 getting
      monitors: querying routers: pq: got 1 parameters but the statement
      requires 0
---
 CHANGELOG.md                                           |  1 +
 traffic_ops/traffic_ops_golang/crstats/routing.go      | 10 +++++++---
 traffic_ops/traffic_ops_golang/crstats/routing_test.go |  2 +-
 3 files changed, 9 insertions(+), 4 deletions(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index 4559b43..da785de 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -28,6 +28,7 @@ The format is based on [Keep a 
Changelog](http://keepachangelog.com/en/1.0.0/).
 - [#5893](https://github.com/apache/trafficcontrol/issues/5893) - A self 
signed certificate is created when an HTTPS delivery service is created or an 
HTTP delivery service is updated to HTTPS.
 - [#6125](https://github.com/apache/trafficcontrol/issues/6125) - Fix 
`/cdns/{name}/federations?id=#` to search for CDN.
 - [#6255](https://github.com/apache/trafficcontrol/issues/6255) - Unreadable 
Prod Mode CDN Notifications in Traffic Portal
+- Fixed broken `GET /cdns/routing` Traffic Ops API
 - [#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.
 - [#6285](https://github.com/apache/trafficcontrol/issues/6285) - The Traffic 
Ops Postinstall script will work in CentOS 7, even if Python 3 is installed
diff --git a/traffic_ops/traffic_ops_golang/crstats/routing.go 
b/traffic_ops/traffic_ops_golang/crstats/routing.go
index 20e9a99..5f10b57 100644
--- a/traffic_ops/traffic_ops_golang/crstats/routing.go
+++ b/traffic_ops/traffic_ops_golang/crstats/routing.go
@@ -207,7 +207,6 @@ func getCRSStats(respond chan<- RouterResp, wg 
*sync.WaitGroup, routerFQDN, cdn
 
 // getCDNRouterFQDNs returns an FQDN, including port, of an online router for 
each CDN, for each router. If a CDN has no online routers, that CDN will not 
have an entry in the map. The port returned is the API port.
 func getCDNRouterFQDNs(tx *sql.Tx, requiredCDN *string) 
(map[tc.CDNName][]string, error) {
-       var args interface{}
        query := `
 SELECT s.host_name, s.domain_name, max(pa.value) as port, c.name as cdn
 FROM server as s
@@ -222,12 +221,17 @@ AND st.name = '` + RouterOnlineStatus + `'
 `
        if requiredCDN != nil {
                query += `AND c.name = $1`
-               args = *requiredCDN
        }
        query += `
 GROUP BY s.host_name, s.domain_name, c.name
 `
-       rows, err := tx.Query(query, args)
+       var rows *sql.Rows
+       var err error
+       if requiredCDN != nil {
+               rows, err = tx.Query(query, *requiredCDN)
+       } else {
+               rows, err = tx.Query(query)
+       }
        if err != nil {
                return nil, errors.New("querying routers: " + err.Error())
        }
diff --git a/traffic_ops/traffic_ops_golang/crstats/routing_test.go 
b/traffic_ops/traffic_ops_golang/crstats/routing_test.go
index 7329516..d27889c 100644
--- a/traffic_ops/traffic_ops_golang/crstats/routing_test.go
+++ b/traffic_ops/traffic_ops_golang/crstats/routing_test.go
@@ -79,7 +79,7 @@ func TestGetCDNRouterFQDNsWithoutCDN(t *testing.T) {
 
        rows.AddRow("host1", "test", 2500, "ott")
        rows.AddRow("host2", "test2", 3500, "newCDN")
-       mock.ExpectQuery("SELECT").WithArgs(nil).WillReturnRows(rows)
+       mock.ExpectQuery("SELECT").WillReturnRows(rows)
        mock.ExpectCommit()
 
        dbCtx, cancelTx := context.WithTimeout(context.TODO(), 10*time.Second)

Reply via email to