[network] Work around ss -atun bug not differentiating tcp and udp#296
Conversation
olivielpeau
left a comment
There was a problem hiding this comment.
Had a comment on how we could simplify the logic, but overall I think calling ss 4 times is the correct approach.
Also, the CI is failing, on a flake8 thing. Let's fix it and also update the mock tests/fixtures to reflect what ss actually returns now.
| output, _, _ = get_subprocess_output(["ss", "-n", "-u", "-t", "-a", "-{0}".format(ip_version)], self.log) | ||
| lines = output.splitlines() | ||
| output_tcp, _, _ = get_subprocess_output(["ss", "-n", "-t", "-a", "-{0}".format(ip_version)], self.log) | ||
| output_udp, _, _ = get_subprocess_output(["ss", "-n", "-u", "-a", "-{0}".format(ip_version)], self.log) |
There was a problem hiding this comment.
I think this could be simplified by using a second for loop iterating on ['tcp', 'udp'] (or having one loop iterating over all 4 combinations of protocols/ip versions) and calling get_subprocess_output and _parse_linux_cx_state inside the loop. This should allow removing your specific code below that adds a header to each line and modifies the output of the command.
Feel free to change the signature and internal behavior of _parse_linux_cx_state, or remove it altogether if it doesn't make sense to use it anymore, it's only used for these ss and netstat calls.
olivielpeau
left a comment
There was a problem hiding this comment.
Looks 👌 !
Let's merge this and double-check that the these metrics are flowing correctly when this is shipped to an actual environment.
* Extract datadog tags into a template var * Support strings and hashes * Update docs for tag attribute * Add test coverage for tags (string, hash, empty hash value) Closes #186
No description provided.