Skip to content

Commit

Permalink
add metrics
Browse files Browse the repository at this point in the history
  • Loading branch information
giskook committed Mar 21, 2024
1 parent dcdf8a6 commit bd459ec
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
9 changes: 3 additions & 6 deletions jsonrpc/endpoints_eth_xlayer.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"sync"
"time"

"github.com/0xPolygonHermez/zkevm-node/jsonrpc/metrics"
"github.com/0xPolygonHermez/zkevm-node/jsonrpc/types"
"github.com/0xPolygonHermez/zkevm-node/log"
"github.com/0xPolygonHermez/zkevm-node/state"
Expand All @@ -25,10 +26,6 @@ var once sync.Once

// GetInternalTransactions returns a transaction by his hash
func (e *EthEndpoints) GetInternalTransactions(hash types.ArgHash) (interface{}, types.Error) {
ts := time.Now()
defer func() {
log.Info("GetInternalTransactions took: ", time.Since(ts))
}()
if e.isDisabled("eth_getInternalTransactions") {
return RPCErrorResponse(types.DefaultErrorCode, "not supported yet", nil, true)
}
Expand All @@ -46,7 +43,7 @@ func (e *EthEndpoints) GetInternalTransactions(hash types.ArgHash) (interface{},
var innerTxs []*InnerTx
err = json.Unmarshal([]byte(ret), &innerTxs)
if err == nil {
log.Info("GetInnerTx from cache")
metrics.RequestInnerTxCachedCount()
return innerTxs, nil
} else {
log.Errorf("failed to unmarshal inner txs: %v", err)
Expand Down Expand Up @@ -74,11 +71,11 @@ func (e *EthEndpoints) GetInternalTransactions(hash types.ArgHash) (interface{},
return nil, types.NewRPCError(types.ParserErrorCode, stderr.Error())
}
result := internalTxTraceToInnerTxs(of)
metrics.RequestInnerTxExecutedCount()

if e.cfg.EnableInnerTxCacheDB {
// Add inner txs to the pool
innerTxBlob, myerr := json.Marshal(result)
log.Infof("result: %v", string(innerTxBlob))
if myerr != nil {
log.Errorf("failed to marshal inner txs: %v", err)
} else {
Expand Down
16 changes: 14 additions & 2 deletions jsonrpc/metrics/metrics_xlayer.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ import (
)

var (
requestMethodName = requestPrefix + "method"
requestMethodDurationName = requestPrefix + "method_duration"
requestMethodName = requestPrefix + "method"
requestMethodDurationName = requestPrefix + "method_duration"
requestInnerTxCachedName = requestPrefix + "inner_tx_cached"
requestInnerTxExecutedName = requestPrefix + "inner_tx_executed"

wsRequestPrefix = prefix + "ws_request_"
requestWsMethodName = wsRequestPrefix + "method"
Expand Down Expand Up @@ -78,3 +80,13 @@ func RequestMethodDuration(method string, start time.Time) {
func RequestMethodCount(method string) {
metrics.CounterVecInc(requestMethodName, method)
}

// RequestInnerTxExecutedCount increments the inner tx executed counter vector by one.
func RequestInnerTxExecutedCount() {
metrics.CounterInc(requestInnerTxExecutedName)
}

// RequestInnerTxCachedCount increments the inner tx cached counter vector by one.
func RequestInnerTxCachedCount() {
metrics.CounterInc(requestInnerTxCachedName)
}

0 comments on commit bd459ec

Please sign in to comment.