-
Notifications
You must be signed in to change notification settings - Fork 200
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Implement a dynamic temporary cache that tracks network interfac…
…es that do not support the ethtool operation. (#620) # Description 1.Implement a dynamic temporary cache that tracks network interfaces that do not support the ethtool operation. 2.Add new test cases for the new changings ## Related Issue If this pull request is related to any issue, please mention it here. Additionally, make sure that the issue is assigned to you before submitting this pull request. ## Checklist - [ ] I have read the [contributing documentation](https://retina.sh/docs/contributing). - [ ] I signed and signed-off the commits (`git commit -S -s ...`). See [this documentation](https://docs.github.com/en/authentication/managing-commit-signature-verification/about-commit-signature-verification) on signing commits. - [ ] I have correctly attributed the author(s) of the code. - [ ] I have tested the changes locally. - [ ] I have followed the project's style guidelines. - [ ] I have updated the documentation, if necessary. - [ ] I have added tests, if applicable. ## Screenshots (if applicable) or Testing Completed Please add any relevant screenshots or GIFs to showcase the changes made. ## Additional Notes Add any additional notes or context about the pull request here. --- Please refer to the [CONTRIBUTING.md](../CONTRIBUTING.md) file for more information on how to contribute to this project.
- Loading branch information
1 parent
6443991
commit 576c10e
Showing
6 changed files
with
149 additions
and
14 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package linuxutil | ||
|
||
import ( | ||
"strings" | ||
|
||
"github.com/pkg/errors" | ||
|
||
lru "github.com/hashicorp/golang-lru/v2" | ||
|
||
"github.com/microsoft/retina/pkg/log" | ||
"go.uber.org/zap" | ||
) | ||
|
||
type CachedEthtool struct { | ||
EthtoolInterface | ||
unsupported *lru.Cache[string, struct{}] | ||
l *log.ZapLogger | ||
} | ||
|
||
func NewCachedEthtool(ethHandle EthtoolInterface, opts *EthtoolOpts) *CachedEthtool { | ||
cache, err := lru.New[string, struct{}](int(opts.limit)) | ||
if err != nil { | ||
log.Logger().Error("failed to create LRU cache: ", zap.Error(err)) | ||
} | ||
|
||
return &CachedEthtool{ | ||
EthtoolInterface: ethHandle, | ||
unsupported: cache, | ||
l: log.Logger().Named(string("EthtoolReader")), | ||
} | ||
} | ||
|
||
var errskip = errors.New("skip interface") | ||
|
||
func (ce *CachedEthtool) Stats(intf string) (map[string]uint64, error) { | ||
// Skip unsupported interfaces | ||
if _, ok := ce.unsupported.Get(intf); ok { | ||
return nil, errskip | ||
} | ||
|
||
ifaceStats, err := ce.EthtoolInterface.Stats(intf) | ||
if err != nil { | ||
if strings.Contains(err.Error(), "operation not supported") { | ||
ce.unsupported.Add(intf, struct{}{}) | ||
return nil, errors.Wrap(err, "interface not supported while retrieving stats") | ||
} | ||
return nil, errors.Wrap(err, "failed to retrieve interface stats") | ||
} | ||
return ifaceStats, nil | ||
} |
This file contains 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 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 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 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 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