Skip to content

Commit

Permalink
Fixing panic seen in TM when timestamp_ms appears as float and not st…
Browse files Browse the repository at this point in the history
…ring (#7730)

* Fixing panic seen in TM when timestamp_ms appears as float and not string.

* Updated CHANGELOG.md
  • Loading branch information
rimashah25 authored Aug 17, 2023
1 parent bfe9766 commit 1adfebc
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
- [#7716](https://github.com/apache/trafficcontrol/pull/7716) *Apache Traffic Server* Use GCC 11 for building.

### Fixed
- [#7730](https://github.com/apache/trafficcontrol/pull/7730) *Traffic Monitor* Fixed the panic seen in TM when `plugin.system_stats.timestamp_ms` appears as float and not string.
- [#4393](https://github.com/apache/trafficcontrol/issues/4393) *Traffic Ops* Fixed the error code and alert structure when TO is queried for a delivery service with no ssl keys.
- [#7690](https://github.com/apache/trafficcontrol/pull/7690) *Traffic Ops* Fixes Logs V5 apis to respond with RFC3339 tiestamps.
- [#7631] (https://github.com/apache/trafficcontrol/pull/7631) *Traffic Ops* Fixes Phys_Location V5 apis to respond with RFC3339 date/time Format
Expand Down
5 changes: 2 additions & 3 deletions traffic_monitor/cache/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (
"fmt"
"io"
"regexp"
"strconv"
"time"

"github.com/apache/trafficcontrol/lib/go-log"
Expand Down Expand Up @@ -308,14 +307,14 @@ func (handler Handler) Handle(id string, rdr io.Reader, format string, reqTime t
return
}
if val, ok := miscStats["plugin.system_stats.timestamp_ms"]; ok {
valInt, valErr := strconv.ParseInt(val.(string), 10, 64)
valInt, valErr := parseNumericStat(val)
if valErr != nil {
log.Errorln("parse error: ", valErr)
result.Error = valErr
handler.resultChan <- result
return
}
result.Time = time.UnixMilli(valInt)
result.Time = time.UnixMilli(int64(valInt))
}
if value, ok := miscStats[rfc.Via]; ok {
result.ID = fmt.Sprintf("%v", value)
Expand Down
20 changes: 17 additions & 3 deletions traffic_monitor/cache/cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"bytes"
"io/ioutil"
"net/http"
"reflect"
"testing"

"github.com/apache/trafficcontrol/lib/go-rfc"
Expand Down Expand Up @@ -126,10 +127,23 @@ func TestParseAndDecode(t *testing.T) {
}

if val, ok := miscStats["plugin.system_stats.timestamp_ms"]; ok {
if val.(string) != "1684784877939" {
valType := reflect.TypeOf(val)
if valType.Kind() != reflect.String {
t.Errorf("type mismatch, expected: string, got:%s", valType)
}
val1, _ := parseNumericStat(val)
if val1 != uint64(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")
}
if val, ok := miscStats["plugin.system_stats.timestamp_ms_float64"]; ok {
valType := reflect.TypeOf(val)
if valType.Kind() != reflect.Float64 {
t.Errorf("type mismatch, expected: string, got:%s", valType)
}
val1, _ := parseNumericStat(val)
if val1 != uint64(1684784877939) {
t.Errorf("unable to read `plugin.system_stats.timestamp_ms_float64`")
}
}
}
1 change: 1 addition & 0 deletions traffic_monitor/cache/stats_over_http.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"global": {
"plugin.system_stats.timestamp_ms": "1684784877939",
"plugin.system_stats.timestamp_ms_float64": 1684784877939,
"proxy.process.http.completed_requests": 26220072200,
"proxy.process.http.total_incoming_connections": 770802777,
"proxy.process.http.total_client_connections": 770802777,
Expand Down

0 comments on commit 1adfebc

Please sign in to comment.