Conversation
Summary of ChangesHello @AmrNJ, 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 significantly enhances the robustness and reliability of the Highlights
Changelog
Activity
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
|
Pull Request Functional Test Report for #5132 / 38d0934Virtual Devices
Hardware Devices
|
There was a problem hiding this comment.
Code Review
This pull request introduces several valuable improvements to the default_copp_test. Making the counter parsing prefix-agnostic and handling different value types for dropped packets significantly increases the test's robustness across different hardware. Removing the CPU utilization check during the traffic loop is a good change to prevent gNMI agent timeouts and improve test stability. I have one suggestion to enhance error logging in the new parseDroppedValue helper function to make test failures easier to diagnose.
| func parseDroppedValue(t *testing.T, counterVal any, keyName string) float64 { | ||
| counterMap, ok := counterVal.(map[string]any) | ||
| if !ok { | ||
| return logAndReturnErroredCount("getDroppedPktsForCounter: Error getting stats for counter: %s", counterName) | ||
| return -1 | ||
| } | ||
|
|
||
| dropped, ok := counterMap["dropped"] | ||
| if !ok { | ||
| return logAndReturnErroredCount("getDroppedPktsForCounter: Error getting stats for counter: %s", counterName) | ||
| return -1 | ||
| } | ||
| droppedStr, ok := dropped.(string) | ||
| if !ok { | ||
| return logAndReturnErroredCount("getDroppedPktsForCounter: Error converting dropped value to string for counter: %s", counterName) | ||
|
|
||
| var droppedStr string | ||
| switch v := dropped.(type) { | ||
| case string: | ||
| droppedStr = v | ||
| case float64: | ||
| return v | ||
| default: | ||
| return -1 | ||
| } | ||
|
|
||
| packetsDropped, err := strconv.ParseFloat(droppedStr, 64) | ||
| if err != nil { | ||
| return logAndReturnErroredCount("getDroppedPktsForCounter: Error getting packets dropped for counter: %s", counterName) | ||
| return -1 | ||
| } | ||
| return packetsDropped | ||
| } |
There was a problem hiding this comment.
The helper function parseDroppedValue is a great addition for handling different data types. However, it currently returns -1 on parsing errors without logging any details. This can make debugging test failures difficult as the root cause of the parsing failure (e.g., unexpected data type, missing 'dropped' key) would not be reported. To improve diagnostics, please consider adding error logging using t.Errorf in the failure paths before returning.
func parseDroppedValue(t *testing.T, counterVal any, keyName string) float64 {
counterMap, ok := counterVal.(map[string]any)
if !ok {
t.Errorf("parseDroppedValue: value for key %q is not a map[string]any, but %T", keyName, counterVal)
return -1
}
dropped, ok := counterMap["dropped"]
if !ok {
t.Errorf("parseDroppedValue: 'dropped' field not found in map for key %q", keyName)
return -1
}
var droppedStr string
switch v := dropped.(type) {
case string:
droppedStr = v
case float64:
return v
default:
t.Errorf("parseDroppedValue: 'dropped' field for key %q has unexpected type %T", keyName, v)
return -1
}
packetsDropped, err := strconv.ParseFloat(droppedStr, 64)
if err != nil {
t.Errorf("parseDroppedValue: Error converting dropped value %q to float for key %q: %v", droppedStr, keyName, err)
return -1
}
return packetsDropped
}* Update default_copp_test.go * Update default_copp_test.go
* Update default_copp_test.go * Update default_copp_test.go
Made the following updates to the code