Skip to content

Commit

Permalink
fix: cosmos_relayer_tx_failure metric redundant count (#1343)
Browse files Browse the repository at this point in the history
* fix: cosmos_relayer_tx_failure metric

* feedback
  • Loading branch information
boojamya authored Nov 26, 2023
1 parent be8ebe0 commit 34d3d4f
Showing 1 changed file with 24 additions and 28 deletions.
52 changes: 24 additions & 28 deletions relayer/processor/message_processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,13 @@ type messageProcessor struct {
}

// catagories of tx errors for a Prometheus counter. If the error doesnt fall into one of the below categories, it is labeled as "Tx Failure"
var promErrorCatagories = []error{chantypes.ErrRedundantTx, legacyerrors.ErrInsufficientFunds, legacyerrors.ErrInvalidCoins, legacyerrors.ErrOutOfGas, legacyerrors.ErrWrongSequence}
var promErrorCatagories = []error{
chantypes.ErrRedundantTx,
legacyerrors.ErrInsufficientFunds,
legacyerrors.ErrInvalidCoins,
legacyerrors.ErrOutOfGas,
legacyerrors.ErrWrongSequence,
}

// trackMessage stores the message tracker in the correct slice and index based on the type.
func (mp *messageProcessor) trackMessage(tracker messageToTrack, i int) {
Expand Down Expand Up @@ -374,15 +380,7 @@ func (mp *messageProcessor) sendClientUpdate(
zap.Error(err),
)

for _, promError := range promErrorCatagories {
if mp.metrics != nil {
if errors.Is(err, promError) {
mp.metrics.IncTxFailure(src.info.PathName, src.info.ChainID, promError.Error())
} else {
mp.metrics.IncTxFailure(src.info.PathName, src.info.ChainID, "Tx Failure")
}
}
}
mp.metricParseTxFailureCatagory(err, src)
return
}
dst.log.Debug("Client update broadcast completed")
Expand Down Expand Up @@ -477,15 +475,7 @@ func (mp *messageProcessor) sendBatchMessages(
zap.Error(err),
}

for _, promError := range promErrorCatagories {
if mp.metrics != nil {
if errors.Is(err, promError) {
mp.metrics.IncTxFailure(src.info.PathName, src.info.ChainID, promError.Error())
} else {
mp.metrics.IncTxFailure(src.info.PathName, src.info.ChainID, "Tx Failure")
}
}
}
mp.metricParseTxFailureCatagory(err, src)

if errors.Is(err, chantypes.ErrRedundantTx) {
mp.log.Debug("Redundant message(s)", errFields...)
Expand Down Expand Up @@ -564,15 +554,7 @@ func (mp *messageProcessor) sendSingleMessage(
zap.String("dst_client_id", dst.info.ClientID),
}

for _, promError := range promErrorCatagories {
if mp.metrics != nil {
if errors.Is(err, promError) {
mp.metrics.IncTxFailure(src.info.PathName, src.info.ChainID, promError.Error())
} else {
mp.metrics.IncTxFailure(src.info.PathName, src.info.ChainID, "Tx Failure")
}
}
}
mp.metricParseTxFailureCatagory(err, src)

errFields = append(errFields, zap.Object("msg", tracker))
errFields = append(errFields, zap.Error(err))
Expand All @@ -586,3 +568,17 @@ func (mp *messageProcessor) sendSingleMessage(

dst.log.Debug(fmt.Sprintf("Successfully broadcasted %s message", msgType), zap.Object("msg", tracker))
}

func (mp *messageProcessor) metricParseTxFailureCatagory(err error, src *pathEndRuntime) {
if mp.metrics == nil {
return
}

for _, promError := range promErrorCatagories {
if errors.Is(err, promError) {
mp.metrics.IncTxFailure(src.info.PathName, src.info.ChainID, promError.Error())
return
}
}
mp.metrics.IncTxFailure(src.info.PathName, src.info.ChainID, "Tx Failure")
}

0 comments on commit 34d3d4f

Please sign in to comment.