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 2021/03/02 22:10:49 UTC

[GitHub] [trafficcontrol] srijeet0406 opened a new pull request #5600: Adding check for safer conversion between types

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


   <!--
   ************ STOP!! ************
   If this Pull Request is intended to fix a security vulnerability, DO NOT submit it! Instead, contact
   the Apache Software Foundation Security Team at security@trafficcontrol.apache.org and follow the
   guidelines at https://www.apache.org/security/ regarding vulnerability disclosure.
   -->
   ## What does this PR (Pull Request) do?
   <!-- Explain the changes you made here. If this fixes an Issue, identify it by
   replacing the text in the checkbox item with the Issue number e.g.
   
   - [x] This PR fixes #9001 OR is not related to any Issue
   
   ^ This will automatically close Issue number 9001 when the Pull Request is
   merged (The '#' is important).
   
   Be sure you check the box properly, see the "The following criteria are ALL
   met by this PR" section for details.
   -->
   
   - [x] This PR fixes #5565  <!-- You can check for an issue here: https://github.com/apache/trafficcontrol/issues -->
   
   
   ## Which Traffic Control components are affected by this PR?
   <!-- Please delete all components from this list that are NOT affected by this
   Pull Request. Also, feel free to add the name of a tool or script that is
   affected but not on the list.
   
   Additionally, if this Pull Request does NOT affect documentation, please
   explain why documentation is not required. -->
   
   - Traffic Ops
   - CI tests
   
   ## What is the best way to verify this PR?
   <!-- Please include here ALL the steps necessary to test your Pull Request. If
   it includes tests (and most should), outline here the steps needed to run the
   tests. If not, lay out the manual testing procedure and please explain why
   tests are unnecessary for this Pull Request. -->
   
   Make sure all the api and unit tests pass
   Try making a call to `GET /api/x/caches/stats` and make sure you dont see an ISE and/or panic
   
   ## If this is a bug fix, what versions of Traffic Control are affected?
   <!-- If this PR fixes a bug, please list here all of the affected versions - to
   the best of your knowledge. It's also pretty helpful to include a commit hash
   of where 'master' is at the time this PR is opened (if it affects master),
   because what 'master' means will change over time. For example, if this PR
   fixes a bug that's present in master (at commit hash '1df853c8'), in v4.0.0,
   and in the current 4.0.1 Release candidate (e.g. RC1), then this list would
   look like:
   
   - master (1df853c8)
   - 4.0.0
   - 4.0.1 (RC1)
   
   If you don't know what other versions might have this bug, AND don't know how
   to find the commit hash of 'master', then feel free to leave this section
   blank (or, preferably, delete it entirely).
    -->
   
   - master
   
   ## The following criteria are ALL met by this PR
   <!-- Check the boxes to signify that the associated statement is true. To
   "check a box", replace the space inside of the square brackets with an 'x'.
   e.g.
   
   - [ x] <- Wrong
   - [x ] <- Wrong
   - [] <- Wrong
   - [*] <- Wrong
   - [x] <- Correct!
   
   -->
   
   - [x] This PR includes tests 
   - [x] This PR does not include documentation 
   - [x] This PR does not include an update to CHANGELOG.md 
   - [x] This PR includes any and all required license headers
   - [x] This PR **DOES NOT FIX A SERIOUS SECURITY VULNERABILITY** (see [the Apache Software Foundation's security guidelines](https://www.apache.org/security/) for details)
   
   
   ## Additional Information
   <!-- If you would like to include any additional information on the PR for
   potential reviewers please put it here.
   
   Some examples of this would be:
   
   - Before and after screenshots/gifs of the Traffic Portal if it is affected
   - Links to other dependent Pull Requests
   - References to relevant context (e.g. new/updates to dependent libraries,
   mailing list records, blueprints)
   
   Feel free to leave this section blank (or, preferably, delete it entirely).
   -->
   
   <!--
   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.

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



[GitHub] [trafficcontrol] TaylorCFrey commented on a change in pull request #5600: Adding check for safer conversion between types

Posted by GitBox <gi...@apache.org>.
TaylorCFrey commented on a change in pull request #5600:
URL: https://github.com/apache/trafficcontrol/pull/5600#discussion_r589839155



##########
File path: traffic_ops/traffic_ops_golang/cachesstats/cachesstats_test.go
##########
@@ -0,0 +1,128 @@
+package cachesstats
+
+/*
+ * 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.
+ */
+
+import (
+	"testing"
+	"time"
+
+	"github.com/apache/trafficcontrol/lib/go-tc"
+	"github.com/apache/trafficcontrol/lib/go-util"
+)
+
+func TestAddStatsInvalidString(t *testing.T) {
+	cacheData := make([]CacheData, 0)
+	cacheServerStats := make(map[string]tc.ServerStats, 0)
+	stats := make(map[string][]tc.ResultStatVal, 0)
+	resultStatVals := make([]tc.ResultStatVal, 0)
+	resultStatVal := tc.ResultStatVal{
+		Span: 0,
+		Time: time.Now(),
+		Val:  "invalid bandwidth",

Review comment:
       Yeah, in the bug report is says `panic: (err: interface conversion: interface {} is string, not uint64)`, just was caught offguard by the empty interface being typed as a string. I think this is fine and can be resolved.




----------------------------------------------------------------
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.

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



[GitHub] [trafficcontrol] rawlinp commented on a change in pull request #5600: Adding check for safer conversion between types

Posted by GitBox <gi...@apache.org>.
rawlinp commented on a change in pull request #5600:
URL: https://github.com/apache/trafficcontrol/pull/5600#discussion_r585950615



##########
File path: traffic_ops/traffic_ops_golang/cachesstats/cachesstats.go
##########
@@ -146,11 +146,19 @@ func addStats(cacheData []CacheData, stats tc.Stats) []CacheData {
 		}
 		bandwidth, ok := stat.Stats[tc.StatNameBandwidth]
 		if ok && len(bandwidth) > 0 {
-			cache.KBPS = bandwidth[0].Val.(uint64)
+			cache.KBPS, ok = bandwidth[0].Val.(uint64)

Review comment:
       So when I was looking at this, it seemed like TM was serving this data as strings. If that's the case, we would be hitting this warning case every time. Maybe we need to actually convert the string to a uint64 using `strconv` instead of casting it?




----------------------------------------------------------------
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.

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



[GitHub] [trafficcontrol] TaylorCFrey commented on a change in pull request #5600: Adding check for safer conversion between types

Posted by GitBox <gi...@apache.org>.
TaylorCFrey commented on a change in pull request #5600:
URL: https://github.com/apache/trafficcontrol/pull/5600#discussion_r589839155



##########
File path: traffic_ops/traffic_ops_golang/cachesstats/cachesstats_test.go
##########
@@ -0,0 +1,128 @@
+package cachesstats
+
+/*
+ * 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.
+ */
+
+import (
+	"testing"
+	"time"
+
+	"github.com/apache/trafficcontrol/lib/go-tc"
+	"github.com/apache/trafficcontrol/lib/go-util"
+)
+
+func TestAddStatsInvalidString(t *testing.T) {
+	cacheData := make([]CacheData, 0)
+	cacheServerStats := make(map[string]tc.ServerStats, 0)
+	stats := make(map[string][]tc.ResultStatVal, 0)
+	resultStatVals := make([]tc.ResultStatVal, 0)
+	resultStatVal := tc.ResultStatVal{
+		Span: 0,
+		Time: time.Now(),
+		Val:  "invalid bandwidth",

Review comment:
       Yeah, in the bug report is says `panic: (err: interface conversion: interface {} is string, not uint64)`, just was caught offguard by the empty interface being typed as a string. I think this is fine 👍  and can be resolved.




----------------------------------------------------------------
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.

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



[GitHub] [trafficcontrol] ocket8888 commented on a change in pull request #5600: Adding check for safer conversion between types

Posted by GitBox <gi...@apache.org>.
ocket8888 commented on a change in pull request #5600:
URL: https://github.com/apache/trafficcontrol/pull/5600#discussion_r585952223



##########
File path: traffic_ops/traffic_ops_golang/cachesstats/cachesstats.go
##########
@@ -146,11 +146,19 @@ func addStats(cacheData []CacheData, stats tc.Stats) []CacheData {
 		}
 		bandwidth, ok := stat.Stats[tc.StatNameBandwidth]
 		if ok && len(bandwidth) > 0 {
-			cache.KBPS = bandwidth[0].Val.(uint64)
+			cache.KBPS, ok = bandwidth[0].Val.(uint64)

Review comment:
       On the other hand, was that a breaking API change? Maybe TM should serve integers instead of strings? I'm not sure, though, if/why that changed




----------------------------------------------------------------
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.

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



[GitHub] [trafficcontrol] TaylorCFrey commented on a change in pull request #5600: Adding check for safer conversion between types

Posted by GitBox <gi...@apache.org>.
TaylorCFrey commented on a change in pull request #5600:
URL: https://github.com/apache/trafficcontrol/pull/5600#discussion_r589840379



##########
File path: traffic_ops/traffic_ops_golang/cachesstats/cachesstats.go
##########
@@ -146,11 +147,29 @@ func addStats(cacheData []CacheData, stats tc.Stats) []CacheData {
 		}
 		bandwidth, ok := stat.Stats[tc.StatNameBandwidth]
 		if ok && len(bandwidth) > 0 {
-			cache.KBPS = bandwidth[0].Val.(uint64)

Review comment:
       I recall watching an Uncle Bob video, I believe around architecture, flexibility, etc. and at one point he had effectively removed all types across a boundary in the system and only relied on strings as the format to pass the data across said boundary. I believe, ultimately, his argument against detractors was (I'm completely paraphrasing here) something along the lines of "So long as you have a full test suite, then the data structure/type will be guarded against".
   
   Anyways, 👍 and can be resolved.




----------------------------------------------------------------
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.

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



[GitHub] [trafficcontrol] rawlinp commented on a change in pull request #5600: Adding check for safer conversion between types

Posted by GitBox <gi...@apache.org>.
rawlinp commented on a change in pull request #5600:
URL: https://github.com/apache/trafficcontrol/pull/5600#discussion_r590558778



##########
File path: traffic_ops/traffic_ops_golang/cachesstats/cachesstats.go
##########
@@ -146,11 +147,25 @@ func addStats(cacheData []CacheData, stats tc.Stats) []CacheData {
 		}
 		bandwidth, ok := stat.Stats[tc.StatNameBandwidth]
 		if ok && len(bandwidth) > 0 {
-			cache.KBPS = bandwidth[0].Val.(uint64)
+			if kbps, ok := bandwidth[0].Val.(string); !ok {
+				log.Warnf("couldn't convert %v into string", bandwidth[0].Val)

Review comment:
       These warnings would be hard to troubleshoot with this information. I think it would be helpful to include the `cache.HostName`, which stat we're actually trying to convert, and what URL was used to fetch the data from. For that last one, the URL is actually returned via `GetCacheStats` and `GetLegacyCacheStats`, but we ignore it. Maybe we should pass it into this function and use it in the warnings instead.




----------------------------------------------------------------
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.

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



[GitHub] [trafficcontrol] srijeet0406 commented on a change in pull request #5600: Adding check for safer conversion between types

Posted by GitBox <gi...@apache.org>.
srijeet0406 commented on a change in pull request #5600:
URL: https://github.com/apache/trafficcontrol/pull/5600#discussion_r590696337



##########
File path: traffic_ops/traffic_ops_golang/cachesstats/cachesstats.go
##########
@@ -146,11 +147,25 @@ func addStats(cacheData []CacheData, stats tc.Stats) []CacheData {
 		}
 		bandwidth, ok := stat.Stats[tc.StatNameBandwidth]
 		if ok && len(bandwidth) > 0 {
-			cache.KBPS = bandwidth[0].Val.(uint64)
+			if kbps, ok := bandwidth[0].Val.(string); !ok {
+				log.Warnf("couldn't convert %v into string", bandwidth[0].Val)

Review comment:
       Done




----------------------------------------------------------------
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.

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



[GitHub] [trafficcontrol] rawlinp commented on a change in pull request #5600: Adding check for safer conversion between types

Posted by GitBox <gi...@apache.org>.
rawlinp commented on a change in pull request #5600:
URL: https://github.com/apache/trafficcontrol/pull/5600#discussion_r585955148



##########
File path: traffic_ops/traffic_ops_golang/cachesstats/cachesstats.go
##########
@@ -146,11 +146,19 @@ func addStats(cacheData []CacheData, stats tc.Stats) []CacheData {
 		}
 		bandwidth, ok := stat.Stats[tc.StatNameBandwidth]
 		if ok && len(bandwidth) > 0 {
-			cache.KBPS = bandwidth[0].Val.(uint64)
+			cache.KBPS, ok = bandwidth[0].Val.(uint64)

Review comment:
       I don't know, from the small amount of digging I did, it seemed like the TM API has always served strings.




----------------------------------------------------------------
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.

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



[GitHub] [trafficcontrol] ocket8888 commented on a change in pull request #5600: Adding check for safer conversion between types

Posted by GitBox <gi...@apache.org>.
ocket8888 commented on a change in pull request #5600:
URL: https://github.com/apache/trafficcontrol/pull/5600#discussion_r588839990



##########
File path: traffic_ops/traffic_ops_golang/cachesstats/cachesstats.go
##########
@@ -146,11 +147,29 @@ func addStats(cacheData []CacheData, stats tc.Stats) []CacheData {
 		}
 		bandwidth, ok := stat.Stats[tc.StatNameBandwidth]
 		if ok && len(bandwidth) > 0 {
-			cache.KBPS = bandwidth[0].Val.(uint64)

Review comment:
       TM serves data as strings because it serves many statistics in a totally unstructured way. String is the only type to which it can be guaranteed that all data can be cast or formatted.




----------------------------------------------------------------
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.

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



[GitHub] [trafficcontrol] rawlinp commented on a change in pull request #5600: Adding check for safer conversion between types

Posted by GitBox <gi...@apache.org>.
rawlinp commented on a change in pull request #5600:
URL: https://github.com/apache/trafficcontrol/pull/5600#discussion_r585967242



##########
File path: traffic_ops/traffic_ops_golang/cachesstats/cachesstats.go
##########
@@ -146,11 +146,19 @@ func addStats(cacheData []CacheData, stats tc.Stats) []CacheData {
 		}
 		bandwidth, ok := stat.Stats[tc.StatNameBandwidth]
 		if ok && len(bandwidth) > 0 {
-			cache.KBPS = bandwidth[0].Val.(uint64)
+			cache.KBPS, ok = bandwidth[0].Val.(uint64)

Review comment:
       I believe so. We should `strconv` it




----------------------------------------------------------------
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.

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



[GitHub] [trafficcontrol] srijeet0406 commented on a change in pull request #5600: Adding check for safer conversion between types

Posted by GitBox <gi...@apache.org>.
srijeet0406 commented on a change in pull request #5600:
URL: https://github.com/apache/trafficcontrol/pull/5600#discussion_r585959231



##########
File path: traffic_ops/traffic_ops_golang/cachesstats/cachesstats.go
##########
@@ -146,11 +146,19 @@ func addStats(cacheData []CacheData, stats tc.Stats) []CacheData {
 		}
 		bandwidth, ok := stat.Stats[tc.StatNameBandwidth]
 		if ok && len(bandwidth) > 0 {
-			cache.KBPS = bandwidth[0].Val.(uint64)
+			cache.KBPS, ok = bandwidth[0].Val.(uint64)

Review comment:
       So TM serving strings for stats is expected?




----------------------------------------------------------------
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.

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



[GitHub] [trafficcontrol] rawlinp merged pull request #5600: Adding check for safer conversion between types

Posted by GitBox <gi...@apache.org>.
rawlinp merged pull request #5600:
URL: https://github.com/apache/trafficcontrol/pull/5600


   


----------------------------------------------------------------
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.

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



[GitHub] [trafficcontrol] srijeet0406 commented on a change in pull request #5600: Adding check for safer conversion between types

Posted by GitBox <gi...@apache.org>.
srijeet0406 commented on a change in pull request #5600:
URL: https://github.com/apache/trafficcontrol/pull/5600#discussion_r588832225



##########
File path: traffic_ops/traffic_ops_golang/cachesstats/cachesstats_test.go
##########
@@ -0,0 +1,128 @@
+package cachesstats
+
+/*
+ * 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.
+ */
+
+import (
+	"testing"
+	"time"
+
+	"github.com/apache/trafficcontrol/lib/go-tc"
+	"github.com/apache/trafficcontrol/lib/go-util"
+)
+
+func TestAddStatsInvalidString(t *testing.T) {
+	cacheData := make([]CacheData, 0)
+	cacheServerStats := make(map[string]tc.ServerStats, 0)
+	stats := make(map[string][]tc.ResultStatVal, 0)
+	resultStatVals := make([]tc.ResultStatVal, 0)
+	resultStatVal := tc.ResultStatVal{
+		Span: 0,
+		Time: time.Now(),
+		Val:  "invalid bandwidth",

Review comment:
       I do not have it handy, but I remember that this came up after 5.0 got deployed. I can dig in the TM logs and find another example if you'd like. I did adda test for empty json objects though.

##########
File path: traffic_ops/traffic_ops_golang/cachesstats/cachesstats.go
##########
@@ -146,11 +147,29 @@ func addStats(cacheData []CacheData, stats tc.Stats) []CacheData {
 		}
 		bandwidth, ok := stat.Stats[tc.StatNameBandwidth]
 		if ok && len(bandwidth) > 0 {
-			cache.KBPS = bandwidth[0].Val.(uint64)

Review comment:
       I believe this was caused because TM was serving some strings that could not be converted into uint64's. I'm not really sure why TM serves strings for metrics (not really the TM expert), but yeah, definitely sounds like an effort for betterment (unless I'm missing some TM logic). 

##########
File path: traffic_ops/traffic_ops_golang/cachesstats/cachesstats.go
##########
@@ -146,11 +147,29 @@ func addStats(cacheData []CacheData, stats tc.Stats) []CacheData {
 		}
 		bandwidth, ok := stat.Stats[tc.StatNameBandwidth]
 		if ok && len(bandwidth) > 0 {
-			cache.KBPS = bandwidth[0].Val.(uint64)
+			if kbps, ok := bandwidth[0].Val.(string); !ok {
+				log.Warnf("couldn't convert %v into string", bandwidth[0].Val)
+				continue

Review comment:
       You're correct. Fixed now.




----------------------------------------------------------------
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.

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



[GitHub] [trafficcontrol] TaylorCFrey commented on a change in pull request #5600: Adding check for safer conversion between types

Posted by GitBox <gi...@apache.org>.
TaylorCFrey commented on a change in pull request #5600:
URL: https://github.com/apache/trafficcontrol/pull/5600#discussion_r588770959



##########
File path: traffic_ops/traffic_ops_golang/cachesstats/cachesstats.go
##########
@@ -146,11 +147,29 @@ func addStats(cacheData []CacheData, stats tc.Stats) []CacheData {
 		}
 		bandwidth, ok := stat.Stats[tc.StatNameBandwidth]
 		if ok && len(bandwidth) > 0 {
-			cache.KBPS = bandwidth[0].Val.(uint64)
+			if kbps, ok := bandwidth[0].Val.(string); !ok {
+				log.Warnf("couldn't convert %v into string", bandwidth[0].Val)
+				continue

Review comment:
       So these `continue`s might not quite work the way we expect. Now if it fails it will skip attempting to parse the connections from the Stats. For instance, in the companion test `TestAddStatsInvalidString` it correctly fails to parse the "invalid bandwidth" without crashing, but does not then drop down to test the "invalid ats current connection stat"

##########
File path: traffic_ops/traffic_ops_golang/cachesstats/cachesstats.go
##########
@@ -146,11 +147,29 @@ func addStats(cacheData []CacheData, stats tc.Stats) []CacheData {
 		}
 		bandwidth, ok := stat.Stats[tc.StatNameBandwidth]
 		if ok && len(bandwidth) > 0 {
-			cache.KBPS = bandwidth[0].Val.(uint64)

Review comment:
       I assume these bugs are artifacts for using empty interfaces. Are the empty interfaces necessary? Is it an attempt to add some sort of _generics_ or flexibility? Or can we modify the structs to contain hard data types so our failures happen "earlier" in the processing of a request?
   
   What are your thoughts on this?

##########
File path: traffic_ops/traffic_ops_golang/cachesstats/cachesstats_test.go
##########
@@ -0,0 +1,128 @@
+package cachesstats
+
+/*
+ * 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.
+ */
+
+import (
+	"testing"
+	"time"
+
+	"github.com/apache/trafficcontrol/lib/go-tc"
+	"github.com/apache/trafficcontrol/lib/go-util"
+)
+
+func TestAddStatsInvalidString(t *testing.T) {
+	cacheData := make([]CacheData, 0)
+	cacheServerStats := make(map[string]tc.ServerStats, 0)
+	stats := make(map[string][]tc.ResultStatVal, 0)
+	resultStatVals := make([]tc.ResultStatVal, 0)
+	resultStatVal := tc.ResultStatVal{
+		Span: 0,
+		Time: time.Now(),
+		Val:  "invalid bandwidth",

Review comment:
       Do you happen to have an example of the values that we were actually receiving that was causing this bug? I see in the panic that it considers the interface a string type. Is that what happens when we get an empty JSON object?




----------------------------------------------------------------
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.

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