This is an automated email from the ASF dual-hosted git repository.
zrhoffman pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficcontrol.git
The following commit(s) were added to refs/heads/master by this push:
new 35c8db7471 Bugfix/tm bandwidth bug (#7608)
35c8db7471 is described below
commit 35c8db7471f65c80f4de998b39a7222d2834fd6c
Author: Rima Shah <[email protected]>
AuthorDate: Wed Jul 5 13:59:17 2023 -0600
Bugfix/tm bandwidth bug (#7608)
* Added changes to fix BW bug
* Updated CHANGELOG.md
* Updated cache/cache files
* addressed review comments.
* using rfc package
* using rfc package-1
---
CHANGELOG.md | 1 +
traffic_monitor/cache/cache.go | 11 +++++++++
traffic_monitor/cache/cache_test.go | 38 ++++++++++++++++++++++++++++++
traffic_monitor/cache/stats_over_http.json | 1 +
4 files changed, 51 insertions(+)
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 8f7e10bb74..925f4a37cb 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -61,6 +61,7 @@ The format is based on [Keep a
Changelog](http://keepachangelog.com/en/1.0.0/).
- [#7600](https://github.com/apache/trafficcontrol/pull/7600) *t3c* changed
default go-direct command line arg to be old to avoid unexpected config changes
upon upgrade.
### Fixed
+- [#7608](https://github.com/apache/trafficcontrol/pull/7608) *Traffic
Monitor* Use stats_over_http(plugin.system_stats.timestamp_ms) timestamp field
to calculate bandwidth for TM's caches.
- [#6318](https://github.com/apache/trafficcontrol/issues/6318) *Docs*
Included docs for POST, PUT, DELETE (v3,v4,v5) for statuses and statuses{id}
- [#7561](https://github.com/apache/trafficcontrol/pull/7561) *Traffic Ops*
*Traffic Ops* Fixed `ASN` V5 apis to respond with `RFC3339` date/time Format.
- [#7598](https://github.com/apache/trafficcontrol/pull/7598) *Traffic Ops*
Fixes Server Capability V5 Type Name Minor version
diff --git a/traffic_monitor/cache/cache.go b/traffic_monitor/cache/cache.go
index 339c4a5f5c..756662c4bd 100644
--- a/traffic_monitor/cache/cache.go
+++ b/traffic_monitor/cache/cache.go
@@ -23,6 +23,7 @@ import (
"fmt"
"io"
"regexp"
+ "strconv"
"time"
"github.com/apache/trafficcontrol/lib/go-log"
@@ -306,6 +307,16 @@ func (handler Handler) Handle(id string, rdr io.Reader,
format string, reqTime t
handler.resultChan <- result
return
}
+ if val, ok := miscStats["plugin.system_stats.timestamp_ms"]; ok {
+ valInt, valErr := strconv.ParseInt(val.(string), 10, 64)
+ if valErr != nil {
+ log.Errorln("parse error: ", valErr)
+ result.Error = valErr
+ handler.resultChan <- result
+ return
+ }
+ result.Time = time.UnixMilli(valInt)
+ }
if value, ok := miscStats[rfc.Via]; ok {
result.ID = fmt.Sprintf("%v", value)
}
diff --git a/traffic_monitor/cache/cache_test.go
b/traffic_monitor/cache/cache_test.go
index b20a392507..f881339320 100644
--- a/traffic_monitor/cache/cache_test.go
+++ b/traffic_monitor/cache/cache_test.go
@@ -20,10 +20,15 @@ package cache
*/
import (
+ "bytes"
+ "io/ioutil"
+ "net/http"
"testing"
+ "github.com/apache/trafficcontrol/lib/go-rfc"
"github.com/apache/trafficcontrol/lib/go-tc"
"github.com/apache/trafficcontrol/lib/go-util"
+ "github.com/apache/trafficcontrol/traffic_monitor/poller"
"github.com/apache/trafficcontrol/traffic_monitor/todata"
)
@@ -95,3 +100,36 @@ func TestComputeStatGbps(t *testing.T) {
}
}
}
+
+func TestParseAndDecode(t *testing.T) {
+ file, err := ioutil.ReadFile("stats_over_http.json")
+ if err != nil {
+ t.Fatal(err)
+ }
+
+ pl := &poller.HTTPPollCtx{HTTPHeader: http.Header{}}
+ ctx := interface{}(pl)
+ ctx.(*poller.HTTPPollCtx).HTTPHeader.Set(rfc.ContentType,
rfc.ApplicationJSON)
+
+ decoder, err := GetDecoder("stats_over_http")
+ if err != nil {
+ t.Errorf("decoder error, expected: nil, got: %v", err)
+ }
+
+ _, miscStats, err := decoder.Parse("1", bytes.NewReader(file), ctx)
+ if err != nil {
+ t.Errorf("decoder parse error, expected: nil, got: %v", err)
+ }
+
+ if len(miscStats) < 1 {
+ t.Errorf("empty miscStats structure")
+ }
+
+ if val, ok := miscStats["plugin.system_stats.timestamp_ms"]; ok {
+ if val.(string) != "1684784877939" {
+ t.Errorf("unable to read
`plugin.system_stats.timestamp_ms`")
+ }
+ } else {
+ t.Errorf("plugin.system_stats.timestamp_ms field was not found
in the json file")
+ }
+}
diff --git a/traffic_monitor/cache/stats_over_http.json
b/traffic_monitor/cache/stats_over_http.json
index 70cce951b4..979a2bac72 100644
--- a/traffic_monitor/cache/stats_over_http.json
+++ b/traffic_monitor/cache/stats_over_http.json
@@ -1,5 +1,6 @@
{
"global": {
+ "plugin.system_stats.timestamp_ms": "1684784877939",
"proxy.process.http.completed_requests": 26220072200,
"proxy.process.http.total_incoming_connections": 770802777,
"proxy.process.http.total_client_connections": 770802777,