Commit a008d59
dmitrii
Avoid running the IPv6 regex on IPv4:port in normalizeIp
normalizeIp() called the version-less IPValidator.isIP(ip) first, which runs
the expensive IPv6 regex on every value that is not a bare IPv4 — including
IPv4:port forms that proxies routinely send in X-Forwarded-For / the peer
address. Since this runs in the per-request context constructor, it added
CPU on proxied traffic (introduced in #307).
Reorder normalizeIp to run the cheap structural checks before the version-less
isIP, keeping the same checks (and branch bodies) as zen-node's
getClientIpFromHeader: single-colon IPv4:port via isIP(host, "4"), then
bracketed IPv6 ([ipv6] / [ipv6]:port), and only then the version-less isIP as
the final fallback. node's isIP is native and cheap, ours is a regex, so the
only deviation from node is running isIP last instead of first.
Behavior is unchanged (existing ProxyForwardedParserTest suite passes; added
cases for multi-colon IPv4, IPv4:port short-circuit, bracketed IPv4 and
malformed "[::1]foo"). Verified with a JFR A/B on zen-demo-java under ip:port
traffic: total agent CPU 4.90% -> 4.41% (baseline before the regression 4.53%).1 parent 6ee5432 commit a008d59
2 files changed
Lines changed: 42 additions & 8 deletions
File tree
- agent_api/src
- main/java/dev/aikido/agent_api/helpers/net
- test/java/helpers
Lines changed: 16 additions & 8 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
55 | 55 | | |
56 | 56 | | |
57 | 57 | | |
58 | | - | |
59 | | - | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
60 | 70 | | |
61 | 71 | | |
| 72 | + | |
62 | 73 | | |
63 | 74 | | |
64 | 75 | | |
65 | 76 | | |
66 | 77 | | |
67 | 78 | | |
68 | 79 | | |
| 80 | + | |
69 | 81 | | |
70 | 82 | | |
71 | 83 | | |
| |||
76 | 88 | | |
77 | 89 | | |
78 | 90 | | |
79 | | - | |
80 | | - | |
81 | | - | |
82 | | - | |
83 | | - | |
84 | | - | |
| 91 | + | |
| 92 | + | |
85 | 93 | | |
86 | 94 | | |
87 | 95 | | |
| |||
Lines changed: 26 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
214 | 214 | | |
215 | 215 | | |
216 | 216 | | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
217 | 243 | | |
0 commit comments