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/04/09 21:31:11 UTC

[GitHub] [trafficcontrol] TaylorCFrey opened a new pull request #5730: Fixes an issue where multiple interfaces reported by a cache are included in the vitals (bandwidth)

TaylorCFrey opened a new pull request #5730:
URL: https://github.com/apache/trafficcontrol/pull/5730


   
   ## What does this PR (Pull Request) do?
   
   - [X] This PR fixes #5695
   
   ## Which Traffic Control components are affected by this PR?
   
   - Traffic Monitor
   
   ## What is the best way to verify this PR?
   
   Unit tests have been added to the Traffic Monitor project to ensure this logic will work.
   
   `go test apache/trafficcontrol/traffic_monitor/health` must pass
   
   Additionally, verify Traffic Monitor still continues to report Bandwidth as reported in:
   https://github.com/apache/trafficcontrol/issues/5558
   
   ## If this is a bug fix, what versions of Traffic Control are affected?
   
   - master (f8c82a7)
   - 5.1.+
   
   ## The following criteria are ALL met by this PR
   
   - [X] This PR includes tests OR I have explained why tests are unnecessary
   - [ ] This PR includes documentation OR I have explained why documentation is unnecessary
   - [X] This PR includes an update to CHANGELOG.md OR such an update is not necessary
   - [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 #5730: Fixes an issue where multiple interfaces reported by a cache are included in the vitals (bandwidth)

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



##########
File path: traffic_monitor/health/cache_test.go
##########
@@ -33,9 +33,364 @@ import (
 	"github.com/apache/trafficcontrol/lib/go-tc"
 )
 
+// TestNoMonitoredInterfacesGetVitals assures that GetVitals
+// does not fail even if no interfaces are marked to be monitored
+func TestNoMonitoredInterfacesGetVitals(t *testing.T) {
+	serverID := "no-monitored"
+	fakeRequestTime := time.Now()
+	zeroValueVitals := cache.Vitals{}
+
+	// Interfaces to monitor are marked true (none)
+	tmcm := tc.TrafficMonitorConfigMap{
+		TrafficServer: map[string]tc.TrafficServer{
+			serverID: {
+				Interfaces: []tc.ServerInterfaceInfo{
+					{
+						Name:    "bond0",
+						Monitor: false,
+					},
+					{
+						Name:    "bond1",
+						Monitor: false,
+					},
+					{
+						Name:    "lo",
+						Monitor: false,
+					},
+				},
+			},
+		},
+	}
+
+	// multiple interfaces, plus extra
+	firstResult := cache.Result{
+		ID:            serverID,
+		Error:         nil,
+		Miscellaneous: map[string]interface{}{},
+		Statistics: cache.Statistics{
+			Interfaces: map[string]cache.Interface{
+				"bond0": {
+					Speed:    100000,
+					BytesIn:  570791700709,
+					BytesOut: 4212211168526,
+				},
+				"bond1": {
+					Speed:    100000,
+					BytesIn:  1989352297218,
+					BytesOut: 10630690813,
+				},
+				"lo": {
+					Speed:    0,
+					BytesIn:  181882394,
+					BytesOut: 181882394,
+				},
+				"em5": {
+					Speed:    0,
+					BytesIn:  0,
+					BytesOut: 0,
+				},
+			},
+		},
+		Time:            fakeRequestTime,
+		RequestTime:     time.Second,
+		Vitals:          cache.Vitals{},
+		InterfaceVitals: nil,
+		PollID:          42,
+		PollFinished:    make(chan uint64, 1),
+		PrecomputedData: cache.PrecomputedData{},
+		Available:       true,
+		UsingIPv4:       false,
+	}
+	GetVitals(&firstResult, nil, &tmcm)
+
+	// No interfaces were selected to be monitored so none
+	// should have been added later
+	if len(firstResult.InterfaceVitals) > 0 {
+		t.Errorf("InterfaceVitals map should be empty. expected: %v actual: %v:", 0, len(firstResult.InterfaceVitals))
+	}
+
+	// No interfaces were selected to be monitored so no vitals
+	// should have been calculated
+	if firstResult.Vitals != zeroValueVitals {
+		t.Errorf("Vitals should have zero values. expected: %v actual: %v:", zeroValueVitals, firstResult.Vitals)
+	}
+
+	// multiple interfaces, plus extras
+	secondResult := cache.Result{
+		ID:            serverID,
+		Error:         nil,
+		Miscellaneous: map[string]interface{}{},
+		Statistics: cache.Statistics{
+			Interfaces: map[string]cache.Interface{
+				"bond0": {
+					Speed:    100000,
+					BytesIn:  570791700709,
+					BytesOut: 4212211168526,
+				},
+				"bond1": {
+					Speed:    100000,
+					BytesIn:  1989352297218,
+					BytesOut: 10630690813,
+				},
+				"lo": {
+					Speed:    0,
+					BytesIn:  181882394,
+					BytesOut: 181882394,
+				},
+				"em5": {
+					Speed:    0,
+					BytesIn:  0,
+					BytesOut: 0,
+				},
+			},
+		},
+		Time:            fakeRequestTime.Add(5 * time.Second),
+		RequestTime:     time.Second,
+		Vitals:          cache.Vitals{},
+		InterfaceVitals: map[string]cache.Vitals{},
+		PollID:          42,
+		PollFinished:    make(chan uint64, 1),
+		PrecomputedData: cache.PrecomputedData{},
+		Available:       true,
+		UsingIPv4:       false,
+	}
+	GetVitals(&secondResult, &firstResult, &tmcm)
+
+	// No interfaces were selected to be monitored so none
+	// should have been added later
+	if len(secondResult.InterfaceVitals) > 0 {
+		t.Errorf("InterfaceVitals map should be empty. expected: %v actual: %v:", 0, len(secondResult.InterfaceVitals))
+	}
+
+	// No interfaces were selected to be monitored so no vitals
+	// should have been calculated
+	if secondResult.Vitals != zeroValueVitals {
+		t.Errorf("Vitals should have zero values. expected: %v actual: %v:", zeroValueVitals, secondResult.Vitals)
+	}
+
+	// The previous results should not have been impacted
+	if firstResult.Vitals != zeroValueVitals {
+		t.Errorf("Vitals should have zero values. expected: %v actual: %v:", zeroValueVitals, firstResult.Vitals)
+	}
+}
+
+// TestDualHomingMonitoredInterfacesGetVitals ensures cache servers
+// with multiple interfaces correctly calculate bandwidth based on
+// whether the interfaces are marked as "Monitor this interface"
+func TestDualHomingMonitoredInterfacesGetVitals(t *testing.T) {
+
+	serverID := "dual-homed"
+	fakeRequestTime := time.Now()
+
+	// Interfaces to monitor are marked true
+	tmcm := tc.TrafficMonitorConfigMap{
+		TrafficServer: map[string]tc.TrafficServer{
+			serverID: {
+				Interfaces: []tc.ServerInterfaceInfo{
+					{
+						Name:    "bond0",
+						Monitor: true,
+					},
+					{
+						Name:    "bond1",
+						Monitor: true,
+					},
+					{
+						Name:    "lo",
+						Monitor: false,
+					},
+				},
+			},
+		},
+	}
+
+	// multiple interfaces, plus extras
+	firstResult := cache.Result{
+		ID:            serverID,
+		Error:         nil,
+		Miscellaneous: map[string]interface{}{},
+		Statistics: cache.Statistics{
+			Interfaces: map[string]cache.Interface{
+				"bond0": {
+					Speed:    100000,
+					BytesIn:  570791700709,
+					BytesOut: 4212211168526,
+				},
+				"bond1": {
+					Speed:    100000,
+					BytesIn:  1989352297218,
+					BytesOut: 10630690813,
+				},
+				"p1p1": {
+					Speed:    100000,
+					BytesIn:  570793589545,
+					BytesOut: 4212220919951,
+				},
+				"p3p1": {
+					Speed:    100000,
+					BytesIn:  1989354450479,
+					BytesOut: 10630690813,
+				},
+				"lo": {
+					Speed:    0,
+					BytesIn:  181882394,
+					BytesOut: 181882394,
+				},
+				"em5": {
+					Speed:    0,
+					BytesIn:  0,
+					BytesOut: 0,
+				},
+				"em6": {
+					Speed:    0,
+					BytesIn:  0,
+					BytesOut: 0,
+				},
+			},
+		},
+		Time:            fakeRequestTime,
+		RequestTime:     time.Second,
+		Vitals:          cache.Vitals{},
+		InterfaceVitals: nil,
+		PollID:          42,
+		PollFinished:    make(chan uint64, 1),
+		PrecomputedData: cache.PrecomputedData{},
+		Available:       true,
+		UsingIPv4:       false,
+	}
+	GetVitals(&firstResult, nil, &tmcm)
+
+	// Two interfaces were selected to be monitored so they
+	// should have been added later
+	if len(firstResult.InterfaceVitals) != 2 {
+		t.Errorf("InterfaceVitals map should not be empty. expected: %v actual: %v:", 2, len(firstResult.InterfaceVitals))
+	}
+
+	expectedFirstVitals := cache.Vitals{
+		LoadAvg:    0,
+		BytesIn:    2560143997927,
+		BytesOut:   4222841859339,
+		KbpsOut:    0,
+		MaxKbpsOut: 200000000,
+	}
+	// Only two interfaces were selected to be monitored so vitals
+	// should have been calculated based on those two (bond0 and bond1)
+	if firstResult.Vitals != expectedFirstVitals {
+		t.Errorf("Vitals do not match expected output. expected: %v actual: %v:", expectedFirstVitals, firstResult.Vitals)
+	}
+
+	// multiple interfaces, plus extras
+	secondResult := cache.Result{

Review comment:
       Will do.

##########
File path: traffic_monitor/health/cache_test.go
##########
@@ -33,9 +33,364 @@ import (
 	"github.com/apache/trafficcontrol/lib/go-tc"
 )
 
+// TestNoMonitoredInterfacesGetVitals assures that GetVitals
+// does not fail even if no interfaces are marked to be monitored
+func TestNoMonitoredInterfacesGetVitals(t *testing.T) {
+	serverID := "no-monitored"
+	fakeRequestTime := time.Now()
+	zeroValueVitals := cache.Vitals{}
+
+	// Interfaces to monitor are marked true (none)
+	tmcm := tc.TrafficMonitorConfigMap{
+		TrafficServer: map[string]tc.TrafficServer{
+			serverID: {
+				Interfaces: []tc.ServerInterfaceInfo{
+					{
+						Name:    "bond0",
+						Monitor: false,
+					},
+					{
+						Name:    "bond1",
+						Monitor: false,
+					},
+					{
+						Name:    "lo",
+						Monitor: false,
+					},
+				},
+			},
+		},
+	}
+
+	// multiple interfaces, plus extra
+	firstResult := cache.Result{
+		ID:            serverID,
+		Error:         nil,
+		Miscellaneous: map[string]interface{}{},
+		Statistics: cache.Statistics{
+			Interfaces: map[string]cache.Interface{
+				"bond0": {
+					Speed:    100000,
+					BytesIn:  570791700709,
+					BytesOut: 4212211168526,
+				},
+				"bond1": {
+					Speed:    100000,
+					BytesIn:  1989352297218,
+					BytesOut: 10630690813,
+				},
+				"lo": {
+					Speed:    0,
+					BytesIn:  181882394,
+					BytesOut: 181882394,
+				},
+				"em5": {
+					Speed:    0,
+					BytesIn:  0,
+					BytesOut: 0,
+				},
+			},
+		},
+		Time:            fakeRequestTime,
+		RequestTime:     time.Second,
+		Vitals:          cache.Vitals{},
+		InterfaceVitals: nil,
+		PollID:          42,
+		PollFinished:    make(chan uint64, 1),
+		PrecomputedData: cache.PrecomputedData{},
+		Available:       true,
+		UsingIPv4:       false,
+	}
+	GetVitals(&firstResult, nil, &tmcm)
+
+	// No interfaces were selected to be monitored so none
+	// should have been added later
+	if len(firstResult.InterfaceVitals) > 0 {
+		t.Errorf("InterfaceVitals map should be empty. expected: %v actual: %v:", 0, len(firstResult.InterfaceVitals))
+	}
+
+	// No interfaces were selected to be monitored so no vitals
+	// should have been calculated
+	if firstResult.Vitals != zeroValueVitals {
+		t.Errorf("Vitals should have zero values. expected: %v actual: %v:", zeroValueVitals, firstResult.Vitals)
+	}
+
+	// multiple interfaces, plus extras
+	secondResult := cache.Result{

Review comment:
       Will do.




-- 
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 #5730: Fixes an issue where multiple interfaces reported by a cache are included in the vitals (bandwidth)

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



##########
File path: traffic_monitor/health/cache.go
##########
@@ -53,14 +53,44 @@ func GetVitals(newResult *cache.Result, prevResult *cache.Result, mc *tc.Traffic
 		return
 	}
 
+	if mc == nil {
+		log.Errorf("mc TrafficMonitorConfigMap cannot be nil")

Review comment:
       Will remove.

##########
File path: CHANGELOG.md
##########
@@ -49,8 +49,10 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
 - [#5405](https://github.com/apache/trafficcontrol/issues/5405) - Prevent Tenant update from choosing child as new parent
 - [#5384](https://github.com/apache/trafficcontrol/issues/5384) - New grids will now properly remember the current page number.
 - [#5548](https://github.com/apache/trafficcontrol/issues/5548) - Don't return a `403 Forbidden` when the user tries to get servers of a non-existent DS using `GET /servers?dsId={{nonexistent DS ID}}`
+- [#5695](https://github.com/apache/trafficcontrol/issues/5695) - Ensure vitals are calculated only against monitored interfaces
 - [#5724](https://github.com/apache/trafficcontrol/issues/5724) - Set XMPPID to hostname if the server had none, don't error on server update when XMPPID is empty
 
+

Review comment:
       Will remove.




-- 
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 #5730: Fixes an issue where multiple interfaces reported by a cache are included in the vitals (bandwidth)

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



##########
File path: CHANGELOG.md
##########
@@ -49,8 +49,10 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
 - [#5405](https://github.com/apache/trafficcontrol/issues/5405) - Prevent Tenant update from choosing child as new parent
 - [#5384](https://github.com/apache/trafficcontrol/issues/5384) - New grids will now properly remember the current page number.
 - [#5548](https://github.com/apache/trafficcontrol/issues/5548) - Don't return a `403 Forbidden` when the user tries to get servers of a non-existent DS using `GET /servers?dsId={{nonexistent DS ID}}`
+- [#5695](https://github.com/apache/trafficcontrol/issues/5695) - Ensure vitals are calculated only against monitored interfaces
 - [#5724](https://github.com/apache/trafficcontrol/issues/5724) - Set XMPPID to hostname if the server had none, don't error on server update when XMPPID is empty
 
+

Review comment:
       nit: Extra blank line

##########
File path: traffic_monitor/health/cache.go
##########
@@ -53,14 +53,44 @@ func GetVitals(newResult *cache.Result, prevResult *cache.Result, mc *tc.Traffic
 		return
 	}
 
+	if mc == nil {
+		log.Errorf("mc TrafficMonitorConfigMap cannot be nil")

Review comment:
       The word `mc` might not make much sense in the logs.

##########
File path: traffic_monitor/health/cache.go
##########
@@ -53,14 +53,44 @@ func GetVitals(newResult *cache.Result, prevResult *cache.Result, mc *tc.Traffic
 		return
 	}
 
+	if mc == nil {
+		log.Errorf("mc TrafficMonitorConfigMap cannot be nil")
+		return
+	}
+
 	if newResult.InterfaceVitals == nil {
 		newResult.InterfaceVitals = map[string]cache.Vitals{}
 	}
 
 	// proc.loadavg -- we're using the 1 minute average (!?)
 	newResult.Vitals.LoadAvg = newResult.Statistics.Loadavg.One
 
-	for ifaceName, iface := range newResult.Interfaces() {
+	if mc.TrafficServer[newResult.ID].Interfaces == nil {

Review comment:
       Could you add some checks here to see that the length of `mc.TrafficServer` is not 0, and also to make sure that `mc.TrafficServer` has the key `newResult.ID`?

##########
File path: traffic_monitor/health/cache_test.go
##########
@@ -33,9 +33,364 @@ import (
 	"github.com/apache/trafficcontrol/lib/go-tc"
 )
 
+// TestNoMonitoredInterfacesGetVitals assures that GetVitals
+// does not fail even if no interfaces are marked to be monitored
+func TestNoMonitoredInterfacesGetVitals(t *testing.T) {
+	serverID := "no-monitored"
+	fakeRequestTime := time.Now()
+	zeroValueVitals := cache.Vitals{}
+
+	// Interfaces to monitor are marked true (none)
+	tmcm := tc.TrafficMonitorConfigMap{
+		TrafficServer: map[string]tc.TrafficServer{
+			serverID: {
+				Interfaces: []tc.ServerInterfaceInfo{
+					{
+						Name:    "bond0",
+						Monitor: false,
+					},
+					{
+						Name:    "bond1",
+						Monitor: false,
+					},
+					{
+						Name:    "lo",
+						Monitor: false,
+					},
+				},
+			},
+		},
+	}
+
+	// multiple interfaces, plus extra
+	firstResult := cache.Result{
+		ID:            serverID,
+		Error:         nil,
+		Miscellaneous: map[string]interface{}{},
+		Statistics: cache.Statistics{
+			Interfaces: map[string]cache.Interface{
+				"bond0": {
+					Speed:    100000,
+					BytesIn:  570791700709,
+					BytesOut: 4212211168526,
+				},
+				"bond1": {
+					Speed:    100000,
+					BytesIn:  1989352297218,
+					BytesOut: 10630690813,
+				},
+				"lo": {
+					Speed:    0,
+					BytesIn:  181882394,
+					BytesOut: 181882394,
+				},
+				"em5": {
+					Speed:    0,
+					BytesIn:  0,
+					BytesOut: 0,
+				},
+			},
+		},
+		Time:            fakeRequestTime,
+		RequestTime:     time.Second,
+		Vitals:          cache.Vitals{},
+		InterfaceVitals: nil,
+		PollID:          42,
+		PollFinished:    make(chan uint64, 1),
+		PrecomputedData: cache.PrecomputedData{},
+		Available:       true,
+		UsingIPv4:       false,
+	}
+	GetVitals(&firstResult, nil, &tmcm)
+
+	// No interfaces were selected to be monitored so none
+	// should have been added later
+	if len(firstResult.InterfaceVitals) > 0 {
+		t.Errorf("InterfaceVitals map should be empty. expected: %v actual: %v:", 0, len(firstResult.InterfaceVitals))
+	}
+
+	// No interfaces were selected to be monitored so no vitals
+	// should have been calculated
+	if firstResult.Vitals != zeroValueVitals {
+		t.Errorf("Vitals should have zero values. expected: %v actual: %v:", zeroValueVitals, firstResult.Vitals)
+	}
+
+	// multiple interfaces, plus extras
+	secondResult := cache.Result{

Review comment:
       Instead of rewriting the whole struct here, can we just take `firstResult`, copy it into `secondResult` and modify just the required fields?

##########
File path: traffic_monitor/health/cache.go
##########
@@ -53,14 +53,44 @@ func GetVitals(newResult *cache.Result, prevResult *cache.Result, mc *tc.Traffic
 		return
 	}
 
+	if mc == nil {
+		log.Errorf("mc TrafficMonitorConfigMap cannot be nil")
+		return
+	}
+
 	if newResult.InterfaceVitals == nil {
 		newResult.InterfaceVitals = map[string]cache.Vitals{}
 	}
 
 	// proc.loadavg -- we're using the 1 minute average (!?)
 	newResult.Vitals.LoadAvg = newResult.Statistics.Loadavg.One
 
-	for ifaceName, iface := range newResult.Interfaces() {
+	if mc.TrafficServer[newResult.ID].Interfaces == nil {
+		log.Debugf("no interfaces reported in config map to be monitored")
+		return
+	}
+
+	var monitoredInterfaces []tc.ServerInterfaceInfo

Review comment:
       Just a general question with respect to the `lo` interface. Could we ever have a case where the `lo` interface is marked as `Monitor this interface`? And in that case, should we be including the `lo` interface stats? 

##########
File path: traffic_monitor/health/cache.go
##########
@@ -53,14 +53,44 @@ func GetVitals(newResult *cache.Result, prevResult *cache.Result, mc *tc.Traffic
 		return
 	}
 
+	if mc == nil {
+		log.Errorf("mc TrafficMonitorConfigMap cannot be nil")
+		return
+	}
+
 	if newResult.InterfaceVitals == nil {
 		newResult.InterfaceVitals = map[string]cache.Vitals{}
 	}
 
 	// proc.loadavg -- we're using the 1 minute average (!?)
 	newResult.Vitals.LoadAvg = newResult.Statistics.Loadavg.One
 
-	for ifaceName, iface := range newResult.Interfaces() {
+	if mc.TrafficServer[newResult.ID].Interfaces == nil {
+		log.Debugf("no interfaces reported in config map to be monitored")
+		return
+	}
+
+	var monitoredInterfaces []tc.ServerInterfaceInfo
+	for _, srvrIfaceInfo := range mc.TrafficServer[newResult.ID].Interfaces {
+		if srvrIfaceInfo.Monitor {
+			monitoredInterfaces = append(monitoredInterfaces, srvrIfaceInfo)
+		}
+	}
+
+	if len(monitoredInterfaces) == 0 {
+		log.Debugf("no interfaces selected to be monitored for %v", newResult.ID)
+		return
+	}
+
+	for _, monitoredInterface := range monitoredInterfaces {
+		ifaceName := monitoredInterface.Name
+		iface, exists := newResult.Interfaces()[ifaceName]
+		if !exists {
+			// monitored interface doesn't exist in Result interfaces, skip
+			log.Warnf("monitored interface %v does not exist in %v cache.Result.Interfaces()", ifaceName, newResult.ID)

Review comment:
       Do you think this log line would read better as:
   `log.Warnf("monitored interface %v does not exist in cache %v", ifaceName, newResult.ID)`?

##########
File path: traffic_monitor/health/cache.go
##########
@@ -53,14 +53,44 @@ func GetVitals(newResult *cache.Result, prevResult *cache.Result, mc *tc.Traffic
 		return
 	}
 
+	if mc == nil {
+		log.Errorf("mc TrafficMonitorConfigMap cannot be nil")
+		return
+	}
+
 	if newResult.InterfaceVitals == nil {
 		newResult.InterfaceVitals = map[string]cache.Vitals{}
 	}
 
 	// proc.loadavg -- we're using the 1 minute average (!?)
 	newResult.Vitals.LoadAvg = newResult.Statistics.Loadavg.One
 
-	for ifaceName, iface := range newResult.Interfaces() {
+	if mc.TrafficServer[newResult.ID].Interfaces == nil {
+		log.Debugf("no interfaces reported in config map to be monitored")
+		return
+	}
+
+	var monitoredInterfaces []tc.ServerInterfaceInfo
+	for _, srvrIfaceInfo := range mc.TrafficServer[newResult.ID].Interfaces {
+		if srvrIfaceInfo.Monitor {
+			monitoredInterfaces = append(monitoredInterfaces, srvrIfaceInfo)
+		}
+	}
+
+	if len(monitoredInterfaces) == 0 {
+		log.Debugf("no interfaces selected to be monitored for %v", newResult.ID)
+		return
+	}
+
+	for _, monitoredInterface := range monitoredInterfaces {
+		ifaceName := monitoredInterface.Name
+		iface, exists := newResult.Interfaces()[ifaceName]

Review comment:
       Maybe add some similar checks here like my last comment^^

##########
File path: traffic_monitor/health/cache_test.go
##########
@@ -33,9 +33,364 @@ import (
 	"github.com/apache/trafficcontrol/lib/go-tc"
 )
 
+// TestNoMonitoredInterfacesGetVitals assures that GetVitals
+// does not fail even if no interfaces are marked to be monitored
+func TestNoMonitoredInterfacesGetVitals(t *testing.T) {
+	serverID := "no-monitored"
+	fakeRequestTime := time.Now()
+	zeroValueVitals := cache.Vitals{}
+
+	// Interfaces to monitor are marked true (none)
+	tmcm := tc.TrafficMonitorConfigMap{
+		TrafficServer: map[string]tc.TrafficServer{
+			serverID: {
+				Interfaces: []tc.ServerInterfaceInfo{
+					{
+						Name:    "bond0",
+						Monitor: false,
+					},
+					{
+						Name:    "bond1",
+						Monitor: false,
+					},
+					{
+						Name:    "lo",
+						Monitor: false,
+					},
+				},
+			},
+		},
+	}
+
+	// multiple interfaces, plus extra
+	firstResult := cache.Result{
+		ID:            serverID,
+		Error:         nil,
+		Miscellaneous: map[string]interface{}{},
+		Statistics: cache.Statistics{
+			Interfaces: map[string]cache.Interface{
+				"bond0": {
+					Speed:    100000,
+					BytesIn:  570791700709,
+					BytesOut: 4212211168526,
+				},
+				"bond1": {
+					Speed:    100000,
+					BytesIn:  1989352297218,
+					BytesOut: 10630690813,
+				},
+				"lo": {
+					Speed:    0,
+					BytesIn:  181882394,
+					BytesOut: 181882394,
+				},
+				"em5": {
+					Speed:    0,
+					BytesIn:  0,
+					BytesOut: 0,
+				},
+			},
+		},
+		Time:            fakeRequestTime,
+		RequestTime:     time.Second,
+		Vitals:          cache.Vitals{},
+		InterfaceVitals: nil,
+		PollID:          42,
+		PollFinished:    make(chan uint64, 1),
+		PrecomputedData: cache.PrecomputedData{},
+		Available:       true,
+		UsingIPv4:       false,
+	}
+	GetVitals(&firstResult, nil, &tmcm)
+
+	// No interfaces were selected to be monitored so none
+	// should have been added later
+	if len(firstResult.InterfaceVitals) > 0 {
+		t.Errorf("InterfaceVitals map should be empty. expected: %v actual: %v:", 0, len(firstResult.InterfaceVitals))
+	}
+
+	// No interfaces were selected to be monitored so no vitals
+	// should have been calculated
+	if firstResult.Vitals != zeroValueVitals {
+		t.Errorf("Vitals should have zero values. expected: %v actual: %v:", zeroValueVitals, firstResult.Vitals)
+	}
+
+	// multiple interfaces, plus extras
+	secondResult := cache.Result{
+		ID:            serverID,
+		Error:         nil,
+		Miscellaneous: map[string]interface{}{},
+		Statistics: cache.Statistics{
+			Interfaces: map[string]cache.Interface{
+				"bond0": {
+					Speed:    100000,
+					BytesIn:  570791700709,
+					BytesOut: 4212211168526,
+				},
+				"bond1": {
+					Speed:    100000,
+					BytesIn:  1989352297218,
+					BytesOut: 10630690813,
+				},
+				"lo": {
+					Speed:    0,
+					BytesIn:  181882394,
+					BytesOut: 181882394,
+				},
+				"em5": {
+					Speed:    0,
+					BytesIn:  0,
+					BytesOut: 0,
+				},
+			},
+		},
+		Time:            fakeRequestTime.Add(5 * time.Second),
+		RequestTime:     time.Second,
+		Vitals:          cache.Vitals{},
+		InterfaceVitals: map[string]cache.Vitals{},
+		PollID:          42,
+		PollFinished:    make(chan uint64, 1),
+		PrecomputedData: cache.PrecomputedData{},
+		Available:       true,
+		UsingIPv4:       false,
+	}
+	GetVitals(&secondResult, &firstResult, &tmcm)
+
+	// No interfaces were selected to be monitored so none
+	// should have been added later
+	if len(secondResult.InterfaceVitals) > 0 {
+		t.Errorf("InterfaceVitals map should be empty. expected: %v actual: %v:", 0, len(secondResult.InterfaceVitals))
+	}
+
+	// No interfaces were selected to be monitored so no vitals
+	// should have been calculated
+	if secondResult.Vitals != zeroValueVitals {
+		t.Errorf("Vitals should have zero values. expected: %v actual: %v:", zeroValueVitals, secondResult.Vitals)
+	}
+
+	// The previous results should not have been impacted
+	if firstResult.Vitals != zeroValueVitals {
+		t.Errorf("Vitals should have zero values. expected: %v actual: %v:", zeroValueVitals, firstResult.Vitals)
+	}
+}
+
+// TestDualHomingMonitoredInterfacesGetVitals ensures cache servers
+// with multiple interfaces correctly calculate bandwidth based on
+// whether the interfaces are marked as "Monitor this interface"
+func TestDualHomingMonitoredInterfacesGetVitals(t *testing.T) {
+
+	serverID := "dual-homed"
+	fakeRequestTime := time.Now()
+
+	// Interfaces to monitor are marked true
+	tmcm := tc.TrafficMonitorConfigMap{
+		TrafficServer: map[string]tc.TrafficServer{
+			serverID: {
+				Interfaces: []tc.ServerInterfaceInfo{
+					{
+						Name:    "bond0",
+						Monitor: true,
+					},
+					{
+						Name:    "bond1",
+						Monitor: true,
+					},
+					{
+						Name:    "lo",
+						Monitor: false,
+					},
+				},
+			},
+		},
+	}
+
+	// multiple interfaces, plus extras
+	firstResult := cache.Result{
+		ID:            serverID,
+		Error:         nil,
+		Miscellaneous: map[string]interface{}{},
+		Statistics: cache.Statistics{
+			Interfaces: map[string]cache.Interface{
+				"bond0": {
+					Speed:    100000,
+					BytesIn:  570791700709,
+					BytesOut: 4212211168526,
+				},
+				"bond1": {
+					Speed:    100000,
+					BytesIn:  1989352297218,
+					BytesOut: 10630690813,
+				},
+				"p1p1": {
+					Speed:    100000,
+					BytesIn:  570793589545,
+					BytesOut: 4212220919951,
+				},
+				"p3p1": {
+					Speed:    100000,
+					BytesIn:  1989354450479,
+					BytesOut: 10630690813,
+				},
+				"lo": {
+					Speed:    0,
+					BytesIn:  181882394,
+					BytesOut: 181882394,
+				},
+				"em5": {
+					Speed:    0,
+					BytesIn:  0,
+					BytesOut: 0,
+				},
+				"em6": {
+					Speed:    0,
+					BytesIn:  0,
+					BytesOut: 0,
+				},
+			},
+		},
+		Time:            fakeRequestTime,
+		RequestTime:     time.Second,
+		Vitals:          cache.Vitals{},
+		InterfaceVitals: nil,
+		PollID:          42,
+		PollFinished:    make(chan uint64, 1),
+		PrecomputedData: cache.PrecomputedData{},
+		Available:       true,
+		UsingIPv4:       false,
+	}
+	GetVitals(&firstResult, nil, &tmcm)
+
+	// Two interfaces were selected to be monitored so they
+	// should have been added later
+	if len(firstResult.InterfaceVitals) != 2 {
+		t.Errorf("InterfaceVitals map should not be empty. expected: %v actual: %v:", 2, len(firstResult.InterfaceVitals))
+	}
+
+	expectedFirstVitals := cache.Vitals{
+		LoadAvg:    0,
+		BytesIn:    2560143997927,
+		BytesOut:   4222841859339,
+		KbpsOut:    0,
+		MaxKbpsOut: 200000000,
+	}
+	// Only two interfaces were selected to be monitored so vitals
+	// should have been calculated based on those two (bond0 and bond1)
+	if firstResult.Vitals != expectedFirstVitals {
+		t.Errorf("Vitals do not match expected output. expected: %v actual: %v:", expectedFirstVitals, firstResult.Vitals)
+	}
+
+	// multiple interfaces, plus extras
+	secondResult := cache.Result{

Review comment:
       Same comment here.




-- 
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 #5730: Fixes an issue where multiple interfaces reported by a cache are included in the vitals (bandwidth)

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



##########
File path: traffic_monitor/health/cache.go
##########
@@ -53,14 +53,44 @@ func GetVitals(newResult *cache.Result, prevResult *cache.Result, mc *tc.Traffic
 		return
 	}
 
+	if mc == nil {
+		log.Errorf("mc TrafficMonitorConfigMap cannot be nil")
+		return
+	}
+
 	if newResult.InterfaceVitals == nil {
 		newResult.InterfaceVitals = map[string]cache.Vitals{}
 	}
 
 	// proc.loadavg -- we're using the 1 minute average (!?)
 	newResult.Vitals.LoadAvg = newResult.Statistics.Loadavg.One
 
-	for ifaceName, iface := range newResult.Interfaces() {
+	if mc.TrafficServer[newResult.ID].Interfaces == nil {

Review comment:
       Done

##########
File path: traffic_monitor/health/cache.go
##########
@@ -53,14 +53,44 @@ func GetVitals(newResult *cache.Result, prevResult *cache.Result, mc *tc.Traffic
 		return
 	}
 
+	if mc == nil {
+		log.Errorf("mc TrafficMonitorConfigMap cannot be nil")
+		return
+	}
+
 	if newResult.InterfaceVitals == nil {
 		newResult.InterfaceVitals = map[string]cache.Vitals{}
 	}
 
 	// proc.loadavg -- we're using the 1 minute average (!?)
 	newResult.Vitals.LoadAvg = newResult.Statistics.Loadavg.One
 
-	for ifaceName, iface := range newResult.Interfaces() {
+	if mc.TrafficServer[newResult.ID].Interfaces == nil {
+		log.Debugf("no interfaces reported in config map to be monitored")
+		return
+	}
+
+	var monitoredInterfaces []tc.ServerInterfaceInfo
+	for _, srvrIfaceInfo := range mc.TrafficServer[newResult.ID].Interfaces {
+		if srvrIfaceInfo.Monitor {
+			monitoredInterfaces = append(monitoredInterfaces, srvrIfaceInfo)
+		}
+	}
+
+	if len(monitoredInterfaces) == 0 {
+		log.Debugf("no interfaces selected to be monitored for %v", newResult.ID)
+		return
+	}
+
+	for _, monitoredInterface := range monitoredInterfaces {
+		ifaceName := monitoredInterface.Name
+		iface, exists := newResult.Interfaces()[ifaceName]
+		if !exists {
+			// monitored interface doesn't exist in Result interfaces, skip
+			log.Warnf("monitored interface %v does not exist in %v cache.Result.Interfaces()", ifaceName, newResult.ID)

Review comment:
       Done

##########
File path: traffic_monitor/health/cache_test.go
##########
@@ -33,9 +33,364 @@ import (
 	"github.com/apache/trafficcontrol/lib/go-tc"
 )
 
+// TestNoMonitoredInterfacesGetVitals assures that GetVitals
+// does not fail even if no interfaces are marked to be monitored
+func TestNoMonitoredInterfacesGetVitals(t *testing.T) {
+	serverID := "no-monitored"
+	fakeRequestTime := time.Now()
+	zeroValueVitals := cache.Vitals{}
+
+	// Interfaces to monitor are marked true (none)
+	tmcm := tc.TrafficMonitorConfigMap{
+		TrafficServer: map[string]tc.TrafficServer{
+			serverID: {
+				Interfaces: []tc.ServerInterfaceInfo{
+					{
+						Name:    "bond0",
+						Monitor: false,
+					},
+					{
+						Name:    "bond1",
+						Monitor: false,
+					},
+					{
+						Name:    "lo",
+						Monitor: false,
+					},
+				},
+			},
+		},
+	}
+
+	// multiple interfaces, plus extra
+	firstResult := cache.Result{
+		ID:            serverID,
+		Error:         nil,
+		Miscellaneous: map[string]interface{}{},
+		Statistics: cache.Statistics{
+			Interfaces: map[string]cache.Interface{
+				"bond0": {
+					Speed:    100000,
+					BytesIn:  570791700709,
+					BytesOut: 4212211168526,
+				},
+				"bond1": {
+					Speed:    100000,
+					BytesIn:  1989352297218,
+					BytesOut: 10630690813,
+				},
+				"lo": {
+					Speed:    0,
+					BytesIn:  181882394,
+					BytesOut: 181882394,
+				},
+				"em5": {
+					Speed:    0,
+					BytesIn:  0,
+					BytesOut: 0,
+				},
+			},
+		},
+		Time:            fakeRequestTime,
+		RequestTime:     time.Second,
+		Vitals:          cache.Vitals{},
+		InterfaceVitals: nil,
+		PollID:          42,
+		PollFinished:    make(chan uint64, 1),
+		PrecomputedData: cache.PrecomputedData{},
+		Available:       true,
+		UsingIPv4:       false,
+	}
+	GetVitals(&firstResult, nil, &tmcm)
+
+	// No interfaces were selected to be monitored so none
+	// should have been added later
+	if len(firstResult.InterfaceVitals) > 0 {
+		t.Errorf("InterfaceVitals map should be empty. expected: %v actual: %v:", 0, len(firstResult.InterfaceVitals))
+	}
+
+	// No interfaces were selected to be monitored so no vitals
+	// should have been calculated
+	if firstResult.Vitals != zeroValueVitals {
+		t.Errorf("Vitals should have zero values. expected: %v actual: %v:", zeroValueVitals, firstResult.Vitals)
+	}
+
+	// multiple interfaces, plus extras
+	secondResult := cache.Result{

Review comment:
       Done

##########
File path: traffic_monitor/health/cache_test.go
##########
@@ -33,9 +33,364 @@ import (
 	"github.com/apache/trafficcontrol/lib/go-tc"
 )
 
+// TestNoMonitoredInterfacesGetVitals assures that GetVitals
+// does not fail even if no interfaces are marked to be monitored
+func TestNoMonitoredInterfacesGetVitals(t *testing.T) {
+	serverID := "no-monitored"
+	fakeRequestTime := time.Now()
+	zeroValueVitals := cache.Vitals{}
+
+	// Interfaces to monitor are marked true (none)
+	tmcm := tc.TrafficMonitorConfigMap{
+		TrafficServer: map[string]tc.TrafficServer{
+			serverID: {
+				Interfaces: []tc.ServerInterfaceInfo{
+					{
+						Name:    "bond0",
+						Monitor: false,
+					},
+					{
+						Name:    "bond1",
+						Monitor: false,
+					},
+					{
+						Name:    "lo",
+						Monitor: false,
+					},
+				},
+			},
+		},
+	}
+
+	// multiple interfaces, plus extra
+	firstResult := cache.Result{
+		ID:            serverID,
+		Error:         nil,
+		Miscellaneous: map[string]interface{}{},
+		Statistics: cache.Statistics{
+			Interfaces: map[string]cache.Interface{
+				"bond0": {
+					Speed:    100000,
+					BytesIn:  570791700709,
+					BytesOut: 4212211168526,
+				},
+				"bond1": {
+					Speed:    100000,
+					BytesIn:  1989352297218,
+					BytesOut: 10630690813,
+				},
+				"lo": {
+					Speed:    0,
+					BytesIn:  181882394,
+					BytesOut: 181882394,
+				},
+				"em5": {
+					Speed:    0,
+					BytesIn:  0,
+					BytesOut: 0,
+				},
+			},
+		},
+		Time:            fakeRequestTime,
+		RequestTime:     time.Second,
+		Vitals:          cache.Vitals{},
+		InterfaceVitals: nil,
+		PollID:          42,
+		PollFinished:    make(chan uint64, 1),
+		PrecomputedData: cache.PrecomputedData{},
+		Available:       true,
+		UsingIPv4:       false,
+	}
+	GetVitals(&firstResult, nil, &tmcm)
+
+	// No interfaces were selected to be monitored so none
+	// should have been added later
+	if len(firstResult.InterfaceVitals) > 0 {
+		t.Errorf("InterfaceVitals map should be empty. expected: %v actual: %v:", 0, len(firstResult.InterfaceVitals))
+	}
+
+	// No interfaces were selected to be monitored so no vitals
+	// should have been calculated
+	if firstResult.Vitals != zeroValueVitals {
+		t.Errorf("Vitals should have zero values. expected: %v actual: %v:", zeroValueVitals, firstResult.Vitals)
+	}
+
+	// multiple interfaces, plus extras
+	secondResult := cache.Result{
+		ID:            serverID,
+		Error:         nil,
+		Miscellaneous: map[string]interface{}{},
+		Statistics: cache.Statistics{
+			Interfaces: map[string]cache.Interface{
+				"bond0": {
+					Speed:    100000,
+					BytesIn:  570791700709,
+					BytesOut: 4212211168526,
+				},
+				"bond1": {
+					Speed:    100000,
+					BytesIn:  1989352297218,
+					BytesOut: 10630690813,
+				},
+				"lo": {
+					Speed:    0,
+					BytesIn:  181882394,
+					BytesOut: 181882394,
+				},
+				"em5": {
+					Speed:    0,
+					BytesIn:  0,
+					BytesOut: 0,
+				},
+			},
+		},
+		Time:            fakeRequestTime.Add(5 * time.Second),
+		RequestTime:     time.Second,
+		Vitals:          cache.Vitals{},
+		InterfaceVitals: map[string]cache.Vitals{},
+		PollID:          42,
+		PollFinished:    make(chan uint64, 1),
+		PrecomputedData: cache.PrecomputedData{},
+		Available:       true,
+		UsingIPv4:       false,
+	}
+	GetVitals(&secondResult, &firstResult, &tmcm)
+
+	// No interfaces were selected to be monitored so none
+	// should have been added later
+	if len(secondResult.InterfaceVitals) > 0 {
+		t.Errorf("InterfaceVitals map should be empty. expected: %v actual: %v:", 0, len(secondResult.InterfaceVitals))
+	}
+
+	// No interfaces were selected to be monitored so no vitals
+	// should have been calculated
+	if secondResult.Vitals != zeroValueVitals {
+		t.Errorf("Vitals should have zero values. expected: %v actual: %v:", zeroValueVitals, secondResult.Vitals)
+	}
+
+	// The previous results should not have been impacted
+	if firstResult.Vitals != zeroValueVitals {
+		t.Errorf("Vitals should have zero values. expected: %v actual: %v:", zeroValueVitals, firstResult.Vitals)
+	}
+}
+
+// TestDualHomingMonitoredInterfacesGetVitals ensures cache servers
+// with multiple interfaces correctly calculate bandwidth based on
+// whether the interfaces are marked as "Monitor this interface"
+func TestDualHomingMonitoredInterfacesGetVitals(t *testing.T) {
+
+	serverID := "dual-homed"
+	fakeRequestTime := time.Now()
+
+	// Interfaces to monitor are marked true
+	tmcm := tc.TrafficMonitorConfigMap{
+		TrafficServer: map[string]tc.TrafficServer{
+			serverID: {
+				Interfaces: []tc.ServerInterfaceInfo{
+					{
+						Name:    "bond0",
+						Monitor: true,
+					},
+					{
+						Name:    "bond1",
+						Monitor: true,
+					},
+					{
+						Name:    "lo",
+						Monitor: false,
+					},
+				},
+			},
+		},
+	}
+
+	// multiple interfaces, plus extras
+	firstResult := cache.Result{
+		ID:            serverID,
+		Error:         nil,
+		Miscellaneous: map[string]interface{}{},
+		Statistics: cache.Statistics{
+			Interfaces: map[string]cache.Interface{
+				"bond0": {
+					Speed:    100000,
+					BytesIn:  570791700709,
+					BytesOut: 4212211168526,
+				},
+				"bond1": {
+					Speed:    100000,
+					BytesIn:  1989352297218,
+					BytesOut: 10630690813,
+				},
+				"p1p1": {
+					Speed:    100000,
+					BytesIn:  570793589545,
+					BytesOut: 4212220919951,
+				},
+				"p3p1": {
+					Speed:    100000,
+					BytesIn:  1989354450479,
+					BytesOut: 10630690813,
+				},
+				"lo": {
+					Speed:    0,
+					BytesIn:  181882394,
+					BytesOut: 181882394,
+				},
+				"em5": {
+					Speed:    0,
+					BytesIn:  0,
+					BytesOut: 0,
+				},
+				"em6": {
+					Speed:    0,
+					BytesIn:  0,
+					BytesOut: 0,
+				},
+			},
+		},
+		Time:            fakeRequestTime,
+		RequestTime:     time.Second,
+		Vitals:          cache.Vitals{},
+		InterfaceVitals: nil,
+		PollID:          42,
+		PollFinished:    make(chan uint64, 1),
+		PrecomputedData: cache.PrecomputedData{},
+		Available:       true,
+		UsingIPv4:       false,
+	}
+	GetVitals(&firstResult, nil, &tmcm)
+
+	// Two interfaces were selected to be monitored so they
+	// should have been added later
+	if len(firstResult.InterfaceVitals) != 2 {
+		t.Errorf("InterfaceVitals map should not be empty. expected: %v actual: %v:", 2, len(firstResult.InterfaceVitals))
+	}
+
+	expectedFirstVitals := cache.Vitals{
+		LoadAvg:    0,
+		BytesIn:    2560143997927,
+		BytesOut:   4222841859339,
+		KbpsOut:    0,
+		MaxKbpsOut: 200000000,
+	}
+	// Only two interfaces were selected to be monitored so vitals
+	// should have been calculated based on those two (bond0 and bond1)
+	if firstResult.Vitals != expectedFirstVitals {
+		t.Errorf("Vitals do not match expected output. expected: %v actual: %v:", expectedFirstVitals, firstResult.Vitals)
+	}
+
+	// multiple interfaces, plus extras
+	secondResult := cache.Result{

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] TaylorCFrey commented on a change in pull request #5730: Fixes an issue where multiple interfaces reported by a cache are included in the vitals (bandwidth)

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



##########
File path: traffic_monitor/health/cache.go
##########
@@ -53,14 +53,44 @@ func GetVitals(newResult *cache.Result, prevResult *cache.Result, mc *tc.Traffic
 		return
 	}
 
+	if mc == nil {
+		log.Errorf("mc TrafficMonitorConfigMap cannot be nil")
+		return
+	}
+
 	if newResult.InterfaceVitals == nil {
 		newResult.InterfaceVitals = map[string]cache.Vitals{}
 	}
 
 	// proc.loadavg -- we're using the 1 minute average (!?)
 	newResult.Vitals.LoadAvg = newResult.Statistics.Loadavg.One
 
-	for ifaceName, iface := range newResult.Interfaces() {
+	if mc.TrafficServer[newResult.ID].Interfaces == nil {
+		log.Debugf("no interfaces reported in config map to be monitored")
+		return
+	}
+
+	var monitoredInterfaces []tc.ServerInterfaceInfo
+	for _, srvrIfaceInfo := range mc.TrafficServer[newResult.ID].Interfaces {
+		if srvrIfaceInfo.Monitor {
+			monitoredInterfaces = append(monitoredInterfaces, srvrIfaceInfo)
+		}
+	}
+
+	if len(monitoredInterfaces) == 0 {
+		log.Debugf("no interfaces selected to be monitored for %v", newResult.ID)
+		return
+	}
+
+	for _, monitoredInterface := range monitoredInterfaces {
+		ifaceName := monitoredInterface.Name
+		iface, exists := newResult.Interfaces()[ifaceName]
+		if !exists {
+			// monitored interface doesn't exist in Result interfaces, skip
+			log.Warnf("monitored interface %v does not exist in %v cache.Result.Interfaces()", ifaceName, newResult.ID)

Review comment:
       Appreciate the clarity and simplicity. Will do.




-- 
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 #5730: Fixes an issue where multiple interfaces reported by a cache are included in the vitals (bandwidth)

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



##########
File path: traffic_monitor/health/cache.go
##########
@@ -53,14 +53,44 @@ func GetVitals(newResult *cache.Result, prevResult *cache.Result, mc *tc.Traffic
 		return
 	}
 
+	if mc == nil {
+		log.Errorf("mc TrafficMonitorConfigMap cannot be nil")
+		return
+	}
+
 	if newResult.InterfaceVitals == nil {
 		newResult.InterfaceVitals = map[string]cache.Vitals{}
 	}
 
 	// proc.loadavg -- we're using the 1 minute average (!?)
 	newResult.Vitals.LoadAvg = newResult.Statistics.Loadavg.One
 
-	for ifaceName, iface := range newResult.Interfaces() {
+	if mc.TrafficServer[newResult.ID].Interfaces == nil {

Review comment:
       This won't necessarily panic or cause any issues if the length is 0 or the cache isn't found. However, this is actually silently failing for those reasons. I will put checks in so that we can at least log the information to uncover the issues in the future should the cache map be empty or if the cache we're attempting to monitor is missing from said map.




-- 
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 #5730: Fixes an issue where multiple interfaces reported by a cache are included in the vitals (bandwidth)

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



##########
File path: CHANGELOG.md
##########
@@ -49,8 +49,10 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
 - [#5405](https://github.com/apache/trafficcontrol/issues/5405) - Prevent Tenant update from choosing child as new parent
 - [#5384](https://github.com/apache/trafficcontrol/issues/5384) - New grids will now properly remember the current page number.
 - [#5548](https://github.com/apache/trafficcontrol/issues/5548) - Don't return a `403 Forbidden` when the user tries to get servers of a non-existent DS using `GET /servers?dsId={{nonexistent DS ID}}`
+- [#5695](https://github.com/apache/trafficcontrol/issues/5695) - Ensure vitals are calculated only against monitored interfaces
 - [#5724](https://github.com/apache/trafficcontrol/issues/5724) - Set XMPPID to hostname if the server had none, don't error on server update when XMPPID is empty
 
+

Review comment:
       Done

##########
File path: traffic_monitor/health/cache.go
##########
@@ -53,14 +53,44 @@ func GetVitals(newResult *cache.Result, prevResult *cache.Result, mc *tc.Traffic
 		return
 	}
 
+	if mc == nil {
+		log.Errorf("mc TrafficMonitorConfigMap cannot be nil")

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] TaylorCFrey commented on a change in pull request #5730: Fixes an issue where multiple interfaces reported by a cache are included in the vitals (bandwidth)

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



##########
File path: traffic_monitor/health/cache.go
##########
@@ -53,14 +53,44 @@ func GetVitals(newResult *cache.Result, prevResult *cache.Result, mc *tc.Traffic
 		return
 	}
 
+	if mc == nil {
+		log.Errorf("mc TrafficMonitorConfigMap cannot be nil")
+		return
+	}
+
 	if newResult.InterfaceVitals == nil {
 		newResult.InterfaceVitals = map[string]cache.Vitals{}
 	}
 
 	// proc.loadavg -- we're using the 1 minute average (!?)
 	newResult.Vitals.LoadAvg = newResult.Statistics.Loadavg.One
 
-	for ifaceName, iface := range newResult.Interfaces() {
+	if mc.TrafficServer[newResult.ID].Interfaces == nil {
+		log.Debugf("no interfaces reported in config map to be monitored")
+		return
+	}
+
+	var monitoredInterfaces []tc.ServerInterfaceInfo
+	for _, srvrIfaceInfo := range mc.TrafficServer[newResult.ID].Interfaces {
+		if srvrIfaceInfo.Monitor {
+			monitoredInterfaces = append(monitoredInterfaces, srvrIfaceInfo)
+		}
+	}
+
+	if len(monitoredInterfaces) == 0 {
+		log.Debugf("no interfaces selected to be monitored for %v", newResult.ID)
+		return
+	}
+
+	for _, monitoredInterface := range monitoredInterfaces {
+		ifaceName := monitoredInterface.Name
+		iface, exists := newResult.Interfaces()[ifaceName]

Review comment:
       Since this is a map, the `exists` value will tell us if a match was found and we can log the information thusly. Otherwise the map returns an empty interface, rather than `nil`. This should be satisfactory as written.




-- 
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 merged pull request #5730: Fixes an issue where multiple interfaces reported by a cache are included in the vitals (bandwidth)

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


   


-- 
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 #5730: Fixes an issue where multiple interfaces reported by a cache are included in the vitals (bandwidth)

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



##########
File path: traffic_monitor/health/cache.go
##########
@@ -53,14 +53,44 @@ func GetVitals(newResult *cache.Result, prevResult *cache.Result, mc *tc.Traffic
 		return
 	}
 
+	if mc == nil {
+		log.Errorf("mc TrafficMonitorConfigMap cannot be nil")
+		return
+	}
+
 	if newResult.InterfaceVitals == nil {
 		newResult.InterfaceVitals = map[string]cache.Vitals{}
 	}
 
 	// proc.loadavg -- we're using the 1 minute average (!?)
 	newResult.Vitals.LoadAvg = newResult.Statistics.Loadavg.One
 
-	for ifaceName, iface := range newResult.Interfaces() {
+	if mc.TrafficServer[newResult.ID].Interfaces == nil {
+		log.Debugf("no interfaces reported in config map to be monitored")
+		return
+	}
+
+	var monitoredInterfaces []tc.ServerInterfaceInfo

Review comment:
       Excellent question. Ideally with DH servers, this would be the single interface being collected, rather than marking both (or more) of the other interfaces with "Monitor this interface". As such, we don't want to put any restrictions on this value for two reasons:
   1) We can't guarantee the naming of the interfaces. Thus any restrictions would have to be done just on conventions around names (such as `lo`)
   2) Should we want to monitor the `lo` interface in the future, any coded restrictions now would require a codebase change and a deployment, rather than a toggle of a checkbox in Traffic Portal. This does mean there is a potential for User-Error by checking or unchecking the various interfaces in TP to be monitored, but there isn't an elegant approach beyond that for now. I will look into adding a tooltip to the "Monitor this interface" checkbox label in TP to see if that is an appropriate fix to help prevent accidental User-Error




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