Skip to content

Commit

Permalink
fix: cosmos_relayer_tx_failure metric
Browse files Browse the repository at this point in the history
  • Loading branch information
boojamya committed Nov 21, 2023
1 parent d0b2700 commit d9fe686
Showing 1 changed file with 28 additions and 28 deletions.
56 changes: 28 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.metricExportTxFailure(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.metricExportTxFailure(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.metricExportTxFailure(err, src)

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

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

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

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

0 comments on commit d9fe686

Please sign in to comment.