-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Ensure tcp connection value is provided for all states, even when count is 0 #1329
Conversation
…work scraper tests
Codecov Report
@@ Coverage Diff @@
## master #1329 +/- ##
==========================================
+ Coverage 89.60% 89.64% +0.04%
==========================================
Files 215 215
Lines 15185 15197 +12
==========================================
+ Hits 13606 13624 +18
+ Misses 1151 1148 -3
+ Partials 428 425 -3
Continue to review full report at Codecov.
|
func getConnectionStatusCounts(connections []net.ConnectionStat) map[string]int64 { | ||
connectionStatuses := make(map[string]int64, len(connections)) | ||
func getTCPConnectionStatusCounts(connections []net.ConnectionStat) map[string]int64 { | ||
var tcpStatuses = map[string]int64{ |
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.
Why not an array and a enum for status? Seems better for me
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.
I'm not totally sure what you mean by this.
Do you mean enum as in?
type tcpStatus string
const (
closeWait tcpStatus = "CLOSE_WAIT"
closed tcpStatus = "CLOSED"
...
)
Also I think a map should outperform an array here since we need to iterate through potentially 100s of connections to record the counts. Using an array would require O(n^2)?
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.
I mean an enum as in:
type tcpStatus int
const (
closeWait tcpStatus = iota
closed tcpStatus
...
)
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.
You may need a switch for the status. Not 100% sure so your call
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.
Oh okay yea - ofc 🤦♂️
We would need a switch to convert strings to indexes, so I suspect performance would be pretty similar either way. Annoyingly gopsutil actually converts these from ints to strings before returning the values 😞
If you don't feel too strongly about this I will probably leave it as is. This has the arguably useful propery that if we ever receive an unexpected status value, it will get added to the map.
…work scraper tests (open-telemetry#1329)
Co-authored-by: Tyler Yahn <[email protected]>
Ensure tcp connection value is provided for all states, even when count is 0. Also update tests & improve test coverage.