You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficcontrol.apache.org by oc...@apache.org on 2021/04/07 16:02:13 UTC

[trafficcontrol] branch 5.1.x updated (2f0bdad -> 924138d)

This is an automated email from the ASF dual-hosted git repository.

ocket8888 pushed a change to branch 5.1.x
in repository https://gitbox.apache.org/repos/asf/trafficcontrol.git.


    from 2f0bdad  Fix TO client urlsig path (#5705)
     new 885f68d  Fixed GET api/3.1/cdns/routing endpoint to avoid incorrect success response (return all zeros)  (#5709)
     new 924138d  Ensure that 5.x TS is not logging all 0's for cache_stats, when linked with a 5.x TM/TO (#5714)

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 CHANGELOG.md                                       |   7 +
 traffic_ops/traffic_ops_golang/crstats/routing.go  |   3 +-
 .../traffic_router/core/router/StatTracker.java    |  14 +-
 traffic_stats/traffic_stats.go                     |  16 ++-
 traffic_stats/traffic_stats_test.go                | 157 +++++++++++++++++++++
 5 files changed, 185 insertions(+), 12 deletions(-)
 create mode 100644 traffic_stats/traffic_stats_test.go

[trafficcontrol] 01/02: Fixed GET api/3.1/cdns/routing endpoint to avoid incorrect success response (return all zeros) (#5709)

Posted by oc...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

ocket8888 pushed a commit to branch 5.1.x
in repository https://gitbox.apache.org/repos/asf/trafficcontrol.git

commit 885f68dd4c32098369a51a0424b3389fd053c14b
Author: Rima Shah <22...@users.noreply.github.com>
AuthorDate: Mon Apr 5 16:26:39 2021 -0600

    Fixed GET api/3.1/cdns/routing endpoint to avoid incorrect success response (return all zeros)  (#5709)
    
    * Added debug statements
    
    * Removed debug fmt statements and updated the return error as it was returning incorrect err value.
    
    * Updated TR's stat tracker to include long int
    Update CHANGELOG.md
    Removed unnecessary new lines
    
    * Updated TR's stat tracker to include long int-1
    
    (cherry picked from commit b31db78965ee66dd5abea1508f732bdc42cafe0c)
---
 CHANGELOG.md                                               |  1 +
 traffic_ops/traffic_ops_golang/crstats/routing.go          |  3 +--
 .../traffic_router/core/router/StatTracker.java            | 14 +++++++-------
 3 files changed, 9 insertions(+), 9 deletions(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index eaab102..738fc5e 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -16,6 +16,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
 - [#5604](https://github.com/apache/trafficcontrol/issues/5604) - traffic_monitor.log is no longer truncated when restarting Traffic Monitor
 - [#1624](https://github.com/apache/trafficcontrol/issues/1624) - Fixed ORT to reload Traffic Server if LUA scripts are added or changed.
 - #5554 - TM UI overflows screen width and hides table data
+- Fixed the return error for GET api `cdns/routing` to avoid incorrect success response.
 
 
 ## [5.1.0] - 2021-02-21
diff --git a/traffic_ops/traffic_ops_golang/crstats/routing.go b/traffic_ops/traffic_ops_golang/crstats/routing.go
index 6a18ebc..bd720c0 100644
--- a/traffic_ops/traffic_ops_golang/crstats/routing.go
+++ b/traffic_ops/traffic_ops_golang/crstats/routing.go
@@ -102,10 +102,9 @@ func getRoutersRouting(tx *sql.Tx, routers map[tc.CDNName][]string, statType *st
 	close(resp)
 
 	dat := RouterData{}
-
 	for r := range resp {
 		if r.Error != nil {
-			return tc.Routing{}, err
+			return tc.Routing{}, r.Error
 		}
 		dat = addCRSStats(dat, r.Stats, statType, hostRegex)
 	}
diff --git a/traffic_router/core/src/main/java/com/comcast/cdn/traffic_control/traffic_router/core/router/StatTracker.java b/traffic_router/core/src/main/java/com/comcast/cdn/traffic_control/traffic_router/core/router/StatTracker.java
index 6546b87..0aac2c9 100644
--- a/traffic_router/core/src/main/java/com/comcast/cdn/traffic_control/traffic_router/core/router/StatTracker.java
+++ b/traffic_router/core/src/main/java/com/comcast/cdn/traffic_control/traffic_router/core/router/StatTracker.java
@@ -318,32 +318,32 @@ public class StatTracker {
 	public Map<String, Tallies> getHttpMap() {
 		return httpMap;
 	}
-	public int getTotalDnsCount() {
+	public long getTotalDnsCount() {
 		return totalDnsCount;
 	}
 	public long getAverageDnsTime() {
 		if(totalDnsCount==0) { return 0; }
 		return totalDnsTime/totalDnsCount;
 	}
-	public int getTotalHttpCount() {
+	public long getTotalHttpCount() {
 		return totalHttpCount;
 	}
 	public long getAverageHttpTime() {
 		if(totalHttpCount==0) { return 0; }
 		return totalHttpTime/totalHttpCount;
 	}
-	public int getTotalDsMissCount() {
+	public long getTotalDsMissCount() {
 		return totalDsMissCount;
 	}
-	public void setTotalDsMissCount(final int totalDsMissCount) {
+	public void setTotalDsMissCount(final long totalDsMissCount) {
 		this.totalDsMissCount = totalDsMissCount;
 	}
 
-	private int totalDnsCount;
+	private long totalDnsCount;
 	private long totalDnsTime;
-	private int totalHttpCount;
+	private long totalHttpCount;
 	private long totalHttpTime;
-	private int totalDsMissCount = 0;
+	private long totalDsMissCount = 0;
 	public Map<String,Long> getUpdateTracker() {
 		return TrafficRouterManager.getTimeTracker();
 	}

[trafficcontrol] 02/02: Ensure that 5.x TS is not logging all 0's for cache_stats, when linked with a 5.x TM/TO (#5714)

Posted by oc...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

ocket8888 pushed a commit to branch 5.1.x
in repository https://gitbox.apache.org/repos/asf/trafficcontrol.git

commit 924138d143febb66e926f0e6be82b22d450bfbd9
Author: Srijeet Chatterjee <30...@users.noreply.github.com>
AuthorDate: Tue Apr 6 08:26:26 2021 -0600

    Ensure that 5.x TS is not logging all 0's for cache_stats, when linked with a 5.x TM/TO (#5714)
    
    * Add fixes to ensure that TS is not logging all 0's for cache_stats
    
    * change log msg modification
    
    (cherry picked from commit ff7984842b143212e27460bcf4243786d5098b94)
---
 CHANGELOG.md                        |   8 +-
 traffic_stats/traffic_stats.go      |  16 +++-
 traffic_stats/traffic_stats_test.go | 157 ++++++++++++++++++++++++++++++++++++
 3 files changed, 177 insertions(+), 4 deletions(-)

diff --git a/CHANGELOG.md b/CHANGELOG.md
index 738fc5e..d5759f5 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -3,6 +3,13 @@ All notable changes to this project will be documented in this file.
 
 The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
 
+## [5.1.2] - 2021-04-07
+### Fixed
+- Fixed the return error for GET api `cdns/routing` to avoid incorrect success response.
+- [#5712](https://github.com/apache/trafficcontrol/issues/5712) - Ensure that 5.x Traffic Stats is compatible with 5.x Traffic Monitor and 5.x Traffic Ops, and that it doesn't log all 0's for `cache_stats`
+- Fixed ORT being unable to update URLSIG keys for Delivery Services
+- Fixed an issue where Traffic Ops becoming unavailable caused Traffic Monitor to segfault and crash
+
 ## [5.1.1] - 2021-03-19
 ### Added
 - Atscfg: Added a rule to ip_allow such that PURGE requests are allowed over localhost
@@ -16,7 +23,6 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
 - [#5604](https://github.com/apache/trafficcontrol/issues/5604) - traffic_monitor.log is no longer truncated when restarting Traffic Monitor
 - [#1624](https://github.com/apache/trafficcontrol/issues/1624) - Fixed ORT to reload Traffic Server if LUA scripts are added or changed.
 - #5554 - TM UI overflows screen width and hides table data
-- Fixed the return error for GET api `cdns/routing` to avoid incorrect success response.
 
 
 ## [5.1.0] - 2021-02-21
diff --git a/traffic_stats/traffic_stats.go b/traffic_stats/traffic_stats.go
index a4aef4e..5088a19 100644
--- a/traffic_stats/traffic_stats.go
+++ b/traffic_stats/traffic_stats.go
@@ -654,10 +654,14 @@ func calcCacheValues(trafmonData []byte, cdnName string, sampleTime int64, cache
 	if err != nil {
 		errHndlr(err, ERROR)
 	}
+
 	for cacheName, cacheData := range jData.Caches {
 		cache := cacheMap[string(cacheName)]
 
 		for statName, statData := range cacheData {
+			if len(statData) == 0 {
+				continue
+			}
 			//Get the stat time and make sure it's greater than the time 24 hours ago.  If not, skip it so influxdb doesn't throw retention policy errors.
 			validTime := time.Now().AddDate(0, 0, -1)
 			if statData[0].Time.Before(validTime) {
@@ -669,10 +673,16 @@ func calcCacheValues(trafmonData []byte, cdnName string, sampleTime int64, cache
 			dataKey = strings.Replace(dataKey, "-", "_", -1)
 
 			//Get the stat value and convert to float
-			statFloatValue, ok := statData[0].Val.(float64)
-			if !ok {
-				statFloatValue = 0.00
+			statFloatValue := 0.0
+			if statsValue, ok := statData[0].Val.(string); !ok {
+				log.Warnf("stat data %s with value %v couldn't be converted into string", statName, statData[0].Val)
+			} else {
+				statFloatValue, err = strconv.ParseFloat(statsValue, 64)
+				if err != nil {
+					log.Warnf("stat %s with value %v couldn't be converted into a float", statName, statsValue)
+				}
 			}
+
 			tags := map[string]string{
 				"cachegroup": cache.Cachegroup,
 				"hostname":   string(cacheName),
diff --git a/traffic_stats/traffic_stats_test.go b/traffic_stats/traffic_stats_test.go
new file mode 100644
index 0000000..735023a
--- /dev/null
+++ b/traffic_stats/traffic_stats_test.go
@@ -0,0 +1,157 @@
+package main
+
+/*
+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 (
+	"encoding/json"
+	"testing"
+	"time"
+
+	"github.com/apache/trafficcontrol/lib/go-tc"
+	influx "github.com/influxdata/influxdb/client/v2"
+)
+
+func TestCalcCacheValuesWithInvalidValue(t *testing.T) {
+	stats := make(map[string][]tc.ResultStatVal)
+	caches := make(map[tc.CacheName]map[string][]tc.ResultStatVal)
+	cacheMap := make(map[string]tc.Server)
+	resultSatsVal := []tc.ResultStatVal{
+		{
+			Span: 0,
+			Time: time.Now(),
+			Val:  "invalid stat",
+		},
+	}
+	stats["maxKbps"] = resultSatsVal
+	caches["cache1"] = stats
+	cacheMap["cache1"] = tc.Server{}
+	config := StartupConfig{
+		BpsChan: make(chan influx.BatchPoints),
+	}
+	legacyStats := tc.LegacyStats{
+		CommonAPIData: tc.CommonAPIData{},
+		Caches:        caches,
+	}
+	data, err := json.Marshal(legacyStats)
+	if err != nil {
+		t.Fatalf("couldn't marshal struct %v", caches)
+	}
+	go calcCacheValues(data, "cdn", 0, cacheMap, config)
+	result := <-config.BpsChan
+	if len(result.Points()) == 0 {
+		t.Fatalf("expected one point in the result, got none")
+	}
+	fields, err := result.Points()[0].Fields()
+	if err != nil {
+		t.Fatalf("couldn't read the fields of the result: %v", err.Error())
+	}
+	if val, ok := fields["value"]; !ok {
+		t.Fatalf("couldn't find a 'value' field")
+	} else {
+		if val.(float64) != 0.0 {
+			t.Errorf("expected invalid stat to result in a value of 0.0, but got %v instead", val.(float64))
+		}
+	}
+}
+
+func TestCalcCacheValuesWithEmptyInterface(t *testing.T) {
+	stats := make(map[string][]tc.ResultStatVal)
+	caches := make(map[tc.CacheName]map[string][]tc.ResultStatVal)
+	cacheMap := make(map[string]tc.Server)
+	resultSatsVal := []tc.ResultStatVal{
+		{
+			Span: 0,
+			Time: time.Now(),
+		},
+	}
+	stats["maxKbps"] = resultSatsVal
+	caches["cache1"] = stats
+	cacheMap["cache1"] = tc.Server{}
+	config := StartupConfig{
+		BpsChan: make(chan influx.BatchPoints),
+	}
+	legacyStats := tc.LegacyStats{
+		CommonAPIData: tc.CommonAPIData{},
+		Caches:        caches,
+	}
+	data, err := json.Marshal(legacyStats)
+	if err != nil {
+		t.Fatalf("couldn't marshal struct %v", caches)
+	}
+	go calcCacheValues(data, "cdn", 0, cacheMap, config)
+	result := <-config.BpsChan
+	if len(result.Points()) == 0 {
+		t.Fatalf("expected one point in the result, got none")
+	}
+	fields, err := result.Points()[0].Fields()
+	if err != nil {
+		t.Fatalf("couldn't read the fields of the result: %v", err.Error())
+	}
+	if val, ok := fields["value"]; !ok {
+		t.Fatalf("couldn't find a 'value' field")
+	} else {
+		if val.(float64) != 0.0 {
+			t.Errorf("expected invalid stat to result in a value of 0.0, but got %v instead", val.(float64))
+		}
+	}
+}
+
+func TestCalcCacheValues(t *testing.T) {
+	stats := make(map[string][]tc.ResultStatVal)
+	caches := make(map[tc.CacheName]map[string][]tc.ResultStatVal)
+	cacheMap := make(map[string]tc.Server)
+	resultSatsVal := []tc.ResultStatVal{
+		{
+			Span: 0,
+			Time: time.Now(),
+			Val:  "25.56",
+		},
+	}
+	stats["maxKbps"] = resultSatsVal
+	caches["cache1"] = stats
+	cacheMap["cache1"] = tc.Server{}
+	config := StartupConfig{
+		BpsChan: make(chan influx.BatchPoints),
+	}
+	legacyStats := tc.LegacyStats{
+		CommonAPIData: tc.CommonAPIData{},
+		Caches:        caches,
+	}
+	data, err := json.Marshal(legacyStats)
+	if err != nil {
+		t.Fatalf("couldn't marshal struct %v", caches)
+	}
+	go calcCacheValues(data, "cdn", 0, cacheMap, config)
+	result := <-config.BpsChan
+	if len(result.Points()) == 0 {
+		t.Fatalf("expected one point in the result, got none")
+	}
+	fields, err := result.Points()[0].Fields()
+	if err != nil {
+		t.Fatalf("couldn't read the fields of the result: %v", err.Error())
+	}
+	if val, ok := fields["value"]; !ok {
+		t.Fatalf("couldn't find a 'value' field")
+	} else {
+		if val.(float64) != 25.56 {
+			t.Errorf("expected invalid stat to result in a value of 0.0, but got %v instead", val.(float64))
+		}
+	}
+}