-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathmetrics.go
114 lines (106 loc) · 5.31 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
package gpbft
import (
"errors"
"github.com/filecoin-project/go-f3/internal/measurements"
"go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/attribute"
"go.opentelemetry.io/otel/metric"
)
const (
attrKeyPhase = "phase"
attrKeyErr = "err"
)
var (
meter = otel.Meter("f3/gpbft")
attrInitialPhase = attribute.String(attrKeyPhase, INITIAL_PHASE.String())
attrQualityPhase = attribute.String(attrKeyPhase, QUALITY_PHASE.String())
attrConvergePhase = attribute.String(attrKeyPhase, CONVERGE_PHASE.String())
attrPreparePhase = attribute.String(attrKeyPhase, PREPARE_PHASE.String())
attrCommitPhase = attribute.String(attrKeyPhase, COMMIT_PHASE.String())
attrDecidePhase = attribute.String(attrKeyPhase, DECIDE_PHASE.String())
attrTerminatedPhase = attribute.String(attrKeyPhase, TERMINATED_PHASE.String())
attrPhase = map[Phase]attribute.KeyValue{
INITIAL_PHASE: attrInitialPhase,
QUALITY_PHASE: attrQualityPhase,
CONVERGE_PHASE: attrConvergePhase,
PREPARE_PHASE: attrPreparePhase,
COMMIT_PHASE: attrCommitPhase,
DECIDE_PHASE: attrDecidePhase,
TERMINATED_PHASE: attrTerminatedPhase,
}
attrSkipToRound = attribute.String("to", "round")
attrSkipToDecide = attribute.String("to", "decide")
attrCacheHit = attribute.String("cache", "hit")
attrCacheMiss = attribute.String("cache", "miss")
attrCacheKindMessage = attribute.String("kind", "message")
attrCacheKindJustification = attribute.String("kind", "justification")
attrKeyRound = attribute.Key("round")
metrics = struct {
phaseCounter metric.Int64Counter
roundHistogram metric.Int64Histogram
broadcastCounter metric.Int64Counter
reBroadcastCounter metric.Int64Counter
errorCounter metric.Int64Counter
currentInstance metric.Int64Gauge
currentRound metric.Int64Gauge
currentPhase metric.Int64Gauge
proposalLength metric.Int64Gauge
skipCounter metric.Int64Counter
validationCache metric.Int64Counter
quorumParticipation metric.Float64Gauge
totalPower metric.Float64Gauge
}{
phaseCounter: measurements.Must(meter.Int64Counter("f3_gpbft_phase_counter", metric.WithDescription("Number of times phases change"))),
roundHistogram: measurements.Must(meter.Int64Histogram("f3_gpbft_round_histogram",
metric.WithDescription("Histogram of rounds per instance"),
metric.WithExplicitBucketBoundaries(0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 20.0, 50.0, 100.0, 1000.0),
)),
broadcastCounter: measurements.Must(meter.Int64Counter("f3_gpbft_broadcast_counter", metric.WithDescription("Number of broadcasted messages"))),
reBroadcastCounter: measurements.Must(meter.Int64Counter("f3_gpbft_rebroadcast_counter", metric.WithDescription("Number of rebroadcasted messages"))),
errorCounter: measurements.Must(meter.Int64Counter("f3_gpbft_error_counter", metric.WithDescription("Number of errors"))),
currentInstance: measurements.Must(meter.Int64Gauge("f3_gpbft_current_instance", metric.WithDescription("The ID of the current instance"))),
currentRound: measurements.Must(meter.Int64Gauge("f3_gpbft_current_round", metric.WithDescription("The current round number"))),
currentPhase: measurements.Must(meter.Int64Gauge("f3_gpbft_current_phase",
metric.WithDescription("The current phase represented as numeric value of gpbft.Phase: "+
"0=INITIAL, 1=QUALITY, 2=CONVERGE, 3=PREPARE, 4=COMMIT, 5=DECIDE, and 6=TERMINATED"))),
proposalLength: measurements.Must(meter.Int64Gauge("f3_gpbft_current_proposal_len",
metric.WithDescription("Length of active proposal"))),
skipCounter: measurements.Must(meter.Int64Counter("f3_gpbft_skip_counter", metric.WithDescription("The number of times GPBFT skip either round or phase"))),
validationCache: measurements.Must(meter.Int64Counter("f3_gpbft_validation_cache", metric.WithDescription("The number of times GPBFT validation cache resulted in hit or miss."))),
quorumParticipation: measurements.Must(meter.Float64Gauge("f3_gpbft_participation",
metric.WithDescription("The current ratio of participation at a given round and phase (converge not tracked)."))),
totalPower: measurements.Must(meter.Float64Gauge("f3_gpbft_total_power",
metric.WithDescription("The size of the power table as observed by gpbft."))),
}
)
func metricAttributeFromError(err error) attribute.KeyValue {
var v string
switch {
case errors.Is(err, ErrValidationTooOld):
v = "invalid_too_old"
case errors.Is(err, ErrValidationNoCommittee):
v = "invalid_no_committee"
case errors.Is(err, ErrValidationInvalid):
v = "invalid_msg"
case errors.Is(err, ErrValidationWrongBase):
v = "invalid_wrong_base"
case errors.Is(err, ErrValidationWrongSupplement):
v = "invalid_wrong_supp"
case errors.Is(err, ErrValidationNotRelevant):
v = "invalid_not_relevant"
case errors.As(err, &ValidationError{}):
v = "type_invalid"
case errors.Is(err, ErrReceivedWrongInstance):
v = "wrong_instance"
case errors.Is(err, ErrReceivedAfterTermination):
v = "after_termination"
case errors.Is(err, ErrReceivedInternalError):
v = "internal"
case errors.Is(err, &PanicError{}):
// Any unknown error that ended up getting wrapped with PanicError.
v = "recovered_panic"
default:
v = "unknown"
}
return attribute.KeyValue{Key: attrKeyErr, Value: attribute.StringValue(v)}
}