-
Notifications
You must be signed in to change notification settings - Fork 1
fix: Initialize metrics on startup to fix restart gap; ProbeTx can be disabled #6
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
Open
KA-ROM
wants to merge
8
commits into
main
Choose a base branch
from
metric_init_with_0
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 3 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
6d550e8
Add FlashblocksStreamUp gauge metric
KA-ROM 97a944e
Specify stream_type label in FlashblocksReceiveFailureCount adds
KA-ROM 492c1a3
Add initMetrics function for fblocks streams
KA-ROM c9e7698
Update code comment
KA-ROM 4a64d0a
Add flag to enable/disable tx probes
KA-ROM d55ad37
Init block inspector metrics
KA-ROM 5b65735
Init flashblocks and flashtestations metrics if configured
KA-ROM 6c24486
Log tx probe enabled config
KA-ROM File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -100,11 +100,13 @@ func (fm *FlashblocksMonitor) Run(ctx context.Context) *<-chan *flashblockEvent | |
| processingContext, cancel := context.WithCancel(processingContext) | ||
| fm.stop = cancel | ||
|
|
||
| fm.initializeMetricsFlashblocksStreams(ctx) | ||
|
|
||
| for stream, url := range fm.cfg.privateStreams { | ||
| fm.readStream(ctx, stream, url, fm.flashblocksPrivate) | ||
| fm.readStream(ctx, stream, url, "private", fm.flashblocksPrivate) | ||
| } | ||
| for stream, url := range fm.cfg.publicStreams { | ||
| fm.readStream(ctx, stream, url, fm.flashblocksPublic) | ||
| fm.readStream(ctx, stream, url, "public", fm.flashblocksPublic) | ||
| } | ||
|
|
||
| flashblocks := make(chan *flashblockEvent, 2*fm.cfg.flashblocksPerBlock) | ||
|
|
@@ -135,7 +137,7 @@ func (fm *FlashblocksMonitor) Observe(_ context.Context, o otelapi.Observer) err | |
|
|
||
| func (fm *FlashblocksMonitor) readStream( | ||
| ctx context.Context, | ||
| streamID, streamUrl string, | ||
| streamID, streamUrl, streamType string, | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. praise: stream type is useful, thanks |
||
| flashblocks chan<- *flashblockEvent, | ||
| ) { | ||
| go func() { | ||
|
|
@@ -167,6 +169,13 @@ func (fm *FlashblocksMonitor) readStream( | |
| metrics.FlashblocksReceiveFailureCount.Add(ctx, 1, otelapi.WithAttributes( | ||
| attribute.KeyValue{Key: "kind", Value: attribute.StringValue("l2")}, | ||
| attribute.KeyValue{Key: "stream", Value: attribute.StringValue(streamID)}, | ||
| attribute.KeyValue{Key: "stream_type", Value: attribute.StringValue(streamType)}, | ||
| attribute.KeyValue{Key: "network_id", Value: attribute.Int64Value(fm.cfg.networkID)}, | ||
| )) | ||
| metrics.FlashblocksStreamUp.Record(ctx, 0, otelapi.WithAttributes( | ||
| attribute.KeyValue{Key: "kind", Value: attribute.StringValue("l2")}, | ||
| attribute.KeyValue{Key: "stream", Value: attribute.StringValue(streamID)}, | ||
| attribute.KeyValue{Key: "stream_type", Value: attribute.StringValue(streamType)}, | ||
| attribute.KeyValue{Key: "network_id", Value: attribute.Int64Value(fm.cfg.networkID)}, | ||
| )) | ||
| l.Warn("Failed to connect to flashblocks stream", | ||
|
|
@@ -184,6 +193,14 @@ func (fm *FlashblocksMonitor) readStream( | |
| backoff = wsBackoffMin | ||
| conn = _conn | ||
| doneReceiving = doneDialling | ||
|
|
||
| // connection successful - set stream_up to 1 | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. question: under which conditions does it go from in what way is it better/more reliable than, for example: ? |
||
| metrics.FlashblocksStreamUp.Record(ctx, 1, otelapi.WithAttributes( | ||
| attribute.KeyValue{Key: "kind", Value: attribute.StringValue("l2")}, | ||
| attribute.KeyValue{Key: "stream", Value: attribute.StringValue(streamID)}, | ||
| attribute.KeyValue{Key: "stream_type", Value: attribute.StringValue(streamType)}, | ||
| attribute.KeyValue{Key: "network_id", Value: attribute.Int64Value(fm.cfg.networkID)}, | ||
| )) | ||
| } | ||
|
|
||
| { // receive | ||
|
|
@@ -194,6 +211,13 @@ func (fm *FlashblocksMonitor) readStream( | |
| metrics.FlashblocksReceiveFailureCount.Add(ctx, 1, otelapi.WithAttributes( | ||
| attribute.KeyValue{Key: "kind", Value: attribute.StringValue("l2")}, | ||
| attribute.KeyValue{Key: "stream", Value: attribute.StringValue(streamID)}, | ||
| attribute.KeyValue{Key: "stream_type", Value: attribute.StringValue(streamType)}, | ||
| attribute.KeyValue{Key: "network_id", Value: attribute.Int64Value(fm.cfg.networkID)}, | ||
| )) | ||
| metrics.FlashblocksStreamUp.Record(ctx, 0, otelapi.WithAttributes( | ||
| attribute.KeyValue{Key: "kind", Value: attribute.StringValue("l2")}, | ||
| attribute.KeyValue{Key: "stream", Value: attribute.StringValue(streamID)}, | ||
| attribute.KeyValue{Key: "stream_type", Value: attribute.StringValue(streamType)}, | ||
| attribute.KeyValue{Key: "network_id", Value: attribute.Int64Value(fm.cfg.networkID)}, | ||
| )) | ||
| l.Warn("Failed to read message from flashblocks stream", | ||
|
|
@@ -215,6 +239,7 @@ func (fm *FlashblocksMonitor) readStream( | |
| metrics.FlashblocksReceiveFailureCount.Add(ctx, 1, otelapi.WithAttributes( | ||
| attribute.KeyValue{Key: "kind", Value: attribute.StringValue("l2")}, | ||
| attribute.KeyValue{Key: "stream", Value: attribute.StringValue(streamID)}, | ||
| attribute.KeyValue{Key: "stream_type", Value: attribute.StringValue(streamType)}, | ||
| attribute.KeyValue{Key: "network_id", Value: attribute.Int64Value(fm.cfg.networkID)}, | ||
| )) | ||
| l.Warn("Failed to decompress binary message from flashblocks stream, ignoring...", | ||
|
|
@@ -235,6 +260,7 @@ func (fm *FlashblocksMonitor) readStream( | |
| metrics.FlashblocksReceiveFailureCount.Add(ctx, 1, otelapi.WithAttributes( | ||
| attribute.KeyValue{Key: "kind", Value: attribute.StringValue("l2")}, | ||
| attribute.KeyValue{Key: "stream", Value: attribute.StringValue(streamID)}, | ||
| attribute.KeyValue{Key: "stream_type", Value: attribute.StringValue(streamType)}, | ||
| attribute.KeyValue{Key: "network_id", Value: attribute.Int64Value(fm.cfg.networkID)}, | ||
| )) | ||
| l.Error("Failed to parse flashblock", | ||
|
|
@@ -438,3 +464,56 @@ func (fm *FlashblocksMonitor) detectInconsistentFlashblocks(ctx context.Context, | |
| )) | ||
| } | ||
| } | ||
|
|
||
| func (fm *FlashblocksMonitor) initializeMetricsFlashblocksStreams(ctx context.Context) { | ||
| // initialize stream health metrics to 0 for all streams to ensure | ||
| // metrics always exist regardless of builder health | ||
|
KA-ROM marked this conversation as resolved.
Outdated
|
||
|
|
||
| // FlashblocksStreamUp gauge for private and public streams | ||
| for stream := range fm.cfg.privateStreams { | ||
| metrics.FlashblocksStreamUp.Record(ctx, 0, otelapi.WithAttributes( | ||
| attribute.KeyValue{Key: "kind", Value: attribute.StringValue("l2")}, | ||
| attribute.KeyValue{Key: "stream", Value: attribute.StringValue(stream)}, | ||
| attribute.KeyValue{Key: "stream_type", Value: attribute.StringValue("private")}, | ||
| attribute.KeyValue{Key: "network_id", Value: attribute.Int64Value(fm.cfg.networkID)}, | ||
| )) | ||
| } | ||
| for stream := range fm.cfg.publicStreams { | ||
| metrics.FlashblocksStreamUp.Record(ctx, 0, otelapi.WithAttributes( | ||
| attribute.KeyValue{Key: "kind", Value: attribute.StringValue("l2")}, | ||
| attribute.KeyValue{Key: "stream", Value: attribute.StringValue(stream)}, | ||
| attribute.KeyValue{Key: "stream_type", Value: attribute.StringValue("public")}, | ||
| attribute.KeyValue{Key: "network_id", Value: attribute.Int64Value(fm.cfg.networkID)}, | ||
| )) | ||
|
KA-ROM marked this conversation as resolved.
|
||
| } | ||
|
|
||
| // FlashblocksReceiveSuccess/FailureCount counters for private and public streams | ||
| for stream := range fm.cfg.privateStreams { | ||
| metrics.FlashblocksReceiveSuccessCount.Add(ctx, 0, otelapi.WithAttributes( | ||
| attribute.KeyValue{Key: "kind", Value: attribute.StringValue("l2")}, | ||
| attribute.KeyValue{Key: "stream", Value: attribute.StringValue(stream)}, | ||
| attribute.KeyValue{Key: "stream_type", Value: attribute.StringValue("private")}, | ||
| attribute.KeyValue{Key: "network_id", Value: attribute.Int64Value(fm.cfg.networkID)}, | ||
| )) | ||
| metrics.FlashblocksReceiveFailureCount.Add(ctx, 0, otelapi.WithAttributes( | ||
| attribute.KeyValue{Key: "kind", Value: attribute.StringValue("l2")}, | ||
| attribute.KeyValue{Key: "stream", Value: attribute.StringValue(stream)}, | ||
| attribute.KeyValue{Key: "stream_type", Value: attribute.StringValue("private")}, | ||
| attribute.KeyValue{Key: "network_id", Value: attribute.Int64Value(fm.cfg.networkID)}, | ||
| )) | ||
| } | ||
| for stream := range fm.cfg.publicStreams { | ||
| metrics.FlashblocksReceiveSuccessCount.Add(ctx, 0, otelapi.WithAttributes( | ||
| attribute.KeyValue{Key: "kind", Value: attribute.StringValue("l2")}, | ||
| attribute.KeyValue{Key: "stream", Value: attribute.StringValue(stream)}, | ||
| attribute.KeyValue{Key: "stream_type", Value: attribute.StringValue("public")}, | ||
| attribute.KeyValue{Key: "network_id", Value: attribute.Int64Value(fm.cfg.networkID)}, | ||
| )) | ||
| metrics.FlashblocksReceiveFailureCount.Add(ctx, 0, otelapi.WithAttributes( | ||
| attribute.KeyValue{Key: "kind", Value: attribute.StringValue("l2")}, | ||
| attribute.KeyValue{Key: "stream", Value: attribute.StringValue(stream)}, | ||
| attribute.KeyValue{Key: "stream_type", Value: attribute.StringValue("public")}, | ||
| attribute.KeyValue{Key: "network_id", Value: attribute.Int64Value(fm.cfg.networkID)}, | ||
| )) | ||
|
KA-ROM marked this conversation as resolved.
|
||
| } | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This code sets
fm.stopto cancelprocessingContext, butinitializeMetricsFlashblocksStreamsand the stream goroutines are started withctxinstead ofprocessingContext. Iffm.stop()is called,processingContextwill be canceled but the streams may keep running (and continue recording metrics) because they’re not observing the canceled context. PassprocessingContexttoinitializeMetricsFlashblocksStreams(...)and toreadStream(...)so shutdown behaves as intended.