Skip to content

Commit

Permalink
use json number to decode span (#2849)
Browse files Browse the repository at this point in the history
  • Loading branch information
recallsong committed Nov 4, 2021
1 parent 68828b2 commit 27946dc
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions modules/msp/apm/trace/storage/consumer.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package storage

import (
"bytes"
"encoding/json"
"errors"
"fmt"
Expand Down Expand Up @@ -121,15 +122,17 @@ func convertToIntID(id string) uint32 {
func (p *provider) spotSpanConsumer(key []byte, value []byte, topic *string, timestamp time.Time) error {
// write spot span to cassandra
metric := &metrics.Metric{}
if err := json.Unmarshal(value, metric); err != nil {
dec := json.NewDecoder(bytes.NewReader(value))
dec.UseNumber()
if err := dec.Decode(&metric); err != nil {
return err
}
span, err := metricToSpan(metric)
if err != nil {
return err
}
//metric = toSpan(span)
//err = p.output.kafka.Write(metric)
// metric = toSpan(span)
// err = p.output.kafka.Write(metric)
if err != nil {
p.Log.Errorf("fail to push kafka: %s", err)
return err
Expand Down Expand Up @@ -233,6 +236,8 @@ func toInt64(obj interface{}) (int64, error) {
return int64(val), nil
case float64:
return int64(val), nil
case json.Number:
return val.Int64()
case string:
v, err := strconv.ParseInt(val, 10, 64)
if err != nil {
Expand Down

0 comments on commit 27946dc

Please sign in to comment.