From 56c2e2c7949e335912f36c5344826d2e6af18ffe Mon Sep 17 00:00:00 2001 From: Rawlin Peters Date: Tue, 11 Oct 2022 21:13:53 -0600 Subject: [PATCH] Do not include non-TR profile params in CRConfig "config" section Instead of querying all profile parameters with the config file "CRConfig.json" for any servers of any type that belong to a given CDN, query only profile params assigned to profiles of CCR-type servers for the given CDN. Fixes #3974. --- traffic_ops/traffic_ops_golang/crconfig/config.go | 9 +++++++-- traffic_ops/traffic_ops_golang/crconfig/config_test.go | 3 ++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/traffic_ops/traffic_ops_golang/crconfig/config.go b/traffic_ops/traffic_ops_golang/crconfig/config.go index bcc339a8e3..885bb4d45c 100644 --- a/traffic_ops/traffic_ops_golang/crconfig/config.go +++ b/traffic_ops/traffic_ops_golang/crconfig/config.go @@ -24,6 +24,9 @@ import ( "errors" "strconv" "strings" + + "github.com/apache/trafficcontrol/lib/go-log" + "github.com/apache/trafficcontrol/lib/go-tc" ) func makeCRConfigConfig(cdn string, tx *sql.Tx, dnssecEnabled bool, domain string) (map[string]interface{}, error) { @@ -94,16 +97,18 @@ select name, value from parameter where id in ( select parameter from profile_parameter where profile in ( select distinct profile from server where cdn_id = ( select id from cdn where name = $1 + ) and type = ( + select id from type where name = $2 ) ) ) and config_file = 'CRConfig.json' ` - rows, err := tx.Query(q, cdn) + rows, err := tx.Query(q, cdn, tc.RouterTypeName) if err != nil { return nil, errors.New("Error querying router params: " + err.Error()) } - defer rows.Close() + defer log.Close(rows, "closing crconfig parameter rows") params := []CRConfigConfigParameter{} for rows.Next() { diff --git a/traffic_ops/traffic_ops_golang/crconfig/config_test.go b/traffic_ops/traffic_ops_golang/crconfig/config_test.go index 2dfa5fd436..9414baf970 100644 --- a/traffic_ops/traffic_ops_golang/crconfig/config_test.go +++ b/traffic_ops/traffic_ops_golang/crconfig/config_test.go @@ -26,6 +26,7 @@ import ( "testing" "time" + "github.com/apache/trafficcontrol/lib/go-tc" "github.com/apache/trafficcontrol/traffic_ops/traffic_ops_golang/test" "gopkg.in/DATA-DOG/go-sqlmock.v1" @@ -46,7 +47,7 @@ func MockGetConfigParams(mock sqlmock.Sqlmock, expected []CRConfigConfigParamete v := param.Value rows = rows.AddRow(n, v) } - mock.ExpectQuery("select").WithArgs(cdn).WillReturnRows(rows) + mock.ExpectQuery("select").WithArgs(cdn, tc.RouterTypeName).WillReturnRows(rows) } func TestGetConfigParams(t *testing.T) {