You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@trafficcontrol.apache.org by GitBox <gi...@apache.org> on 2022/05/12 18:15:39 UTC

[GitHub] [trafficcontrol] srijeet0406 opened a new pull request, #6827: `api/{{version}/deliveryservices/{id}/health` returns no info if the delivery service uses a topology

srijeet0406 opened a new pull request, #6827:
URL: https://github.com/apache/trafficcontrol/pull/6827

   <!--
   Thank you for contributing! Please be sure to read our contribution guidelines: https://github.com/apache/trafficcontrol/blob/master/CONTRIBUTING.md
   If this closes or relates to an existing issue, please reference it using one of the following:
   
   Closes: #6271 
   Related: #ISSUE
   
   If this PR fixes a security vulnerability, DO NOT submit! Instead, contact
   the Apache Traffic Control Security Team at security@trafficcontrol.apache.org and follow the
   guidelines at https://apache.org/security regarding vulnerability disclosure.
   -->
   Closes: #6271 
   
   <!-- **^ Add meaningful description above** --><hr/>
   
   ## Which Traffic Control components are affected by this PR?
   <!-- Please delete all components from this list that are NOT affected by this PR.
   Feel free to add the name of a tool or script that is affected but not on the list.
   -->
   - Traffic Ops
   
   
   ## What is the best way to verify this PR?
   <!-- Please include here ALL the steps necessary to test your PR.
   If your PR has tests (and most should), provide the steps needed to run the tests.
   If not, please provide step-by-step instructions to test the PR manually and explain why your PR does not need tests. -->
   Run CDN-in-a-box.
   Create two ds, one with and another without a valid topology.
   Assign some "REPORTED" EDGE caches to the topology, and also do the same for the first DS (without topology).
   Snap both the delivery services.
   Make a call to GET `deliveryservices/{id}/health` for the both the DS's.
   Make sure that both DS's show valid counts of online/ offline caches.
   
   ## If this is a bugfix, which Traffic Control versions contained the bug?
   <!-- Delete this section if the PR is not a bugfix, or if the bug is only in the master branch.
   Examples:
   - 5.1.2
   - 5.1.3 (RC1)
    -->
   
   - master
   ## PR submission checklist
   - [x] This PR has tests <!-- If not, please delete this text and explain why this PR does not need tests. -->
   - [ ] This PR has documentation <!-- If not, please delete this text and explain why this PR does not need documentation. -->
   - [x] This PR has a CHANGELOG.md entry <!-- A fix for a bug from an ATC release, an improvement, or a new feature should have a changelog entry. -->
   - [x] This PR **DOES NOT FIX A SERIOUS SECURITY VULNERABILITY** (see [the Apache Software Foundation's security guidelines](https://apache.org/security) for details)
   
   <!--
   Licensed to the Apache Software Foundation (ASF) under one
   or more contributor license agreements.  See the NOTICE file
   distributed with this work for additional information
   regarding copyright ownership.  The ASF licenses this file
   to you under the Apache License, Version 2.0 (the
   "License"); you may not use this file except in compliance
   with the License.  You may obtain a copy of the License at
   
       http://www.apache.org/licenses/LICENSE-2.0
   
   Unless required by applicable law or agreed to in writing,
   software distributed under the License is distributed on an
   "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
   KIND, either express or implied.  See the License for the
   specific language governing permissions and limitations
   under the License.
   -->
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@trafficcontrol.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [trafficcontrol] ocket8888 commented on a diff in pull request #6827: `api/{{version}/deliveryservices/{id}/health` returns no info if the delivery service uses a topology

Posted by GitBox <gi...@apache.org>.
ocket8888 commented on code in PR #6827:
URL: https://github.com/apache/trafficcontrol/pull/6827#discussion_r878633934


##########
traffic_ops/traffic_ops_golang/deliveryservice/health.go:
##########
@@ -115,29 +118,26 @@ func getMonitorHealth(tx *sql.Tx, ds tc.DeliveryServiceName, monitorFQDNs []stri
 }
 
 // addHealth adds the given cache states to the given data and totals, and returns the new data and totals
-func addHealth(ds tc.DeliveryServiceName, data map[tc.CacheGroupName]tc.HealthDataCacheGroup, totalOnline uint64, totalOffline uint64, crStates tc.CRStates, crConfig tc.CRConfig) (map[tc.CacheGroupName]tc.HealthDataCacheGroup, uint64, uint64) {
+func addHealth(ds tc.DeliveryServiceName, data map[tc.CacheGroupName]tc.HealthDataCacheGroup, totalOnline uint64, totalOffline uint64, crStates tc.CRStates, crConfig tc.CRConfig) (error, map[tc.CacheGroupName]tc.HealthDataCacheGroup, uint64, uint64) {

Review Comment:
   nit: errors should be the last return value when there are multiple



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@trafficcontrol.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [trafficcontrol] ocket8888 merged pull request #6827: `api/{{version}/deliveryservices/{id}/health` returns no info if the delivery service uses a topology

Posted by GitBox <gi...@apache.org>.
ocket8888 merged PR #6827:
URL: https://github.com/apache/trafficcontrol/pull/6827


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@trafficcontrol.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


[GitHub] [trafficcontrol] ocket8888 commented on a diff in pull request #6827: `api/{{version}/deliveryservices/{id}/health` returns no info if the delivery service uses a topology

Posted by GitBox <gi...@apache.org>.
ocket8888 commented on code in PR #6827:
URL: https://github.com/apache/trafficcontrol/pull/6827#discussion_r878470342


##########
traffic_ops/traffic_ops_golang/deliveryservice/health.go:
##########
@@ -132,7 +160,24 @@ func addHealth(ds tc.DeliveryServiceName, data map[tc.CacheGroupName]tc.HealthDa
 		if cache.CacheGroup == nil {
 			continue // TODO warn?
 		}
-
+		if topology != "" {
+			if _, ok := cacheGroupNameMap[*cache.CacheGroup]; !ok {
+				continue
+			}
+			cacheCapabilities = make(map[string]bool)

Review Comment:
   This shadows a variable of the same name in an outer scope; it should be renamed to avoid collisions and confusion.
   
   Also: nit but you know how big this needs to be. It's exactly the size of the cache server's `Capabilities` array, since it's not legal for those to contain duplicates. So you can construct with that in mind to cut down on re-allocations.
   
   Also the value of each map key is unused, so to save an insignificant amount of space this could just be a `map[string]struct{}`



##########
traffic_ops/traffic_ops_golang/deliveryservice/health.go:
##########
@@ -132,7 +160,24 @@ func addHealth(ds tc.DeliveryServiceName, data map[tc.CacheGroupName]tc.HealthDa
 		if cache.CacheGroup == nil {
 			continue // TODO warn?
 		}
-
+		if topology != "" {
+			if _, ok := cacheGroupNameMap[*cache.CacheGroup]; !ok {
+				continue
+			}
+			cacheCapabilities = make(map[string]bool)
+			for _, cap := range cache.Capabilities {
+				cacheCapabilities[cap] = true
+			}
+			for _, rc := range deliveryService.RequiredCapabilities {
+				if _, ok = cacheCapabilities[rc]; !ok {
+					skip = true
+					continue

Review Comment:
   at this point you know that it shouldn't be counted. There's no reason to continue to check the rest of the Capabilities, just `break` here instead.



##########
traffic_ops/traffic_ops_golang/deliveryservice/health.go:
##########
@@ -115,13 +116,40 @@ func getMonitorHealth(tx *sql.Tx, ds tc.DeliveryServiceName, monitorFQDNs []stri
 
 // addHealth adds the given cache states to the given data and totals, and returns the new data and totals
 func addHealth(ds tc.DeliveryServiceName, data map[tc.CacheGroupName]tc.HealthDataCacheGroup, totalOnline uint64, totalOffline uint64, crStates tc.CRStates, crConfig tc.CRConfig) (map[tc.CacheGroupName]tc.HealthDataCacheGroup, uint64, uint64) {
+
+	var deliveryService tc.CRConfigDeliveryService
+	var ok bool
+	var topology string
+	var cacheGroupNameMap = make(map[string]bool)
+	var cacheCapabilities = make(map[string]bool)
+	var skip bool
+
+	if deliveryService, ok = crConfig.DeliveryServices[string(ds)]; !ok {
+		log.Errorln("delivery service not found in CRConfig")

Review Comment:
   Should this return an error instead of logging it and returning data as though the DS *were* found?



##########
traffic_ops/traffic_ops_golang/deliveryservice/health_test.go:
##########
@@ -0,0 +1,165 @@
+package deliveryservice
+
+/*
+
+   Licensed under the Apache License, Version 2.0 (the "License");
+   you may not use this file except in compliance with the License.
+   You may obtain a copy of the License at
+
+   http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.
+*/
+
+import (
+	"github.com/apache/trafficcontrol/lib/go-tc"
+
+	"encoding/json"
+	"testing"
+)
+
+const crConfigJson = `

Review Comment:
   Instead of making two JSON string constants and then doing nothing with them but unmarshalling into a real struct, why not just create that struct immediately, so you get compile-time type safety?



##########
traffic_ops/traffic_ops_golang/deliveryservice/health.go:
##########
@@ -115,13 +116,40 @@ func getMonitorHealth(tx *sql.Tx, ds tc.DeliveryServiceName, monitorFQDNs []stri
 
 // addHealth adds the given cache states to the given data and totals, and returns the new data and totals
 func addHealth(ds tc.DeliveryServiceName, data map[tc.CacheGroupName]tc.HealthDataCacheGroup, totalOnline uint64, totalOffline uint64, crStates tc.CRStates, crConfig tc.CRConfig) (map[tc.CacheGroupName]tc.HealthDataCacheGroup, uint64, uint64) {
+
+	var deliveryService tc.CRConfigDeliveryService
+	var ok bool
+	var topology string
+	var cacheGroupNameMap = make(map[string]bool)
+	var cacheCapabilities = make(map[string]bool)
+	var skip bool
+
+	if deliveryService, ok = crConfig.DeliveryServices[string(ds)]; !ok {
+		log.Errorln("delivery service not found in CRConfig")
+		return map[tc.CacheGroupName]tc.HealthDataCacheGroup{}, 0, 0
+	}
+
+	if deliveryService.Topology != nil {
+		topology = *deliveryService.Topology
+		if topology != "" {
+			if top, ok := crConfig.Topologies[topology]; !ok {
+				log.Errorf("CRConfig topologies does not contain DS topology: %s", topology)

Review Comment:
   Should this return an error instead of logging this and returning data as though the DS's topology *were* found?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: issues-unsubscribe@trafficcontrol.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org