-
Notifications
You must be signed in to change notification settings - Fork 0
fix: Initialize peer metrics on startup to fix restart gap #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -19,10 +19,11 @@ import ( | |||||||||||||||||||||||||||||||||||||
| "github.com/flashbots/bmonitor/metrics" | ||||||||||||||||||||||||||||||||||||||
| "github.com/flashbots/bmonitor/utils" | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| "github.com/ethereum/go-ethereum/ethclient" | ||||||||||||||||||||||||||||||||||||||
| "github.com/prometheus/client_golang/prometheus/promhttp" | ||||||||||||||||||||||||||||||||||||||
| "go.opentelemetry.io/otel/attribute" | ||||||||||||||||||||||||||||||||||||||
| otelapi "go.opentelemetry.io/otel/metric" | ||||||||||||||||||||||||||||||||||||||
| "go.uber.org/zap" | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| "github.com/ethereum/go-ethereum/ethclient" | ||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| type Server struct { | ||||||||||||||||||||||||||||||||||||||
|
|
@@ -114,6 +115,8 @@ func (s *Server) Run() error { | |||||||||||||||||||||||||||||||||||||
| return err | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| s.initializePeersMetrics(ctx) | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| go func() { // run the server | ||||||||||||||||||||||||||||||||||||||
| l.Info("Builder monitor server is going up...", | ||||||||||||||||||||||||||||||||||||||
| zap.String("server_listen_address", s.cfg.Server.ListenAddress), | ||||||||||||||||||||||||||||||||||||||
|
|
@@ -182,3 +185,21 @@ func (s *Server) Run() error { | |||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| return utils.FlattenErrors(errs) | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| func (s *Server) initializePeersMetrics(ctx context.Context) { | ||||||||||||||||||||||||||||||||||||||
| for builder := range s.builders { | ||||||||||||||||||||||||||||||||||||||
| for _, typ := range []string{"loopback", "internal", "external"} { | ||||||||||||||||||||||||||||||||||||||
| metrics.PeersCount.Record(ctx, 0, otelapi.WithAttributes( | ||||||||||||||||||||||||||||||||||||||
| attribute.KeyValue{Key: "builder", Value: attribute.StringValue(builder)}, | ||||||||||||||||||||||||||||||||||||||
| attribute.KeyValue{Key: "type", Value: attribute.StringValue(typ)}, | ||||||||||||||||||||||||||||||||||||||
| )) | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+191
to
+196
|
||||||||||||||||||||||||||||||||||||||
| for _, label := range s.peers { | ||||||||||||||||||||||||||||||||||||||
| metrics.PeersCount.Record(ctx, 0, otelapi.WithAttributes( | ||||||||||||||||||||||||||||||||||||||
| attribute.KeyValue{Key: "builder", Value: attribute.StringValue(builder)}, | ||||||||||||||||||||||||||||||||||||||
| attribute.KeyValue{Key: "type", Value: attribute.StringValue("labelled")}, | ||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||
| attribute.KeyValue{Key: "label", Value: attribute.StringValue(label)}, | ||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+193
to
+201
|
||||||||||||||||||||||||||||||||||||||
| attribute.KeyValue{Key: "builder", Value: attribute.StringValue(builder)}, | |
| attribute.KeyValue{Key: "type", Value: attribute.StringValue(typ)}, | |
| )) | |
| } | |
| for _, label := range s.peers { | |
| metrics.PeersCount.Record(ctx, 0, otelapi.WithAttributes( | |
| attribute.KeyValue{Key: "builder", Value: attribute.StringValue(builder)}, | |
| attribute.KeyValue{Key: "type", Value: attribute.StringValue("labelled")}, | |
| attribute.KeyValue{Key: "label", Value: attribute.StringValue(label)}, | |
| attribute.String("builder", builder), | |
| attribute.String("type", typ), | |
| )) | |
| } | |
| for _, label := range s.peers { | |
| metrics.PeersCount.Record(ctx, 0, otelapi.WithAttributes( | |
| attribute.String("builder", builder), | |
| attribute.String("type", "labelled"), | |
| attribute.String("label", label), |
Uh oh!
There was an error while loading. Please reload this page.