-
Notifications
You must be signed in to change notification settings - Fork 344
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
strips out mids in the wrong cdn when requesting servers for a ds #5128
Conversation
d010be2
to
451e8d6
Compare
a8a1f67
to
f4e9cfb
Compare
_, dsCDNName, _, err = dbhelpers.GetDSNameAndCDNFromID(tx.Tx, dsID) | ||
if err != nil { | ||
return nil, 0, errors.New("ds not found"), nil, http.StatusNotFound, nil | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should not need to check which CDN the delivery service is in. The query just needs to be adjusted to make sure the servers match the delivery service's CDN.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
well, it doesn't always check the cdn. for example:
GET /servers <-- doesn't check cdn
GET /servers?type=ORG <-- doesn't check cdn
GET /servers?dsId=X <-- does check cdn
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, but it always should check the CDN when the dsId
query parameter exists, and all of the SQL for that part is in deliveryServiceServersJoin
and dssTopologiesJoinSubquery
.
// if requesting servers for a given ds, need to only include those in the same cdn | ||
if len(dsCDNName) > 0 && string(dsCDNName) != *server.CDNName { | ||
continue | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a way to perform this check in the query itself?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, i think you're right. best if done in the query but i had no luck figuring that out. i'll look again.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@zrhoffman - updated. how's that look?
Servers API tests fail [user@computer api]$ time go test ./v3 -test.v -cfg=../conf/traffic-ops-test.conf -fixtures=tc-fixtures.json -test.run '^TestServers$'
INFO: traffic_ops_test.go:71: 2020-10-14T17:00:48.15509479-06:00: Using Config values:
TO Config File: ../conf/traffic-ops-test.conf
TO Fixtures: tc-fixtures.json
TO URL: https://localhost:6443
TO Session Timeout In Secs: 60
DB Server: localhost
DB User: traffic_ops
DB Name: traffic_ops
DB Ssl: false
UseIMS: true
=== RUN TestServers
cdns_test.go:89: Response: {[{cdn was created. success}]}
cdns_test.go:89: Response: {[{cdn was created. success}]}
cdns_test.go:89: Response: {[{cdn was created. success}]}
cdns_test.go:89: Response: {[{cdn was created. success}]}
cdns_test.go:89: Response: {[{cdn was created. success}]}
types_test.go:89: ---- CreateTestTypes ----
user_test.go:103: Response: {[{user was created. success}]}
user_test.go:103: Response: {[{user was created. success}]}
user_test.go:103: Response: {[{user was created. success}]}
user_test.go:103: Response: {[{user was created. success}]}
user_test.go:103: Response: {[{user was created. success}]}
user_test.go:103: Response: {[{user was created. success}]}
user_test.go:103: Response: {[{user was created. success}]}
parameters_test.go:75: Response: {[{param was created. success}]}
parameters_test.go:75: Response: {[{param was created. success}]}
parameters_test.go:75: Response: {[{param was created. success}]}
parameters_test.go:75: Response: {[{param was created. success}]}
parameters_test.go:75: Response: {[{param was created. success}]}
parameters_test.go:75: Response: {[{param was created. success}]}
parameters_test.go:75: Response: {[{param was created. success}]}
parameters_test.go:75: Response: {[{param was created. success}]}
parameters_test.go:75: Response: {[{param was created. success}]}
parameters_test.go:75: Response: {[{param was created. success}]}
parameters_test.go:75: Response: {[{param was created. success}]}
parameters_test.go:75: Response: {[{param was created. success}]}
parameters_test.go:75: Response: {[{param was created. success}]}
parameters_test.go:75: Response: {[{param was created. success}]}
parameters_test.go:75: Response: {[{param was created. success}]}
parameters_test.go:75: Response: {[{param was created. success}]}
parameters_test.go:75: Response: {[{param was created. success}]}
parameters_test.go:75: Response: {[{param was created. success}]}
parameters_test.go:75: Response: {[{param was created. success}]}
parameters_test.go:75: Response: {[{param was created. success}]}
profiles_test.go:162: Response: {[{profile was created. success}]}
profiles_test.go:162: Response: {[{profile was created. success}]}
profiles_test.go:162: Response: {[{profile was created. success}]}
profiles_test.go:162: Response: {[{profile was created. success}]}
profiles_test.go:162: Response: {[{profile was created. success}]}
profiles_test.go:162: Response: {[{profile was created. success}]}
profiles_test.go:162: Response: {[{profile was created. success}]}
profiles_test.go:162: Response: {[{profile was created. success}]}
profiles_test.go:162: Response: {[{profile was created. success}]}
profiles_test.go:162: Response: {[{profile was created. success}]}
profiles_test.go:162: Response: {[{profile was created. success}]}
profiles_test.go:162: Response: {[{profile was created. success}]}
profiles_test.go:162: Response: {[{profile was created. success}]}
statuses_test.go:98: Response: {[{status was created. success}]}
statuses_test.go:98: Response: {[{status was created. success}]}
statuses_test.go:98: Response: {[{status was created. success}]}
statuses_test.go:98: Response: {[{status was created. success}]}
statuses_test.go:98: Response: {[{status was created. success}]}
statuses_test.go:98: Response: {[{status was created. success}]}
statuses_test.go:98: Response: {[{status was created. success}]}
divisions_test.go:117: Response: {[{division was created. success}]}
divisions_test.go:117: Response: {[{division was created. success}]}
regions_test.go:91: Response: {[{region was created. success}]}
regions_test.go:91: Response: {[{region was created. success}]}
phys_locations_test.go:91: Response: {[{physLocation was created. success}]}
phys_locations_test.go:91: Response: {[{physLocation was created. success}]}
phys_locations_test.go:91: Response: {[{physLocation was created. success}]}
topologies_test.go:56: Response: &{{a topology my-topology [{0 parentCachegroup [] <nil>} {0 secondaryCachegroup [] <nil>} {0 cachegroup3 [0 1] <nil>}] <nil>} {[{topology was created. success}]}}
topologies_test.go:56: Response: &{{another topology another-topology [{0 parentCachegroup [] <nil>} {0 cachegroup1 [0] <nil>} {0 secondaryCachegroup [] <nil>} {0 cachegroup2 [2] <nil>}] <nil>} {[{topology was created. success}]}}
topologies_test.go:56: Response: &{{A topology with secondary parents secondary-parents [{0 parentCachegroup [] <nil>} {0 cachegroup1 [0 2] <nil>} {0 secondaryCachegroup [] <nil>} {0 fallback1 [2 0] <nil>} {0 fallback2 [2 0] <nil>}] <nil>} {[{topology was created. success}]}}
topologies_test.go:56: Response: &{{A 4-tier topology 4-tiers [{0 parentCachegroup [] <nil>} {0 parentCachegroup2 [0] <nil>} {0 cachegroup1 [1] <nil>} {0 secondaryCachegroup [1 0] <nil>} {0 fallback1 [3] <nil>}] <nil>} {[{topology was created. success}]}}
topologies_test.go:56: Response: &{{This topology stems from 2 ancestors forked-topology [{0 topology-edge-cg-01 [2] <nil>} {0 topology-edge-cg-02 [6] <nil>} {0 topology-mid-cg-01 [3] <nil>} {0 topology-mid-cg-02 [4] <nil>} {0 topology-mid-cg-03 [5] <nil>} {0 topology-mid-cg-04 [] <nil>} {0 topology-mid-cg-05 [7] <nil>} {0 topology-mid-cg-06 [8] <nil>} {0 topology-mid-cg-07 [] <nil>}] <nil>} {[{topology was created. success}]}}
topologies_test.go:56: Response: &{{a topology top-for-ds-req [{0 dtrc1 [] <nil>} {0 dtrc2 [0] <nil>} {0 dtrc3 [0] <nil>}] <nil>} {[{topology was created. success}]}}
topologies_test.go:56: Response: &{{a topology top-for-ds-req2 [{0 dtrc1 [] <nil>} {0 dtrc2 [0] <nil>}] <nil>} {[{topology was created. success}]}}
servers_test.go:246: Response: atlanta-edge-01 {[{Server created success}]}
servers_test.go:246: Response: cdn2-test-edge {[{Server created success}]}
servers_test.go:246: Response: influxdb02 {[{Server created success}]}
servers_test.go:246: Response: atlanta-router-01 {[{Server created success}]}
servers_test.go:246: Response: atlanta-edge-03 {[{Server created success}]}
servers_test.go:246: Response: atlanta-edge-14 {[{Server created success}]}
servers_test.go:246: Response: atlanta-edge-15 {[{Server created success}]}
servers_test.go:246: Response: atlanta-mid-16 {[{Server created success}]}
servers_test.go:246: Response: atlanta-mid-17 {[{Server created success}]}
servers_test.go:246: Response: atlanta-org-1 {[{Server created success}]}
servers_test.go:246: Response: atlanta-org-2 {[{Server created success}]}
servers_test.go:246: Response: atlanta-mid-01 {[{Server created success}]}
servers_test.go:246: Response: rascal01 {[{Server created success}]}
servers_test.go:246: Response: edge1-cdn2 {[{Server created success}]}
servers_test.go:246: Response: riak {[{Server created success}]}
servers_test.go:246: Response: denver-mso-org-01 {[{Server created success}]}
servers_test.go:246: Response: edge1-cdn1-cg3 {[{Server created success}]}
servers_test.go:246: Response: edge2-cdn1-cg3 {[{Server created success}]}
servers_test.go:246: Response: topology-edge-01 {[{Server created success}]}
servers_test.go:246: Response: topology-edge-02 {[{Server created success}]}
servers_test.go:246: Response: topology-mid-04 {[{Server created success}]}
servers_test.go:246: Response: dtrc-mid-01 {[{Server created success}]}
servers_test.go:246: Response: dtrc-mid-02 {[{Server created success}]}
servers_test.go:246: Response: dtrc-mid-03 {[{Server created success}]}
servers_test.go:246: Response: dtrc-edge-01 {[{Server created success}]}
servers_test.go:246: Response: dtrc-edge-02 {[{Server created success}]}
servers_test.go:246: Response: dtrc-edge-03 {[{Server created success}]}
servers_test.go:246: Response: dtrc-edge-04 {[{Server created success}]}
servers_test.go:246: Response: dtrc-edge-05 {[{Server created success}]}
servers_test.go:246: Response: dtrc-edge-06 {[{Server created success}]}
servers_test.go:246: Response: dtrc-edge-07 {[{Server created success}]}
servers_test.go:246: Response: dtrc-edge-08 {[{Server created success}]}
servers_test.go:246: Response: dtrc-mid-04 {[{Server created success}]}
servers_test.go:753: type change update alerts: {Alerts:[]}
servers_to_deliveryservice_assignment_test.go:74: alerts: {Alerts:[{Text:successfully assigned dses to server Level:success}]}
servers_to_deliveryservice_assignment_test.go:77: response: [{DeliveryServiceNullableV14:{DeliveryServiceNullableV13:{DeliveryServiceNullableV12:{DeliveryServiceNullableV11:{Active:0xc002038478 AnonymousBlockingEnabled:0xc002038479 CacheURL:0xc00224cd00 CCRDNSTTL:0xc0020384a0 CDNID:0xc0020384b0 CDNName:0xc00224cd10 CheckPath:0xc00224cd20 DisplayName:0xc00224cd30 DNSBypassCNAME:<nil> DNSBypassIP:0xc00224cd40 DNSBypassIP6:0xc00224cd50 DNSBypassTTL:0xc0020384d0 DSCP:0xc0020384e0 EdgeHeaderRewrite:0xc00224cd70 GeoLimit:0xc0020384f0 GeoLimitCountries:0xc00224cd90 GeoLimitRedirectURL:<nil> GeoProvider:0xc0020384f8 GlobalMaxMBPS:0xc002038500 GlobalMaxTPS:0xc002038508 HTTPBypassFQDN:0xc00224cda0 ID:0xc002038510 InfoURL:0xc00224cdb0 InitialDispersion:0xc002038520 IPV6RoutingEnabled:0xc002038528 LastUpdated:0001-01-01 00:00:00 +0000 UTC LogsEnabled:0xc002038529 LongDesc:0xc00224cdc0 LongDesc1:0xc00224cde0 LongDesc2:0xc00224cdf0 MatchList:0xc002234e00 MaxDNSAnswers:0xc002038538 MidHeaderRewrite:0xc00224ce00 MissLat:0xc002038560 MissLong:0xc002038568 MultiSiteOrigin:0xc00203858a OriginShield:<nil> OrgServerFQDN:0xc00224ce10 ProfileDesc:<nil> ProfileID:<nil> ProfileName:<nil> Protocol:0xc002038590 QStringIgnore:0xc002038598 RangeRequestHandling:0xc0020385a0 RegexRemap:0xc00224ce20 RegionalGeoBlocking:0xc0020385af RemapText:0xc00224ce30 RoutingName:0xc00224ce40 Signed:true SSLKeyVersion:0xc0020385c8 TenantID:0xc0020385d0 Type:HTTP TypeID:0xc002038690 XMLID:0xc00224ce60 ExampleURLs:[http://ccr-ds1.ds1.test.cdn1.net https://ccr-ds1.ds1.test.cdn1.net]}} DeepCachingType:NEVER FQPacingRate:0xc0020386e8 SigningAlgorithm:0xc00224ce80 Tenant:0xc00224ce90 TRResponseHeaders:<nil> TRRequestHeaders:<nil>} ConsistentHashRegex:<nil> ConsistentHashQueryParams:[] MaxOriginConnections:0xc002038700} EcsEnabled:false RangeSliceBlockSize:<nil>}]
servers_test.go:365: expected to get 1 server for Delivery Service: 322, actual: 2
types_test.go:208: ---- DeleteTestTypes ----
--- FAIL: TestServers (11.69s)
FAIL
FAIL github.com/apache/trafficcontrol/traffic_ops/testing/api/v3 12.020s
FAIL |
serversResp, _, err := TOSession.GetServersWithHdr(nil, nil) | ||
serversIds := []int{} | ||
for _, s := range serversResp.Response { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should check err
before trying to use serversResp
dsServersResp, _, err := TOSession.GetServersWithHdr(¶ms, nil) | ||
dsServerIds := []int{} | ||
for _, dss := range dsServersResp.Response { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another case that should check err
before trying to use serversResp
|
||
_, _, err = TOSession.CreateDeliveryServiceServers(*dsWithMid[0].ID, serversIds, true) | ||
if err != nil { | ||
t.Errorf("POST delivery service servers: %v", err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The rest of the function uses t.Fatalf()
, why use t.Errorf()
here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good question
func GetDSCDNIdFromID(tx *sql.Tx, id int) (int, bool, error) { | ||
var cdnID int |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cdnID
is a good name because we know that it refers to the ID of a CDN. id
is less clear, the variable name should mention what kind of ID it is
so strange. all passed for me before. checking. |
servers_test.go:246: Response: dtrc-mid-04 {[{Server created success}]}
servers_test.go:753: type change update alerts: {Alerts:[]}
servers_to_deliveryservice_assignment_test.go:74: alerts: {Alerts:[{Text:successfully assigned dses to server Level:success}]}
servers_to_deliveryservice_assignment_test.go:77: response: [{DeliveryServiceNullableV14:{DeliveryServiceNullableV13:{DeliveryServiceNullableV12:{DeliveryServiceNullableV11:{Active:0xc000249ad8 AnonymousBlockingEnabled:0xc000249ad9 CacheURL:0xc0020fa9a0 CCRDNSTTL:0xc000249b00 CDNID:0xc000249b10 CDNName:0xc0020fa9c0 CheckPath:0xc0020fa9e0 DisplayName:0xc0020fa9f0 DNSBypassCNAME:<nil> DNSBypassIP:0xc0020faa00 DNSBypassIP6:0xc0020faa10 DNSBypassTTL:0xc000249b30 DSCP:0xc000249b40 EdgeHeaderRewrite:0xc0020faa30 GeoLimit:0xc000249b50 GeoLimitCountries:0xc0020faa40 GeoLimitRedirectURL:<nil> GeoProvider:0xc000249b58 GlobalMaxMBPS:0xc000249b60 GlobalMaxTPS:0xc000249b68 HTTPBypassFQDN:0xc0020faa50 ID:0xc000249b70 InfoURL:0xc0020faa60 InitialDispersion:0xc000249b80 IPV6RoutingEnabled:0xc000249b88 LastUpdated:0001-01-01 00:00:00 +0000 UTC LogsEnabled:0xc000249b89 LongDesc:0xc0020faa70 LongDesc1:0xc0020faa80 LongDesc2:0xc0020faa90 MatchList:0xc00160a640 MaxDNSAnswers:0xc000249b98 MidHeaderRewrite:0xc0020faaa0 MissLat:0xc000249bc0 MissLong:0xc000249bc8 MultiSiteOrigin:0xc000249bea OriginShield:<nil> OrgServerFQDN:0xc0020faab0 ProfileDesc:<nil> ProfileID:<nil> ProfileName:<nil> Protocol:0xc000249bf0 QStringIgnore:0xc000249bf8 RangeRequestHandling:0xc000249c00 RegexRemap:0xc0020faac0 RegionalGeoBlocking:0xc000249c0f RemapText:0xc0020faad0 RoutingName:0xc0020faae0 Signed:true SSLKeyVersion:0xc000249c28 TenantID:0xc000249c30 Type:HTTP TypeID:0xc000249c40 XMLID:0xc0020fab10 ExampleURLs:[http://ccr-ds1.ds1.test.cdn1.net https://ccr-ds1.ds1.test.cdn1.net]}} DeepCachingType:NEVER FQPacingRate:0xc000249c58 SigningAlgorithm:0xc0020fab40 Tenant:0xc0020fab50 TRResponseHeaders:<nil> TRRequestHeaders:<nil>} ConsistentHashRegex:<nil> ConsistentHashQueryParams:[] MaxOriginConnections:0xc000249c70} EcsEnabled:false RangeSliceBlockSize:<nil>}]
servers_test.go:458: expected hostnames map[atlanta-mid-16:true edge1-cdn1-cg3:true edge2-cdn1-cg3:true], actual atlanta-mid-17 actual:
types_test.go:208: ---- DeleteTestTypes ----
--- FAIL: TestServers (12.39s)
FAIL
FAIL github.com/apache/trafficcontrol/traffic_ops/testing/api/v3 15.930s
FAIL |
@zrhoffman - do you understand why the api tests are failing? |
Look at the servers_test.go:458: expected hostnames map[atlanta-mid-16:true edge1-cdn1-cg3:true edge2-cdn1-cg3:true], actual atlanta-mid-17 actual: It means that the only servers it expected in the response were
but it found That So, look at whether |
@@ -2317,7 +2317,7 @@ | |||
"xmppPasswd": "X" | |||
}, | |||
{ | |||
"cachegroup": "parentCachegroup", | |||
"cachegroup": "parentCachegroup2", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why does the test fail when atlanta-mid-17
is in parentCachegroup
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
parentCachegroup was used as part of a topology so i just put it in another cg so not to mess w/ that test. but all passes now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It shouldn't matter that it is used as part of a topology. atlanta-mid-17
is in CDN cdn2
. The delivery service used in the test has xmlId ds-top
and is in CDN cdn1
. So, atlanta-mid-17
being returned in the response is a bug because it's in a different CDN, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looking. its hard imo to weed thru all these fixtures and map them to the test cases they are fulfilling. but maybe you're right. maybe it uncovered a different bug...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
reverting that.... parentCachegroup is fine for my test...now to figure out why it's breaking the topology test..
honestly, i could not find that in the GHA output.... |
Neither could I. Your best bet is running the tests locally in CDN-in-a-Box. |
yeah, looks like a bug. atlanta-mid-17 should not be in there as atlanta-mid-17 is in a different cdn than the ds... |
Looking at trafficcontrol/traffic_ops/testing/api/v3/servers_test.go Lines 493 to 508 in ecb3806
the query parameter that is failing in the test is |
… same cdn as the ds
4198d55
to
92edce6
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tests pass. Manual testing confirms only servers within a Delivery Service's CDN are returned when querying servers by Delivery Service.
Which Traffic Control components are affected by this PR?
What is the best way to verify this PR?
Run the API tests
If this is a bug fix, what versions of Traffic Control are affected?
The following criteria are ALL met by this PR
Additional Information