Skip to content

Commit adad659

Browse files
authored
fix uninitialized metrics (#662)
fix uninitialized metrics (#662)
1 parent 6c1c9c2 commit adad659

File tree

4 files changed

+36
-38
lines changed

4 files changed

+36
-38
lines changed

common/monitoring/metricsMonitoring.go

Lines changed: 31 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -15,26 +15,25 @@ var (
1515
isMonitoringActive bool
1616
nodePublicKey []byte
1717

18-
receiptCounter prometheus.Counter
19-
unresolvedPeersCounter prometheus.Gauge
20-
resolvedPeersCounter prometheus.Gauge
21-
unresolvedPriorityPeersCounter prometheus.Gauge
22-
resolvedPriorityPeersCounter prometheus.Gauge
23-
activeRegisteredNodesGauge prometheus.Gauge
24-
nodeScore prometheus.Gauge
25-
blockerCounterVector *prometheus.CounterVec
26-
statusLockGaugeVector *prometheus.GaugeVec
27-
blockchainStatusGaugeVector *prometheus.GaugeVec
28-
blockchainSmithTimeGaugeVector *prometheus.GaugeVec
29-
blockchainIDMsbGaugeVector *prometheus.GaugeVec
30-
blockchainIDLsbGaugeVector *prometheus.GaugeVec
31-
blockchainHeightGaugeVector *prometheus.GaugeVec
32-
goRoutineActivityGaugeVector *prometheus.GaugeVec
33-
downloadCycleDebuggerGaugeVector *prometheus.GaugeVec
34-
apiGaugeVector *prometheus.GaugeVec
35-
apiRunningGaugeVector *prometheus.GaugeVec
36-
snapshotDownloadRequestCounter prometheus.Counter
37-
snapshotDownloadRequestFailedCounter prometheus.Counter
18+
receiptCounter prometheus.Counter
19+
unresolvedPeersCounter prometheus.Gauge
20+
resolvedPeersCounter prometheus.Gauge
21+
unresolvedPriorityPeersCounter prometheus.Gauge
22+
resolvedPriorityPeersCounter prometheus.Gauge
23+
activeRegisteredNodesGauge prometheus.Gauge
24+
nodeScore prometheus.Gauge
25+
blockerCounterVector *prometheus.CounterVec
26+
statusLockGaugeVector *prometheus.GaugeVec
27+
blockchainStatusGaugeVector *prometheus.GaugeVec
28+
blockchainSmithTimeGaugeVector *prometheus.GaugeVec
29+
blockchainIDMsbGaugeVector *prometheus.GaugeVec
30+
blockchainIDLsbGaugeVector *prometheus.GaugeVec
31+
blockchainHeightGaugeVector *prometheus.GaugeVec
32+
goRoutineActivityGaugeVector *prometheus.GaugeVec
33+
downloadCycleDebuggerGaugeVector *prometheus.GaugeVec
34+
apiGaugeVector *prometheus.GaugeVec
35+
apiRunningGaugeVector *prometheus.GaugeVec
36+
snapshotDownloadRequestCounter *prometheus.CounterVec
3837
)
3938

4039
const (
@@ -111,7 +110,7 @@ func SetMonitoringActive(isActive bool) {
111110
statusLockGaugeVector = prometheus.NewGaugeVec(prometheus.GaugeOpts{
112111
Name: "zoobc_status_lock",
113112
Help: "Status lock counter",
114-
}, []string{"blocker_type"})
113+
}, []string{"chaintype", "status_type"})
115114
prometheus.MustRegister(statusLockGaugeVector)
116115

117116
blockchainStatusGaugeVector = prometheus.NewGaugeVec(prometheus.GaugeOpts{
@@ -174,12 +173,11 @@ func SetMonitoringActive(isActive bool) {
174173
}, []string{"api_name"})
175174
prometheus.MustRegister(apiRunningGaugeVector)
176175

177-
snapshotDownloadRequestFailedCounter = prometheus.NewCounter(prometheus.CounterOpts{
178-
Name: fmt.Sprintf("zoobc_snapshot_chunk_downloads_failed"),
179-
Help: fmt.Sprintf("snapshot file chunks failed to download"),
180-
})
181-
prometheus.MustRegister(snapshotDownloadRequestFailedCounter)
182-
176+
snapshotDownloadRequestCounter = prometheus.NewCounterVec(prometheus.CounterOpts{
177+
Name: fmt.Sprintf("zoobc_snapshot_chunk_downloads_status"),
178+
Help: fmt.Sprintf("snapshot file chunks to download"),
179+
}, []string{"status"})
180+
prometheus.MustRegister(snapshotDownloadRequestCounter)
183181
}
184182

185183
func SetNodePublicKey(pk []byte) {
@@ -246,20 +244,20 @@ func IncrementBlockerMetrics(typeBlocker string) {
246244
blockerCounterVector.WithLabelValues(typeBlocker).Inc()
247245
}
248246

249-
func IncrementStatusLockCounter(typeStatusLock int) {
247+
func IncrementStatusLockCounter(chaintype chaintype.ChainType, typeStatusLock int) {
250248
if !isMonitoringActive {
251249
return
252250
}
253251

254-
statusLockGaugeVector.WithLabelValues(fmt.Sprintf("%d", typeStatusLock)).Inc()
252+
statusLockGaugeVector.WithLabelValues(chaintype.GetName(), fmt.Sprintf("%d", typeStatusLock)).Inc()
255253
}
256254

257-
func DecrementStatusLockCounter(typeStatusLock int) {
255+
func DecrementStatusLockCounter(chaintype chaintype.ChainType, typeStatusLock int) {
258256
if !isMonitoringActive {
259257
return
260258
}
261259

262-
statusLockGaugeVector.WithLabelValues(fmt.Sprintf("%d", typeStatusLock)).Dec()
260+
statusLockGaugeVector.WithLabelValues(chaintype.GetName(), fmt.Sprintf("%d", typeStatusLock)).Dec()
263261
}
264262

265263
func SetBlockchainStatus(chainType chaintype.ChainType, newStatus int) {
@@ -366,9 +364,9 @@ func IncrementSnapshotDownloadCounter(succeeded, failed int32) {
366364
}
367365

368366
if succeeded > 0 {
369-
snapshotDownloadRequestCounter.Add(float64(succeeded))
367+
snapshotDownloadRequestCounter.WithLabelValues("success").Add(float64(succeeded))
370368
}
371369
if failed > 0 {
372-
snapshotDownloadRequestFailedCounter.Add(float64(failed))
370+
snapshotDownloadRequestCounter.WithLabelValues("failed").Add(float64(failed))
373371
}
374372
}

core/service/blockMainService.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,15 +213,15 @@ func (bs *BlockService) GetBlocksmithStrategy() strategy.BlocksmithStrategyInter
213213

214214
// ChainWriteLock locks the chain
215215
func (bs *BlockService) ChainWriteLock(actionType int) {
216-
monitoring.IncrementStatusLockCounter(actionType)
216+
monitoring.IncrementStatusLockCounter(bs.Chaintype, actionType)
217217
bs.Lock()
218218
monitoring.SetBlockchainStatus(bs.Chaintype, actionType)
219219
}
220220

221221
// ChainWriteUnlock unlocks the chain
222222
func (bs *BlockService) ChainWriteUnlock(actionType int) {
223223
monitoring.SetBlockchainStatus(bs.Chaintype, constant.BlockchainStatusIdle)
224-
monitoring.DecrementStatusLockCounter(actionType)
224+
monitoring.DecrementStatusLockCounter(bs.Chaintype, actionType)
225225
bs.Unlock()
226226
}
227227

core/service/blockSpineService.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,15 +138,15 @@ func (bs *BlockSpineService) GetBlocksmithStrategy() strategy.BlocksmithStrategy
138138

139139
// ChainWriteLock locks the chain
140140
func (bs *BlockSpineService) ChainWriteLock(actionType int) {
141-
monitoring.IncrementStatusLockCounter(actionType)
141+
monitoring.IncrementStatusLockCounter(bs.Chaintype, actionType)
142142
bs.Lock()
143143
monitoring.SetBlockchainStatus(bs.Chaintype, actionType)
144144
}
145145

146146
// ChainWriteUnlock unlocks the chain
147147
func (bs *BlockSpineService) ChainWriteUnlock(actionType int) {
148148
monitoring.SetBlockchainStatus(bs.Chaintype, constant.BlockchainStatusIdle)
149-
monitoring.DecrementStatusLockCounter(actionType)
149+
monitoring.DecrementStatusLockCounter(bs.Chaintype, actionType)
150150
bs.Unlock()
151151
}
152152

0 commit comments

Comments
 (0)