Skip to content

Commit d6803ac

Browse files
committed
Create generic metrics
1 parent 05e081b commit d6803ac

File tree

5 files changed

+31
-21
lines changed

5 files changed

+31
-21
lines changed

multinode/go.mod

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ require (
1010
github.com/prometheus/client_golang v1.22.0
1111
github.com/prometheus/client_model v0.6.1
1212
github.com/smartcontractkit/chainlink-common v0.7.0
13-
github.com/smartcontractkit/chainlink-framework/metrics v0.0.0-20250425163146-e2685f8677f7
1413
github.com/stretchr/testify v1.10.0
1514
go.uber.org/zap v1.27.0
1615
)

multinode/go.sum

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,6 @@ github.com/rogpeppe/go-internal v1.13.1 h1:KvO1DLK/DRN07sQ1LQKScxyZJuNnedQ5/wKSR
7272
github.com/rogpeppe/go-internal v1.13.1/go.mod h1:uMEvuHeurkdAXX61udpOXGD/AzZDWNMNyH2VO9fmH0o=
7373
github.com/smartcontractkit/chainlink-common v0.7.0 h1:QThOrHKn+du8CTmzJPCha0Nwnvw0tonIEAQca+dnmE0=
7474
github.com/smartcontractkit/chainlink-common v0.7.0/go.mod h1:pptbsF6z90IGCewkCgDMBxNYjfSOyW9X9l2jzYyQgmk=
75-
github.com/smartcontractkit/chainlink-framework/metrics v0.0.0-20250425163146-e2685f8677f7 h1:s/wTwHj1C2IsW05vziADSHsrqTY2d33VRFZFsumQM9s=
76-
github.com/smartcontractkit/chainlink-framework/metrics v0.0.0-20250425163146-e2685f8677f7/go.mod h1:1D0TYbsfFFNVkPs5QAr5xV6aCpcGukQ+jgwh5G91Fu0=
7775
github.com/smartcontractkit/libocr v0.0.0-20250220133800-f3b940c4f298 h1:PKiqnVOTChlH4a4ljJKL3OKGRgYfIpJS4YD1daAIKks=
7876
github.com/smartcontractkit/libocr v0.0.0-20250220133800-f3b940c4f298/go.mod h1:Mb7+/LC4edz7HyHxX4QkE42pSuov4AV68+AxBXAap0o=
7977
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=

multinode/multi_node.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,14 @@ import (
1010

1111
"github.com/smartcontractkit/chainlink-common/pkg/logger"
1212
"github.com/smartcontractkit/chainlink-common/pkg/services"
13-
"github.com/smartcontractkit/chainlink-framework/metrics"
1413
)
1514

1615
var ErrNodeError = fmt.Errorf("no live nodes available")
1716

17+
type multiNodeMetrics interface {
18+
RecordNodeStates(ctx context.Context, state string, count int64)
19+
}
20+
1821
// MultiNode is a generalized multi node client interface that includes methods to interact with different chains.
1922
// It also handles multiple node RPC connections simultaneously.
2023
type MultiNode[
@@ -28,7 +31,7 @@ type MultiNode[
2831
sendOnlyNodes []SendOnlyNode[CHAIN_ID, RPC]
2932
chainID CHAIN_ID
3033
lggr logger.SugaredLogger
31-
metrics metrics.GenericMultiNodeMetrics
34+
metrics multiNodeMetrics
3235
selectionMode string
3336
nodeSelector NodeSelector[CHAIN_ID, RPC]
3437
leaseDuration time.Duration
@@ -46,7 +49,7 @@ func NewMultiNode[
4649
RPC any,
4750
](
4851
lggr logger.Logger,
49-
metrics metrics.GenericMultiNodeMetrics,
52+
metrics multiNodeMetrics,
5053
selectionMode string, // type of the "best" RPC selector (e.g HighestHead, RoundRobin, etc.)
5154
leaseDuration time.Duration, // defines interval on which new "best" RPC should be selected
5255
primaryNodes []Node[CHAIN_ID, RPC],

multinode/node.go

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import (
44
"context"
55
"errors"
66
"fmt"
7-
"github.com/smartcontractkit/chainlink-framework/metrics"
87
"net/url"
98
"sync"
109
"time"
@@ -38,6 +37,19 @@ type ChainConfig interface {
3837
FinalizedBlockOffset() uint32
3938
}
4039

40+
type nodeMetrics interface {
41+
IncrementNodeVerifies(ctx context.Context, nodeName string)
42+
IncrementNodeVerifiesFailed(ctx context.Context, nodeName string)
43+
IncrementNodeVerifiesSuccess(ctx context.Context, nodeName string)
44+
IncrementNodeTransitionsToAlive(ctx context.Context, nodeName string)
45+
IncrementNodeTransitionsToInSync(ctx context.Context, nodeName string)
46+
IncrementNodeTransitionsToOutOfSync(ctx context.Context, nodeName string)
47+
IncrementNodeTransitionsToUnreachable(ctx context.Context, nodeName string)
48+
IncrementNodeTransitionsToInvalidChainID(ctx context.Context, nodeName string)
49+
IncrementNodeTransitionsToUnusable(ctx context.Context, nodeName string)
50+
IncrementNodeTransitionsToSyncing(ctx context.Context, nodeName string)
51+
}
52+
4153
type Node[
4254
CHAIN_ID ID,
4355
RPC any,
@@ -81,7 +93,7 @@ type node[
8193
order int32
8294
chainFamily string
8395

84-
metrics metrics.GenericMultiNodeMetrics
96+
metrics nodeMetrics
8597

8698
ws *url.URL
8799
http *url.URL
@@ -108,7 +120,7 @@ func NewNode[
108120
nodeCfg NodeConfig,
109121
chainCfg ChainConfig,
110122
lggr logger.Logger,
111-
metrics metrics.GenericMultiNodeMetrics,
123+
metrics nodeMetrics,
112124
wsuri *url.URL,
113125
httpuri *url.URL,
114126
name string,

multinode/transaction_sender.go

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,21 +8,10 @@ import (
88
"sync"
99
"time"
1010

11-
"github.com/prometheus/client_golang/prometheus"
12-
"github.com/prometheus/client_golang/prometheus/promauto"
13-
1411
"github.com/smartcontractkit/chainlink-common/pkg/logger"
1512
"github.com/smartcontractkit/chainlink-common/pkg/services"
1613
)
1714

18-
var (
19-
// PromMultiNodeInvariantViolations reports violation of our assumptions
20-
PromMultiNodeInvariantViolations = promauto.NewCounterVec(prometheus.CounterOpts{
21-
Name: "multi_node_invariant_violations",
22-
Help: "The number of invariant violations",
23-
}, []string{"network", "chainId", "invariant"})
24-
)
25-
2615
type sendTxResult[RESULT any] struct {
2716
res RESULT
2817
code SendTxReturnCode
@@ -37,11 +26,16 @@ type SendTxRPCClient[TX any, RESULT any] interface {
3726
SendTransaction(ctx context.Context, tx TX) (RESULT, SendTxReturnCode, error)
3827
}
3928

29+
type transactionSenderMetrics interface {
30+
IncrementInvariantViolations(ctx context.Context, invariant string)
31+
}
32+
4033
func NewTransactionSender[TX any, RESULT any, CHAIN_ID ID, RPC SendTxRPCClient[TX, RESULT]](
4134
lggr logger.Logger,
4235
chainID CHAIN_ID,
4336
chainFamily string,
4437
multiNode *MultiNode[CHAIN_ID, RPC],
38+
metrics transactionSenderMetrics,
4539
classifyErr func(err error) SendTxReturnCode,
4640
sendTxSoftTimeout time.Duration,
4741
) *TransactionSender[TX, RESULT, CHAIN_ID, RPC] {
@@ -52,6 +46,7 @@ func NewTransactionSender[TX any, RESULT any, CHAIN_ID ID, RPC SendTxRPCClient[T
5246
chainID: chainID,
5347
chainFamily: chainFamily,
5448
lggr: logger.Sugared(lggr).Named("TransactionSender").With("chainID", chainID.String()),
49+
metrics: metrics,
5550
multiNode: multiNode,
5651
classifyErr: classifyErr,
5752
sendTxSoftTimeout: sendTxSoftTimeout,
@@ -64,6 +59,7 @@ type TransactionSender[TX any, RESULT any, CHAIN_ID ID, RPC SendTxRPCClient[TX,
6459
chainID CHAIN_ID
6560
chainFamily string
6661
lggr logger.SugaredLogger
62+
metrics transactionSenderMetrics
6763
multiNode *MultiNode[CHAIN_ID, RPC]
6864
classifyErr func(err error) SendTxReturnCode
6965
sendTxSoftTimeout time.Duration // defines max waiting time from first response til responses evaluation
@@ -199,7 +195,9 @@ func (txSender *TransactionSender[TX, RESULT, CHAIN_ID, RPC]) reportSendTxAnomal
199195
_, criticalErr := aggregateTxResults(resultsByCode)
200196
if criticalErr != nil {
201197
txSender.lggr.Criticalw("observed invariant violation on SendTransaction", "tx", tx, "resultsByCode", resultsByCode, "err", criticalErr)
202-
PromMultiNodeInvariantViolations.WithLabelValues(txSender.chainFamily, txSender.chainID.String(), criticalErr.Error()).Inc()
198+
ctx, cancel := txSender.chStop.NewCtx()
199+
defer cancel()
200+
txSender.metrics.IncrementInvariantViolations(ctx, criticalErr.Error())
203201
}
204202
}
205203

0 commit comments

Comments
 (0)