-
Notifications
You must be signed in to change notification settings - Fork 178
/
main.go
61 lines (51 loc) · 1.97 KB
/
main.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
package main
import (
"math/rand"
"time"
"github.com/rs/zerolog"
"github.com/onflow/flow-go/engine"
"github.com/onflow/flow-go/module/metrics"
"github.com/onflow/flow-go/module/metrics/example"
"github.com/onflow/flow-go/module/trace"
"github.com/onflow/flow-go/network/queue"
"github.com/onflow/flow-go/utils/unittest"
)
func main() {
example.WithMetricsServer(func(logger zerolog.Logger) {
tracer, err := trace.NewTracer(logger, "collection", "test", trace.SensitivityCaptureAll)
if err != nil {
panic(err)
}
collector := struct {
*metrics.HotstuffCollector
*metrics.CollectionCollector
*metrics.NetworkCollector
}{
HotstuffCollector: metrics.NewHotstuffCollector("some_chain_id"),
CollectionCollector: metrics.NewCollectionCollector(tracer),
NetworkCollector: metrics.NewNetworkCollector(),
}
topic1 := engine.TestNetwork.String()
topic2 := engine.TestMetrics.String()
message1 := "CollectionRequest"
message2 := "ClusterBlockProposal"
for i := 0; i < 100; i++ {
collector.TransactionIngested(unittest.IdentifierFixture())
collector.HotStuffBusyDuration(10, metrics.HotstuffEventTypeTimeout)
collector.HotStuffWaitDuration(10, metrics.HotstuffEventTypeTimeout)
collector.HotStuffIdleDuration(10)
collector.SetCurView(uint64(i))
collector.SetQCView(uint64(i))
collector.NetworkMessageSent(rand.Intn(1000), topic1, message1)
collector.NetworkMessageSent(rand.Intn(1000), topic2, message2)
collector.NetworkMessageReceived(rand.Intn(1000), topic1, message1)
collector.NetworkMessageReceived(rand.Intn(1000), topic2, message2)
priority1 := rand.Intn(int(queue.HighPriority-queue.LowPriority+1)) + int(queue.LowPriority)
collector.MessageRemoved(priority1)
collector.QueueDuration(time.Millisecond*time.Duration(rand.Intn(1000)), priority1)
priority2 := rand.Intn(int(queue.HighPriority-queue.LowPriority+1)) + int(queue.LowPriority)
collector.MessageAdded(priority2)
time.Sleep(1 * time.Second)
}
})
}