-
Notifications
You must be signed in to change notification settings - Fork 147
/
chain_node_conn.go
67 lines (54 loc) · 2.21 KB
/
chain_node_conn.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package metrics
import (
"time"
"github.com/prometheus/client_golang/prometheus"
"github.com/iotaledger/wasp/packages/isc"
)
type IChainNodeConnMetrics interface {
L1RequestReceived()
L1AliasOutputReceived()
TXPublishStarted()
TXPublishResult(confirmed bool, duration time.Duration)
}
var (
_ IChainNodeConnMetrics = &emptyChainNodeConnMetric{}
_ IChainNodeConnMetrics = &chainNodeConnMetric{}
)
type emptyChainNodeConnMetric struct{}
func NewEmptyChainNodeConnMetric() IChainNodeConnMetrics {
return &emptyChainNodeConnMetric{}
}
func (m *emptyChainNodeConnMetric) L1RequestReceived() {}
func (m *emptyChainNodeConnMetric) L1AliasOutputReceived() {}
func (m *emptyChainNodeConnMetric) TXPublishStarted() {}
func (m *emptyChainNodeConnMetric) TXPublishResult(confirmed bool, duration time.Duration) {}
type chainNodeConnMetric struct {
ncL1RequestReceived prometheus.Counter
ncL1AliasOutputReceived prometheus.Counter
ncTXPublishStarted prometheus.Counter
ncTXPublishResult map[bool]prometheus.Observer
}
func newChainNodeConnMetric(provider *ChainMetricsProvider, chainID isc.ChainID) *chainNodeConnMetric {
chainLabels := getChainLabels(chainID)
return &chainNodeConnMetric{
ncL1RequestReceived: provider.ncL1RequestReceived.With(chainLabels),
ncL1AliasOutputReceived: provider.ncL1AliasOutputReceived.With(chainLabels),
ncTXPublishStarted: provider.ncTXPublishStarted.With(chainLabels),
ncTXPublishResult: map[bool]prometheus.Observer{
true: provider.ncTXPublishResult.MustCurryWith(chainLabels).With(prometheus.Labels{labelTxPublishResult: "confirmed"}),
false: provider.ncTXPublishResult.MustCurryWith(chainLabels).With(prometheus.Labels{labelTxPublishResult: "rejected"}),
},
}
}
func (m *chainNodeConnMetric) L1RequestReceived() {
m.ncL1RequestReceived.Inc()
}
func (m *chainNodeConnMetric) L1AliasOutputReceived() {
m.ncL1AliasOutputReceived.Inc()
}
func (m *chainNodeConnMetric) TXPublishStarted() {
m.ncTXPublishStarted.Inc()
}
func (m *chainNodeConnMetric) TXPublishResult(confirmed bool, duration time.Duration) {
m.ncTXPublishResult[confirmed].Observe(duration.Seconds())
}