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.
  • Loading branch information
rimashah25 committed Aug 17, 2023
1 parent bfe9766 commit d176ab4
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
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 d176ab4

Please sign in to comment.