-
Notifications
You must be signed in to change notification settings - Fork 17
/
stats.go
57 lines (46 loc) · 1.13 KB
/
stats.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
// Copyright (C) 2022 Storj Labs, Inc.
// See LICENSE for copying information.
package uplink
import (
"context"
"time"
"github.com/zeebo/errs"
"storj.io/common/paths"
"storj.io/common/rpc"
"storj.io/common/storj"
)
const eventErrorMessageLimit = 64
type operationStats struct {
start time.Time
quicRollout int
bytes int64
working time.Duration
failure []error
satellite string
encPath paths.Encrypted
}
func newOperationStats(ctx context.Context, satellite storj.NodeURL) (os operationStats) {
os.start = time.Now()
os.quicRollout = rpc.QUICRolloutPercent(ctx)
os.satellite = satellite.String()
return os
}
func (os *operationStats) trackWorking() func() {
start := time.Now()
return func() { os.working += time.Since(start) }
}
func (os *operationStats) flagFailure(err error) {
if err != nil {
os.failure = append(os.failure, err)
}
}
func (os *operationStats) err() (message string, err error) {
err = errs.Combine(os.failure...)
if err != nil {
message = err.Error()
if len(message) > eventErrorMessageLimit {
message = message[:eventErrorMessageLimit]
}
}
return message, err
}