-
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
Conversation
Summary of ChangesHello @chatton, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request enhances the metrics system by implementing a periodic refresh mechanism for submission duration metrics. The change ensures that monitoring dashboards consistently display up-to-date submission duration data, preventing gaps or staleness in graphs when actual submissions are sparse, thereby improving the reliability and readability of performance insights. Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
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.
Code Review
This pull request introduces a mechanism to periodically refresh the submission_duration metric, ensuring its presence in scrapes for smoother graphing. This is achieved by adding a ticker in the verifier to call a new RefreshSubmissionDuration function. While the overall approach is sound, I've identified a high-severity bug in the key parsing logic for refreshing metrics, which could lead to silent failures if a chainID contains a colon. I've provided a robust fix for this. Additionally, I've suggested improving test coverage for the new refresh functionality to include a positive test case.
| func (m *Metrics) RefreshSubmissionDuration() { | ||
| m.mu.Lock() | ||
| defer m.mu.Unlock() | ||
|
|
||
| for key, duration := range m.lastSubmissionDurations { | ||
| // assuming format "chainID:namespace" | ||
| parts := strings.Split(key, ":") | ||
| if len(parts) == 2 { | ||
| m.SubmissionDuration.WithLabelValues(parts[0], parts[1]).Observe(duration.Seconds()) | ||
| } | ||
| } | ||
| } |
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 a chainID contains a colon, the key will be split into more than two parts, causing the len(parts) == 2 check 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 the chainID from the submissionType, assuming the submissionType itself does not contain a colon.
| func (m *Metrics) RefreshSubmissionDuration() { | |
| m.mu.Lock() | |
| defer m.mu.Unlock() | |
| for key, duration := range m.lastSubmissionDurations { | |
| // assuming format "chainID:namespace" | |
| parts := strings.Split(key, ":") | |
| if len(parts) == 2 { | |
| m.SubmissionDuration.WithLabelValues(parts[0], parts[1]).Observe(duration.Seconds()) | |
| } | |
| } | |
| } | |
| func (m *Metrics) RefreshSubmissionDuration() { | |
| m.mu.Lock() | |
| defer m.mu.Unlock() | |
| for key, duration := range m.lastSubmissionDurations { | |
| lastColonIdx := strings.LastIndex(key, ":") | |
| // Ensure the key is in the expected "chainID:submissionType" format and both parts are non-empty. | |
| if lastColonIdx > 0 && lastColonIdx < len(key)-1 { | |
| chainID := key[:lastColonIdx] | |
| submissionType := key[lastColonIdx+1:] | |
| m.SubmissionDuration.WithLabelValues(chainID, submissionType).Observe(duration.Seconds()) | |
| } | |
| } | |
| } |
| 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() | ||
| }) | ||
| } |
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 test correctly ensures that RefreshSubmissionDuration doesn't panic when there are no durations to refresh. However, there is no test case for the "happy path" where it successfully refreshes a metric. It would be beneficial to add a test that:
- Records a submission duration.
- Calls
RefreshSubmissionDuration. - Verifies that the Prometheus summary metric has been updated accordingly.
This might require a helper function to inspect summary metrics, as the existing getMetricValue is designed for gauges. You could, for example, gather metrics and check the _count or _sum for the summary.
Overview
To ensure a smoother graph, we can ensure that there is always a metric for submission duration in the 60 second window.