This is an automated email from the ASF dual-hosted git repository. rshah pushed a commit to branch bugfix/TM-bandwidth-bug in repository https://gitbox.apache.org/repos/asf/trafficcontrol.git
commit 573c69e05e9cecc4bba732d79fda8188272b9879 Author: Rima Shah <[email protected]> AuthorDate: Thu Jun 29 16:55:45 2023 -0600 Added changes to fix BW bug --- CHANGELOG.md | 1 + traffic_monitor/cache/cache.go | 12 +++++++++ traffic_monitor/cache/cache_test.go | 39 ++++++++++++++++++++++++++++++ traffic_monitor/cache/stats_over_http.json | 1 + 4 files changed, 53 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index b82cec39ad..9de26b0490 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -60,6 +60,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 +- [#7607](https://github.com/apache/trafficcontrol/pull/7607) *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..9bedd3494f 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,17 @@ 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 { + valString := fmt.Sprintf("%s", val) + valInt, valErr := strconv.ParseInt(valString, 10, 64) + if valErr != nil { + log.Errorf("parse error '%v'", 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..7d3e685e75 100644 --- a/traffic_monitor/cache/cache_test.go +++ b/traffic_monitor/cache/cache_test.go @@ -20,10 +20,15 @@ package cache */ import ( + "bytes" + "fmt" + "io/ioutil" + "net/http" "testing" "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,37 @@ 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("Content-Type", "text/json") + + 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 { + valString := fmt.Sprintf("%s", val) + if valString != "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,
