-
Notifications
You must be signed in to change notification settings - Fork 0
chore: ensure submission duration always has a reading within the 60 second window #16
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
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 |
|---|---|---|
|
|
@@ -2,6 +2,7 @@ package metrics | |
|
|
||
| import ( | ||
| "testing" | ||
| "time" | ||
|
|
||
| "github.com/prometheus/client_golang/prometheus" | ||
| "github.com/stretchr/testify/require" | ||
|
|
@@ -535,6 +536,33 @@ func TestMetrics_ComplexScenario(t *testing.T) { | |
| } | ||
| } | ||
|
|
||
| func TestMetrics_RecordSubmissionDuration(t *testing.T) { | ||
| reg := prometheus.NewRegistry() | ||
| m := NewWithRegistry("test", reg) | ||
|
|
||
| // record submission durations | ||
| m.RecordSubmissionDuration("chain1", "header", 5*time.Second) | ||
| // overwrite submission duration | ||
| m.RecordSubmissionDuration("chain1", "header", 6*time.Second) | ||
| m.RecordSubmissionDuration("chain1", "data", 10*time.Second) | ||
| m.RecordSubmissionDuration("chain2", "header", 3*time.Second) | ||
|
|
||
| // verify stored in memory | ||
| require.Equal(t, 6*time.Second, m.lastSubmissionDurations["chain1:header"], "last submission duration should be present") | ||
| require.Equal(t, 10*time.Second, m.lastSubmissionDurations["chain1:data"]) | ||
| require.Equal(t, 3*time.Second, m.lastSubmissionDurations["chain2:header"]) | ||
| } | ||
|
|
||
| func TestMetrics_RefreshSubmissionDuration_Empty(t *testing.T) { | ||
| reg := prometheus.NewRegistry() | ||
| m := NewWithRegistry("test", reg) | ||
|
|
||
| // call refresh without any recorded values - should not panic | ||
| require.NotPanics(t, func() { | ||
| m.RefreshSubmissionDuration() | ||
| }) | ||
| } | ||
|
Comment on lines
+556
to
+564
Contributor
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. This test correctly ensures that
This might require a helper function to inspect summary metrics, as the existing |
||
|
|
||
| // helper types for table tests | ||
| type blockToRecord struct { | ||
| chain string | ||
|
|
||
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.
The current method of parsing the metric key using
strings.Split(key, ":")is not robust. If achainIDcontains a colon, the key will be split into more than two parts, causing thelen(parts) == 2check to fail. This would result in the metric for that series not being refreshed, without any error or warning. A more robust approach is to split the key at the last colon, which correctly separates thechainIDfrom thesubmissionType, assuming thesubmissionTypeitself does not contain a colon.