-
Notifications
You must be signed in to change notification settings - Fork 712
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
probe: conntrack: fix output parsing #2118
probe: conntrack: fix output parsing #2118
Conversation
Thanks @alban . Regexps tend to perform pretty badly, let's confirm with a test but I suspect a simple "key=value" parser would be a better option. |
tl;dr:
So regexp is significantly slower. I will try with a simple "key=value" parser. Note that there is several keys with the same string, so we have to read them in order. Long version: pprof couldn't work for me on go 1.7, so I had to revert to go 1.6 with:
Then, the perf check is done with:
The test I did was:
This was not a good idea to pick an external $IP for the test because that server latency changed when I tried the xml version. DoS mitigation? I'll use an internal server for the next test. |
8b82a9d
to
a57360a
Compare
Patch updated with a manual parser instead of regexp. It seems to work at a first glance but I still need to check the performances. |
I checked the performance again, but this time:
Then I compare the perfs from pprof:
I am not sure why my code is faster than the scanf, but that seems good. |
Awesome, great job! |
case key == "id": | ||
f.Independent.ID, err = strconv.ParseInt(value, 10, 64) | ||
} | ||
} |
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
a57360a
to
e640d2b
Compare
Updated. I moved the 60 lines in the helper function, and updated the description of the PR. It worked for me on Fedora (with the SELinux field). I tried with and without "net.netfilter.nf_conntrack_acct". PTAL. |
@@ -250,6 +252,53 @@ func removeInplace(s, sep []byte) []byte { | |||
return s[:len(s)-len(sep)] | |||
} | |||
|
|||
func decodeTwoTuples(line []byte, f *flow) error { |
This comment was marked as abuse.
This comment was marked as abuse.
Sorry, something went wrong.
@alban Can you please a few examples of the lines which use to fail in |
Also, please extend the commented format examples in |
With net.netfilter.nf_conntrack_acct = 1, conntrack adds the following fields in the output: packets=3 bytes=164 And with SELinux (e.g. Fedora), conntrack adds: secctx=... The parsing with fmt.Sscanf introduced in weaveworks#2095 was unfortunately rejecting lines with those fields. This patch fixes that by adding more complicated parsing in decodeFlowKeyValues() with FieldsFunc and SplitN. Fixes weaveworks#2117 Regression from weaveworks#2095
e640d2b
to
f1e2b5d
Compare
Updated and rebased. Only the dumped flows have the extra fields, so I updated the examples and the tests for the dumped flows only. |
With net.netfilter.nf_conntrack_acct = 1, conntrack adds the following
fields in the output: packets=3 bytes=164
And with SELinux (e.g. Fedora), conntrack adds: secctx=...
The parsing with fmt.Sscanf introduced in #2095 was unfortunately
rejecting lines with those fields. This patch fixes that by adding more
complicated parsing in decodeTwoTuples() with FieldsFunc and SplitN.
Fixes #2117
Regression from #2095
/cc @iaguis @2opremio