-
Notifications
You must be signed in to change notification settings - Fork 142
/
chain_state.go
68 lines (53 loc) · 2.16 KB
/
chain_state.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
68
package metrics
import (
"github.com/prometheus/client_golang/prometheus"
"github.com/iotaledger/wasp/packages/isc"
)
type IChainStateMetrics interface {
SetChainActiveStateWant(stateIndex uint32)
SetChainActiveStateHave(stateIndex uint32)
SetChainConfirmedStateWant(stateIndex uint32)
SetChainConfirmedStateHave(stateIndex uint32)
}
var (
_ IChainStateMetrics = &emptyChainStateMetric{}
_ IChainStateMetrics = &chainStateMetric{}
)
type emptyChainStateMetric struct{}
func NewEmptyChainStateMetric() IChainStateMetrics {
return &emptyChainStateMetric{}
}
func (m *emptyChainStateMetric) SetChainActiveStateWant(stateIndex uint32) {}
func (m *emptyChainStateMetric) SetChainActiveStateHave(stateIndex uint32) {}
func (m *emptyChainStateMetric) SetChainConfirmedStateWant(stateIndex uint32) {}
func (m *emptyChainStateMetric) SetChainConfirmedStateHave(stateIndex uint32) {}
type chainStateMetric struct {
provider *ChainMetricsProvider
metricsLabels prometheus.Labels
lastSeenStateIndexVal uint32
}
func newChainStateMetric(provider *ChainMetricsProvider, chainID isc.ChainID) *chainStateMetric {
metricsLabels := getChainLabels(chainID)
// init values so they appear in prometheus
provider.chainActiveStateWant.With(metricsLabels)
provider.chainActiveStateHave.With(metricsLabels)
provider.chainConfirmedStateWant.With(metricsLabels)
provider.chainConfirmedStateHave.With(metricsLabels)
return &chainStateMetric{
provider: provider,
metricsLabels: metricsLabels,
lastSeenStateIndexVal: 0,
}
}
func (m *chainStateMetric) SetChainActiveStateWant(stateIndex uint32) {
m.provider.chainActiveStateWant.With(m.metricsLabels).Set(float64(stateIndex))
}
func (m *chainStateMetric) SetChainActiveStateHave(stateIndex uint32) {
m.provider.chainActiveStateHave.With(m.metricsLabels).Set(float64(stateIndex))
}
func (m *chainStateMetric) SetChainConfirmedStateWant(stateIndex uint32) {
m.provider.chainConfirmedStateWant.With(m.metricsLabels).Set(float64(stateIndex))
}
func (m *chainStateMetric) SetChainConfirmedStateHave(stateIndex uint32) {
m.provider.chainConfirmedStateHave.With(m.metricsLabels).Set(float64(stateIndex))
}