@@ -31,31 +31,7 @@ func (m *Metrics) HandleFailureEvent(ctx context.Context, id types.RetrievalID,
31
31
if storageProviderID != types .BitswapIndentifier {
32
32
m .graphsyncRetrievalFailureCount .Add (ctx , 1 , attribute .String ("sp_id" , storageProviderID ))
33
33
}
34
- var errorMetricMatches = map [string ]instrument.Int64Counter {
35
- "response rejected" : m .retrievalErrorRejectedCount ,
36
- "Too many retrieval deals received" : m .retrievalErrorTooManyCount ,
37
- "Access Control" : m .retrievalErrorACLCount ,
38
- "Under maintenance, retry later" : m .retrievalErrorMaintenanceCount ,
39
- "miner is not accepting online retrieval deals" : m .retrievalErrorNoOnlineCount ,
40
- "unconfirmed block transfer" : m .retrievalErrorUnconfirmedCount ,
41
- "timeout after " : m .retrievalErrorTimeoutCount ,
42
- "there is no unsealed piece containing payload cid" : m .retrievalErrorNoUnsealedCount ,
43
- "getting pieces for cid" : m .retrievalErrorDAGStoreCount ,
44
- "graphsync request failed to complete: request failed - unknown reason" : m .retrievalErrorGraphsyncCount ,
45
- "failed to dial" : m .retrievalErrorFailedToDialCount ,
46
- }
47
-
48
- var matched bool
49
- for substr , metric := range errorMetricMatches {
50
- if strings .Contains (msg , substr ) {
51
- metric .Add (ctx , 1 , attribute .String ("protocol" , protocol (storageProviderID )))
52
- matched = true
53
- break
54
- }
55
- }
56
- if ! matched {
57
- m .retrievalErrorOtherCount .Add (ctx , 1 , attribute .String ("protocol" , protocol (storageProviderID )))
58
- }
34
+ m .matchErrorMessage (ctx , msg , storageProviderID )
59
35
}
60
36
}
61
37
@@ -158,6 +134,101 @@ func (m *Metrics) HandleSuccessEvent(ctx context.Context, id types.RetrievalID,
158
134
m .failedRetrievalsPerRequestCount .Record (ctx , int64 (finalDetails .FailedCount ))
159
135
}
160
136
137
+ func (m * Metrics ) HandleAggregatedEvent (ctx context.Context ,
138
+ timeToFirstIndexerResult time.Duration ,
139
+ timeToFirstByte time.Duration ,
140
+ success bool ,
141
+ storageProviderID string ,
142
+ startTime time.Time ,
143
+ endTime time.Time ,
144
+ bandwidth int64 ,
145
+ bytesTransferred int64 ,
146
+ indexerCandidates int64 ,
147
+ indexerFiltered int64 ,
148
+ attempts map [string ]string ) {
149
+ m .totalRequestCount .Add (ctx , 1 )
150
+ failureCount := 0
151
+ var recordedGraphSync , recordedBitswap bool
152
+ for storageProviderID , msg := range attempts {
153
+ if storageProviderID == types .BitswapIndentifier {
154
+ if ! recordedBitswap {
155
+ recordedBitswap = true
156
+ m .requestWithBitswapAttempt .Add (ctx , 1 )
157
+ }
158
+ } else {
159
+ if ! recordedGraphSync {
160
+ recordedGraphSync = true
161
+ m .requestWithGraphSyncAttempt .Add (ctx , 1 , attribute .String ("sp_id" , storageProviderID ))
162
+ }
163
+ }
164
+ if msg != "" {
165
+ if storageProviderID != types .BitswapIndentifier {
166
+ m .graphsyncRetrievalFailureCount .Add (ctx , 1 , attribute .String ("sp_id" , storageProviderID ))
167
+ }
168
+ m .matchErrorMessage (ctx , msg , storageProviderID )
169
+ failureCount += 0
170
+ }
171
+ }
172
+ if timeToFirstIndexerResult > 0 {
173
+ m .timeToFirstIndexerResult .Record (ctx , timeToFirstIndexerResult .Seconds ())
174
+ }
175
+ if indexerCandidates > 0 {
176
+ m .requestWithIndexerCandidatesCount .Add (ctx , 1 )
177
+ }
178
+ if indexerFiltered > 0 {
179
+ m .requestWithIndexerCandidatesFilteredCount .Add (ctx , 1 )
180
+ }
181
+ if timeToFirstByte > 0 {
182
+ m .requestWithFirstByteReceivedCount .Add (ctx , 1 , attribute .String ("protocol" , protocol (storageProviderID )))
183
+ m .timeToFirstByte .Record (ctx , timeToFirstByte .Seconds (), attribute .String ("protocol" , protocol (storageProviderID )))
184
+ }
185
+ if success {
186
+ m .requestWithSuccessCount .Add (ctx , 1 )
187
+ if storageProviderID == types .BitswapIndentifier {
188
+ m .requestWithBitswapSuccessCount .Add (ctx , 1 )
189
+ } else {
190
+ m .requestWithGraphSyncSuccessCount .Add (ctx , 1 , attribute .String ("sp_id" , storageProviderID ))
191
+ }
192
+
193
+ m .retrievalDealDuration .Record (ctx , endTime .Sub (startTime ).Seconds (), attribute .String ("protocol" , protocol (storageProviderID )))
194
+ m .retrievalDealSize .Record (ctx , bytesTransferred , attribute .String ("protocol" , protocol (storageProviderID )))
195
+ m .bandwidthBytesPerSecond .Record (ctx , bandwidth , attribute .String ("protocol" , protocol (storageProviderID )))
196
+
197
+ m .indexerCandidatesPerRequestCount .Record (ctx , indexerCandidates )
198
+ m .indexerCandidatesFilteredPerRequestCount .Record (ctx , indexerFiltered )
199
+ m .failedRetrievalsPerRequestCount .Record (ctx , int64 (failureCount ))
200
+ } else if len (attempts ) == 0 {
201
+ m .requestWithIndexerFailures .Add (ctx , 1 )
202
+ }
203
+ }
204
+
205
+ func (m * Metrics ) matchErrorMessage (ctx context.Context , msg string , storageProviderID string ) {
206
+ var errorMetricMatches = map [string ]instrument.Int64Counter {
207
+ "response rejected" : m .retrievalErrorRejectedCount ,
208
+ "Too many retrieval deals received" : m .retrievalErrorTooManyCount ,
209
+ "Access Control" : m .retrievalErrorACLCount ,
210
+ "Under maintenance, retry later" : m .retrievalErrorMaintenanceCount ,
211
+ "miner is not accepting online retrieval deals" : m .retrievalErrorNoOnlineCount ,
212
+ "unconfirmed block transfer" : m .retrievalErrorUnconfirmedCount ,
213
+ "timeout after " : m .retrievalErrorTimeoutCount ,
214
+ "there is no unsealed piece containing payload cid" : m .retrievalErrorNoUnsealedCount ,
215
+ "getting pieces for cid" : m .retrievalErrorDAGStoreCount ,
216
+ "graphsync request failed to complete: request failed - unknown reason" : m .retrievalErrorGraphsyncCount ,
217
+ "failed to dial" : m .retrievalErrorFailedToDialCount ,
218
+ }
219
+
220
+ var matched bool
221
+ for substr , metric := range errorMetricMatches {
222
+ if strings .Contains (msg , substr ) {
223
+ metric .Add (ctx , 1 , attribute .String ("protocol" , protocol (storageProviderID )))
224
+ matched = true
225
+ break
226
+ }
227
+ }
228
+ if ! matched {
229
+ m .retrievalErrorOtherCount .Add (ctx , 1 , attribute .String ("protocol" , protocol (storageProviderID )))
230
+ }
231
+ }
161
232
func protocol (storageProviderId string ) string {
162
233
if storageProviderId == types .BitswapIndentifier {
163
234
return "bitswap"
0 commit comments