-
Notifications
You must be signed in to change notification settings - Fork 1
feat: added GetNrQueued API #11
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
|
FYI @weiso131 |
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.
Pull request overview
This PR adds a new GetNrQueued() API method to the Sched interface that returns the number of tasks currently queued and waiting to be dequeued. This method appears to support metrics reporting, as evidenced by the existing NrQueued field in the BssData struct used for metrics.
Changes:
- Added
GetNrQueued() uint64method to theSchedinterface in the registry - Implemented the method in three test mock schedulers (simple_test.go, gthulhu_test.go, factory_integration_test.go)
- Minor formatting fix in factory_integration_test.go (closing brace placement)
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
| plugin/internal/registry/registry.go | Added GetNrQueued() method to the Sched interface |
| plugin/simple/simple_test.go | Implemented GetNrQueued() in MockScheduler test mock |
| plugin/gthulhu/gthulhu_test.go | Implemented GetNrQueued() in MockScheduler test mock |
| tests/factory_integration_test.go | Implemented GetNrQueued() in testSched mock and fixed formatting |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| return nil, cpu | ||
| } | ||
|
|
||
| func (m *MockScheduler) GetNrQueued() uint64 { |
Copilot
AI
Jan 30, 2026
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 GetNrQueued implementation has a potential integer underflow issue. If queueIndex somehow becomes greater than len(m.taskQueue), the subtraction would produce a negative value which, when cast to uint64, would wrap around to a very large positive number. Consider adding a safety check: if m.queueIndex > len(m.taskQueue) { return 0 } before the calculation, or use: if m.queueIndex >= len(m.taskQueue) { return 0 } return uint64(len(m.taskQueue) - m.queueIndex)
| func (m *MockScheduler) GetNrQueued() uint64 { | |
| func (m *MockScheduler) GetNrQueued() uint64 { | |
| if m.queueIndex >= len(m.taskQueue) { | |
| return 0 | |
| } |
| return nil, 0 | ||
| } | ||
|
|
||
| func (s *testSched) GetNrQueued() uint64 { |
Copilot
AI
Jan 30, 2026
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 GetNrQueued implementation has a potential integer underflow issue. If index somehow becomes greater than len(s.tasks), the subtraction would produce a negative value which, when cast to uint64, would wrap around to a very large positive number. Consider adding a safety check: if s.index > len(s.tasks) { return 0 } before the calculation, or use: if s.index >= len(s.tasks) { return 0 } return uint64(len(s.tasks) - s.index)
| func (s *testSched) GetNrQueued() uint64 { | |
| func (s *testSched) GetNrQueued() uint64 { | |
| if s.index >= len(s.tasks) { | |
| return 0 | |
| } |
| func (m *MockScheduler) GetNrQueued() uint64 { | ||
| return uint64(len(m.taskQueue) - m.queueIndex) | ||
| } |
Copilot
AI
Jan 30, 2026
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 newly added GetNrQueued method is not called or tested anywhere in the codebase. Consider adding unit tests that verify the method returns correct values in various scenarios (e.g., empty queue, partially dequeued queue, fully dequeued queue) to ensure the implementation works as expected.
| @@ -12,6 +12,7 @@ import ( | |||
| type Sched interface { | |||
| DequeueTask(task *models.QueuedTask) | |||
| DefaultSelectCPU(t *models.QueuedTask) (error, int32) | |||
Copilot
AI
Jan 30, 2026
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 new GetNrQueued method lacks documentation. Consider adding a comment explaining its purpose and expected behavior, similar to how other interface methods are documented. For example: "GetNrQueued returns the number of tasks currently queued and waiting to be dequeued."
| DefaultSelectCPU(t *models.QueuedTask) (error, int32) | |
| DefaultSelectCPU(t *models.QueuedTask) (error, int32) | |
| // GetNrQueued returns the number of tasks currently queued and waiting to be dequeued. |
| return nil, cpu | ||
| } | ||
|
|
||
| func (m *MockScheduler) GetNrQueued() uint64 { |
Copilot
AI
Jan 30, 2026
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 GetNrQueued implementation has a potential integer underflow issue. If queueIndex somehow becomes greater than len(m.taskQueue), the subtraction would produce a negative value which, when cast to uint64, would wrap around to a very large positive number. Consider adding a safety check: if m.queueIndex > len(m.taskQueue) { return 0 } before the calculation, or use: if m.queueIndex >= len(m.taskQueue) { return 0 } return uint64(len(m.taskQueue) - m.queueIndex)
| func (m *MockScheduler) GetNrQueued() uint64 { | |
| func (m *MockScheduler) GetNrQueued() uint64 { | |
| if m.queueIndex >= len(m.taskQueue) { | |
| return 0 | |
| } |
No description provided.