-
Notifications
You must be signed in to change notification settings - Fork 97
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Observability - instrument QBFT component, ctx propagation
- Loading branch information
1 parent
da9df9b
commit 1c6fb59
Showing
20 changed files
with
139 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,75 +1,56 @@ | ||
package instance | ||
|
||
import ( | ||
"context" | ||
"math" | ||
"time" | ||
|
||
"github.com/prometheus/client_golang/prometheus" | ||
"github.com/prometheus/client_golang/prometheus/promauto" | ||
specqbft "github.com/ssvlabs/ssv-spec/qbft" | ||
"go.uber.org/zap" | ||
"go.opentelemetry.io/otel/metric" | ||
) | ||
|
||
var ( | ||
metricsStageDuration = promauto.NewHistogramVec(prometheus.HistogramOpts{ | ||
Name: "ssv_validator_instance_stage_duration_seconds", | ||
Help: "Instance stage duration (seconds)", | ||
Buckets: []float64{0.02, 0.05, 0.1, 0.2, 0.5, 1, 1.5, 2, 5}, | ||
}, []string{"stage"}) | ||
metricsRound = promauto.NewGaugeVec(prometheus.GaugeOpts{ | ||
Name: "ssv_qbft_instance_round", | ||
Help: "QBFT instance round", | ||
}, []string{"roleType"}) | ||
) | ||
|
||
func init() { | ||
allMetrics := []prometheus.Collector{ | ||
metricsStageDuration, | ||
metricsRound, | ||
} | ||
logger := zap.L() | ||
for _, c := range allMetrics { | ||
if err := prometheus.Register(c); err != nil { | ||
logger.Debug("could not register prometheus collector") | ||
} | ||
} | ||
} | ||
|
||
type metrics struct { | ||
StageStart time.Time | ||
proposalDuration prometheus.Observer | ||
prepareDuration prometheus.Observer | ||
commitDuration prometheus.Observer | ||
round prometheus.Gauge | ||
stageStart time.Time | ||
role string | ||
} | ||
|
||
func newMetrics(role string) *metrics { | ||
return &metrics{ | ||
proposalDuration: metricsStageDuration.WithLabelValues("proposal"), | ||
prepareDuration: metricsStageDuration.WithLabelValues("prepare"), | ||
commitDuration: metricsStageDuration.WithLabelValues("commit"), | ||
round: metricsRound.WithLabelValues(role), | ||
role: role, | ||
} | ||
} | ||
|
||
func (m *metrics) StartStage() { | ||
m.StageStart = time.Now() | ||
m.stageStart = time.Now() | ||
} | ||
|
||
func (m *metrics) EndStageProposal() { | ||
m.proposalDuration.Observe(time.Since(m.StageStart).Seconds()) | ||
m.StageStart = time.Now() | ||
func (m *metrics) EndStageProposal(ctx context.Context) { | ||
validatorStageDurationHistogram.Record( | ||
ctx, | ||
time.Since(m.stageStart).Seconds(), | ||
metric.WithAttributes(stageAttribute(proposalStage))) | ||
m.stageStart = time.Now() | ||
} | ||
|
||
func (m *metrics) EndStagePrepare() { | ||
m.prepareDuration.Observe(time.Since(m.StageStart).Seconds()) | ||
m.StageStart = time.Now() | ||
func (m *metrics) EndStagePrepare(ctx context.Context) { | ||
validatorStageDurationHistogram.Record( | ||
ctx, | ||
time.Since(m.stageStart).Seconds(), | ||
metric.WithAttributes(stageAttribute(prepareStage))) | ||
m.stageStart = time.Now() | ||
} | ||
|
||
func (m *metrics) EndStageCommit() { | ||
m.commitDuration.Observe(time.Since(m.StageStart).Seconds()) | ||
m.StageStart = time.Now() | ||
func (m *metrics) EndStageCommit(ctx context.Context) { | ||
validatorStageDurationHistogram.Record( | ||
ctx, | ||
time.Since(m.stageStart).Seconds(), | ||
metric.WithAttributes(stageAttribute(commitStage))) | ||
m.stageStart = time.Now() | ||
} | ||
|
||
func (m *metrics) SetRound(round specqbft.Round) { | ||
m.round.Set(float64(round)) | ||
func (m *metrics) SetRound(ctx context.Context, round specqbft.Round) { | ||
convertedRound := uint64(round) | ||
if convertedRound <= math.MaxInt64 { | ||
roundGauge.Record(ctx, int64(convertedRound), metric.WithAttributes(roleAttribute(m.role))) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package instance | ||
|
||
import ( | ||
"fmt" | ||
|
||
"go.opentelemetry.io/otel" | ||
"go.opentelemetry.io/otel/attribute" | ||
"go.opentelemetry.io/otel/metric" | ||
|
||
"github.com/ssvlabs/ssv/observability" | ||
) | ||
|
||
const ( | ||
observabilityName = "github.com/ssvlabs/ssv/protocol/v2/qbft" | ||
observabilityNamespace = "ssv.validator" | ||
) | ||
|
||
type stage string | ||
|
||
const ( | ||
proposalStage stage = "proposal" | ||
prepareStage stage = "prepare" | ||
commitStage stage = "commit" | ||
) | ||
|
||
var ( | ||
meter = otel.Meter(observabilityName) | ||
|
||
validatorStageDurationHistogram = observability.NewMetric( | ||
meter.Float64Histogram( | ||
metricName("stage.duration"), | ||
metric.WithUnit("s"), | ||
metric.WithDescription("validator stage(proposal, prepare, commit) duration"), | ||
metric.WithExplicitBucketBoundaries(observability.SecondsHistogramBuckets...))) | ||
|
||
roundGauge = observability.NewMetric( | ||
meter.Int64Gauge( | ||
metricName("round"), | ||
metric.WithUnit("{round}"), | ||
metric.WithDescription("QBFT instance round"))) | ||
) | ||
|
||
func metricName(name string) string { | ||
return fmt.Sprintf("%s.%s", observabilityNamespace, name) | ||
} | ||
|
||
func stageAttribute(stage stage) attribute.KeyValue { | ||
return attribute.String("ssv.validator.stage", string(stage)) | ||
} | ||
|
||
func roleAttribute(role string) attribute.KeyValue { | ||
return attribute.String("ssv.runner.role", role) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.