Skip to content

Commit

Permalink
Tradelogs parsing error metrics (#93)
Browse files Browse the repository at this point in the history
* add error metrics

* update
  • Loading branch information
linhnt3400 authored Nov 4, 2024
1 parent a66fd04 commit 4e7f63b
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 8 deletions.
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ require (
github.com/IBM/sarama v1.43.3
github.com/KyberNetwork/cclog v1.1.0
github.com/KyberNetwork/go-binance/v2 v2.0.3
github.com/KyberNetwork/tradinglib v0.5.10
github.com/KyberNetwork/tradinglib v0.6.1
github.com/TheZeroSlave/zapsentry v1.20.2
github.com/ethereum/go-ethereum v1.13.14
github.com/getsentry/sentry-go v0.26.0
Expand Down Expand Up @@ -67,7 +67,7 @@ require (
github.com/felixge/httpsnoop v1.0.4 // indirect
github.com/fsnotify/fsnotify v1.7.0 // indirect
github.com/gabriel-vasile/mimetype v1.4.3 // indirect
github.com/go-logr/logr v1.4.1 // indirect
github.com/go-logr/logr v1.4.2 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/goccy/go-json v0.10.2 // indirect
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ github.com/KyberNetwork/go-binance/v2 v2.0.3 h1:VsBBHXAJTxryBsdO6U9MyK+oHEJ9qZtQ
github.com/KyberNetwork/go-binance/v2 v2.0.3/go.mod h1:ihNzjOXDgxZ4cSENV2sQfXnO30wobXQPpqTuKxxUVjw=
github.com/KyberNetwork/kyber-trace-go v0.1.1 h1:YgzZb7jSg0Rgj7zFv9zUnSlB13Iksv1eVO5MSWAvjmM=
github.com/KyberNetwork/kyber-trace-go v0.1.1/go.mod h1:X6hVacmKMeOEOlFh4TyfEHaEVRerFQ5YLuQ4keRV3hw=
github.com/KyberNetwork/tradinglib v0.5.10 h1:4R9XWkfCDeisuUyxq8px1JMXNGl73+c3tIuqBX9jWl8=
github.com/KyberNetwork/tradinglib v0.5.10/go.mod h1:3Ciie58Qmd0mFSnUWAg6phbalao6f2GGcAZ6nxw/lcQ=
github.com/KyberNetwork/tradinglib v0.6.1 h1:6BIeci/MawEo+vV/3LFQBzBbulimK4gCNKZSwz6h6fg=
github.com/KyberNetwork/tradinglib v0.6.1/go.mod h1:fRH5mz+qKrwreW2eSppCYRVYGN5RYHlF5xfJBBDzPW8=
github.com/Masterminds/squirrel v1.5.4 h1:uUcX/aBc8O7Fg9kaISIUsHXdKuqehiXAMQTYX8afzqM=
github.com/Masterminds/squirrel v1.5.4/go.mod h1:NNaOrjSoIDfDA40n7sr2tPNZRfjzjA400rg+riTZj10=
github.com/Microsoft/go-winio v0.6.1 h1:9/kr64B9VUZrLm5YYwbGtUJnMgqWVOdUAXu6Migciow=
Expand Down Expand Up @@ -219,8 +219,8 @@ github.com/go-errors/errors v1.0.1/go.mod h1:f4zRHt4oKfwPJE5k8C9vpYG+aDHdBFUsgrm
github.com/go-errors/errors v1.4.2 h1:J6MZopCL4uSllY1OfXM374weqZFFItUbrImctkmUxIA=
github.com/go-errors/errors v1.4.2/go.mod h1:sIVyrIiJhuEF+Pj9Ebtd6P/rEYROXFi3BopGUQ5a5Og=
github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
github.com/go-logr/logr v1.4.1 h1:pKouT5E8xu9zeFC39JXRDukb6JFQPXM5p5I91188VAQ=
github.com/go-logr/logr v1.4.1/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
github.com/go-logr/logr v1.4.2 h1:6pFjapn8bFcIbiKo3XT4j/BhANplGihG6tvd+8rYgrY=
github.com/go-logr/logr v1.4.2/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY=
github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag=
github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE=
github.com/go-martini/martini v0.0.0-20170121215854-22fa46961aab/go.mod h1:/P9AEU963A2AYjv4d1V5eVL1CQbEJq6aCNHDDjibzu8=
Expand Down
13 changes: 11 additions & 2 deletions internal/worker/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,15 @@ import (
"github.com/KyberNetwork/tradelogs/pkg/parser"
"github.com/KyberNetwork/tradelogs/pkg/pricefiller"
"github.com/KyberNetwork/tradelogs/pkg/storage"
"github.com/KyberNetwork/tradinglib/pkg/metrics"
ethTypes "github.com/ethereum/go-ethereum/core/types"
"go.uber.org/zap"
)

const (
RetryInterval = 4 * time.Second
RemoveInterval = time.Hour
RetryInterval = 4 * time.Second
RemoveInterval = time.Hour
ParsingErrorMetricName = "trading_tradelogs_parse_error"
)

type Worker struct {
Expand Down Expand Up @@ -99,6 +101,9 @@ func (w *Worker) processMessages(m []evmlistenerclient.Message) error {
}
order, err := ps.Parse(ethLog, block.Timestamp)
if err != nil {
if err = metrics.RecordCounter(context.Background(), ParsingErrorMetricName, 1); err != nil {
w.l.Errorw("error when record parsing error", "err", err)
}
w.l.Errorw("error when parse log", "log", log, "order", order, "err", err)
if err := w.s.InsertErrorLog(storage.EVMLog{
Address: log.Address,
Expand Down Expand Up @@ -141,6 +146,7 @@ func (w *Worker) retryParseLog() error {
return err
}
w.l.Infow("start retry logs", "len", len(logs))

for _, l := range logs {
topics := strings.Split(l.Topics, ",")
if len(topics) == 0 {
Expand All @@ -162,6 +168,9 @@ func (w *Worker) retryParseLog() error {
}
order, err := ps.Parse(ethLog, l.Time)
if err != nil {
if err := metrics.RecordCounter(context.Background(), ParsingErrorMetricName, 1); err != nil {
w.l.Errorw("error when record parsing error", "err", err)
}
w.l.Errorw("error when retry log", "log", l, "err", err)
continue
}
Expand Down

0 comments on commit 4e7f63b

Please sign in to comment.