Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix prom reporter throwing an error when TXM is disabled #16058

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions core/services/headreporter/prometheus_reporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"fmt"
"math/big"
"strings"
"time"

"github.com/pkg/errors"
Expand Down Expand Up @@ -92,6 +93,9 @@ func (pr *prometheusReporter) reportPendingEthTxes(ctx context.Context, evmChain

unconfirmed, err := txm.CountTransactionsByState(ctx, txmgrcommon.TxUnconfirmed)
if err != nil {
if strings.Contains(err.Error(), "disabled") {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to use errors.Is?

Suggested change
if strings.Contains(err.Error(), "disabled") {
if errors.Is(err, disabledErr) {

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh it looks like that would requires a framework update

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return nil
}
return fmt.Errorf("failed to query for unconfirmed eth_tx count: %w", err)
}
pr.backend.SetUnconfirmedTransactions(evmChainID, int64(unconfirmed))
Expand All @@ -106,6 +110,9 @@ func (pr *prometheusReporter) reportMaxUnconfirmedAge(ctx context.Context, evmCh

broadcastAt, err := txm.FindEarliestUnconfirmedBroadcastTime(ctx)
if err != nil {
if strings.Contains(err.Error(), "disabled") {
return nil
}
return fmt.Errorf("failed to query for min broadcast time: %w", err)
}

Expand All @@ -125,6 +132,9 @@ func (pr *prometheusReporter) reportMaxUnconfirmedBlocks(ctx context.Context, he

earliestUnconfirmedTxBlock, err := txm.FindEarliestUnconfirmedTxAttemptBlock(ctx)
if err != nil {
if strings.Contains(err.Error(), "disabled") {
return nil
}
return fmt.Errorf("failed to query for earliest unconfirmed tx block: %w", err)
}

Expand Down
20 changes: 20 additions & 0 deletions core/services/headreporter/prometheus_reporter_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package headreporter_test

import (
"fmt"
"math/big"
"testing"
"time"
Expand Down Expand Up @@ -45,6 +46,18 @@ func Test_PrometheusReporter(t *testing.T) {
require.NoError(t, err)
})

t.Run("with null txm", func(t *testing.T) {
db := pgtest.NewSqlxDB(t)
backend := headreporter.NewMockPrometheusBackend(t)

reporter := headreporter.NewPrometheusReporter(db, newLegacyChainContainerWithNullTxm(t))
reporter.SetBackend(backend)

head := headreporter.NewHead()
err := reporter.ReportNewHead(testutils.Context(t), &head)
require.NoError(t, err)
})

t.Run("with unconfirmed evm.txes", func(t *testing.T) {
db := pgtest.NewSqlxDB(t)
txStore := cltest.NewTestTxStore(t, db)
Expand Down Expand Up @@ -142,3 +155,10 @@ func newLegacyChainContainer(t *testing.T, db *sqlx.DB) legacyevm.LegacyChainCon
cfg := configtest.NewGeneralConfig(t, nil)
return cltest.NewLegacyChainsWithMockChainAndTxManager(t, ethClient, cfg, txm)
}

func newLegacyChainContainerWithNullTxm(t *testing.T) legacyevm.LegacyChainContainer {
ethClient := evmtest.NewEthClientMockWithDefaultChain(t)
txm := &txmgr.NullTxManager{ErrMsg: fmt.Sprintf("TXM disabled for chain %d", ethClient.ConfiguredChainID())}
cfg := configtest.NewGeneralConfig(t, nil)
return cltest.NewLegacyChainsWithMockChainAndTxManager(t, ethClient, cfg, txm)
}
Loading