-
Notifications
You must be signed in to change notification settings - Fork 12
/
metrics_conflicts.go
58 lines (52 loc) · 2.35 KB
/
metrics_conflicts.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
package prometheus
import (
"time"
"github.com/iotaledger/hive.go/runtime/event"
"github.com/iotaledger/iota-core/components/prometheus/collector"
iotago "github.com/iotaledger/iota.go/v4"
)
const (
conflictNamespace = "conflict"
resolutionTime = "resolution_time_seconds_total"
allConflictCounts = "created_total"
resolvedConflictCount = "resolved_total"
)
var ConflictMetrics = collector.NewCollection(conflictNamespace,
collector.WithMetric(collector.NewMetric(resolutionTime,
collector.WithType(collector.Counter),
collector.WithHelp("Time since transaction issuance to the conflict acceptance"),
collector.WithInitFunc(func() {
deps.Protocol.Events.Engine.SpendDAG.SpenderAccepted.Hook(func(spendID iotago.TransactionID) {
if txMetadata, exists := deps.Protocol.Engines.Main.Get().Ledger.MemPool().TransactionMetadata(spendID); exists {
firstAttachmentID := txMetadata.EarliestIncludedAttachment()
if block, blockExists := deps.Protocol.Engines.Main.Get().BlockFromCache(firstAttachmentID); blockExists {
timeSinceIssuance := time.Since(block.IssuingTime()).Milliseconds()
timeIssuanceSeconds := float64(timeSinceIssuance) / 1000
deps.Collector.Update(conflictNamespace, resolutionTime, timeIssuanceSeconds)
}
}
}, event.WithWorkerPool(Component.WorkerPool))
}),
)),
collector.WithMetric(collector.NewMetric(resolvedConflictCount,
collector.WithType(collector.Counter),
collector.WithHelp("Number of resolved (accepted) conflicts"),
collector.WithInitFunc(func() {
deps.Protocol.Events.Engine.SpendDAG.SpenderAccepted.Hook(func(_ iotago.TransactionID) {
deps.Collector.Increment(conflictNamespace, resolvedConflictCount)
}, event.WithWorkerPool(Component.WorkerPool))
deps.Protocol.Events.Engine.SpendDAG.SpenderRejected.Hook(func(_ iotago.TransactionID) {
deps.Collector.Increment(conflictNamespace, resolvedConflictCount)
}, event.WithWorkerPool(Component.WorkerPool))
}),
)),
collector.WithMetric(collector.NewMetric(allConflictCounts,
collector.WithType(collector.Counter),
collector.WithHelp("Number of created conflicts"),
collector.WithInitFunc(func() {
deps.Protocol.Events.Engine.SpendDAG.SpenderCreated.Hook(func(_ iotago.TransactionID) {
deps.Collector.Increment(conflictNamespace, allConflictCounts)
}, event.WithWorkerPool(Component.WorkerPool))
}),
)),
)