Commit 5f9b47b
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 5f9b47b
2 files changed
Lines changed: 34 additions & 8 deletions
File tree
- agent_api/src
- main/java/dev/aikido/agent_api/helpers/net
- test/java/helpers
Lines changed: 8 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 | + | |
60 | 64 | | |
61 | 65 | | |
62 | 66 | | |
| |||
76 | 80 | | |
77 | 81 | | |
78 | 82 | | |
79 | | - | |
80 | | - | |
81 | | - | |
82 | | - | |
83 | | - | |
84 | | - | |
| 83 | + | |
| 84 | + | |
85 | 85 | | |
86 | 86 | | |
87 | 87 | | |
| |||
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