-
Notifications
You must be signed in to change notification settings - Fork 0
/
metrics.go
154 lines (134 loc) · 4.64 KB
/
metrics.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
/*
Copyright IBM Corp. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/
package mocks
import (
"github.com/hyperledger/fabric/common/metrics"
"github.com/hyperledger/fabric/common/metrics/metricsfakes"
gmetrics "github.com/hyperledger/fabric/gossip/metrics"
)
type TestMetricProvider struct {
FakeProvider *metricsfakes.Provider
FakeHeightGauge *metricsfakes.Gauge
FakeCommitDurationHist *metricsfakes.Histogram
FakePayloadBufferSizeGauge *metricsfakes.Gauge
FakeDeclarationGauge *metricsfakes.Gauge
FakeSentMessages *metricsfakes.Counter
FakeBufferOverflow *metricsfakes.Counter
FakeReceivedMessages *metricsfakes.Counter
FakeTotalGauge *metricsfakes.Gauge
FakeValidationDuration *metricsfakes.Histogram
FakeListMissingPrivateDataDuration *metricsfakes.Histogram
FakeFetchDuration *metricsfakes.Histogram
FakeCommitPrivateDataDuration *metricsfakes.Histogram
FakePurgeDuration *metricsfakes.Histogram
FakeSendDuration *metricsfakes.Histogram
FakeReconciliationDuration *metricsfakes.Histogram
FakePullDuration *metricsfakes.Histogram
FakeRetrieveDuration *metricsfakes.Histogram
}
func TestUtilConstructMetricProvider() *TestMetricProvider {
fakeProvider := &metricsfakes.Provider{}
fakeHeightGauge := testUtilConstructGauge()
fakeCommitDurationHist := testUtilConstructHist()
fakePayloadBufferSizeGauge := testUtilConstructGauge()
fakeDeclarationGauge := testUtilConstructGauge()
fakeSentMessages := testUtilConstructCounter()
fakeBufferOverflow := testUtilConstructCounter()
fakeReceivedMessages := testUtilConstructCounter()
fakeTotalGauge := testUtilConstructGauge()
fakeValidationDuration := testUtilConstructHist()
fakeListMissingPrivateDataDuration := testUtilConstructHist()
fakeFetchDuration := testUtilConstructHist()
fakeCommitPrivateDataDuration := testUtilConstructHist()
fakePurgeDuration := testUtilConstructHist()
fakeSendDuration := testUtilConstructHist()
fakeReconciliationDuration := testUtilConstructHist()
fakePullDuration := testUtilConstructHist()
fakeRetrieveDuration := testUtilConstructHist()
fakeProvider.NewCounterStub = func(opts metrics.CounterOpts) metrics.Counter {
switch opts.Name {
case gmetrics.BufferOverflowOpts.Name:
return fakeBufferOverflow
case gmetrics.SentMessagesOpts.Name:
return fakeSentMessages
case gmetrics.ReceivedMessagesOpts.Name:
return fakeReceivedMessages
}
return nil
}
fakeProvider.NewHistogramStub = func(opts metrics.HistogramOpts) metrics.Histogram {
switch opts.Name {
case gmetrics.CommitDurationOpts.Name:
return fakeCommitDurationHist
case gmetrics.ValidationDurationOpts.Name:
return fakeValidationDuration
case gmetrics.ListMissingPrivateDataDurationOpts.Name:
return fakeListMissingPrivateDataDuration
case gmetrics.FetchDurationOpts.Name:
return fakeFetchDuration
case gmetrics.CommitPrivateDataDurationOpts.Name:
return fakeCommitPrivateDataDuration
case gmetrics.PurgeDurationOpts.Name:
return fakePurgeDuration
case gmetrics.SendDurationOpts.Name:
return fakeSendDuration
case gmetrics.ReconciliationDurationOpts.Name:
return fakeReconciliationDuration
case gmetrics.PullDurationOpts.Name:
return fakePullDuration
case gmetrics.RetrieveDurationOpts.Name:
return fakeRetrieveDuration
}
return nil
}
fakeProvider.NewGaugeStub = func(opts metrics.GaugeOpts) metrics.Gauge {
switch opts.Name {
case gmetrics.PayloadBufferSizeOpts.Name:
return fakePayloadBufferSizeGauge
case gmetrics.HeightOpts.Name:
return fakeHeightGauge
case gmetrics.LeaderDeclerationOpts.Name:
return fakeDeclarationGauge
case gmetrics.TotalOpts.Name:
return fakeTotalGauge
}
return nil
}
return &TestMetricProvider{
fakeProvider,
fakeHeightGauge,
fakeCommitDurationHist,
fakePayloadBufferSizeGauge,
fakeDeclarationGauge,
fakeSentMessages,
fakeBufferOverflow,
fakeReceivedMessages,
fakeTotalGauge,
fakeValidationDuration,
fakeListMissingPrivateDataDuration,
fakeFetchDuration,
fakeCommitPrivateDataDuration,
fakePurgeDuration,
fakeSendDuration,
fakeReconciliationDuration,
fakePullDuration,
fakeRetrieveDuration,
}
}
func testUtilConstructGauge() *metricsfakes.Gauge {
fakeGauge := &metricsfakes.Gauge{}
fakeGauge.WithReturns(fakeGauge)
return fakeGauge
}
func testUtilConstructHist() *metricsfakes.Histogram {
fakeHist := &metricsfakes.Histogram{}
fakeHist.WithReturns(fakeHist)
return fakeHist
}
func testUtilConstructCounter() *metricsfakes.Counter {
fakeCounter := &metricsfakes.Counter{}
fakeCounter.WithReturns(fakeCounter)
return fakeCounter
}