-
Notifications
You must be signed in to change notification settings - Fork 10
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
Add IP quantization to obfuscation #801
base: main
Are you sure you want to change the base?
Conversation
BenchmarksComparisonBenchmark execution time: 2024-12-17 10:30:21 Comparing candidate commit 806ae3d in PR branch Found 0 performance improvements and 4 performance regressions! Performance is the same for 47 metrics, 2 unstable metrics. scenario:credit_card/is_card_number/x371413321323331
scenario:credit_card/is_card_number_no_luhn/x371413321323331
CandidateCandidate benchmark detailsGroup 1
Group 2
Group 3
Group 4
Group 5
Group 6
Group 7
Group 8
Group 9
Group 10
Group 11
Group 12
Group 13
BaselineOmitted due to size. |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #801 +/- ##
==========================================
+ Coverage 70.92% 71.04% +0.12%
==========================================
Files 313 314 +1
Lines 45752 45951 +199
==========================================
+ Hits 32450 32647 +197
- Misses 13302 13304 +2
|
2c2511c
to
d6b9432
Compare
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.
LGTM although I would recommend using OnceLock to avoid more dependencies.
// Copyright 2024-Present Datadog, Inc. https://www.datadoghq.com/ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
use lazy_static::lazy_static; |
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.
In this case since the types are not Sync you'll have to use OnceLock.
use lazy_static::lazy_static; | |
use std::sync::OnceLock |
lazy_static! { | ||
static ref ALLOWED_IP_ADDRESSES: HashSet<&'static str> = HashSet::from([ | ||
// localhost | ||
"127.0.0.1", | ||
"::1", | ||
// link-local cloud provider metadata server addresses | ||
"169.254.169.254", | ||
"fd00:ec2::254" | ||
]); | ||
|
||
static ref PREFIX_REGEX: Regex = Regex::new(r"^((?:dnspoll|ftp|file|http|https):/{2,3})").unwrap(); | ||
} |
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.
lazy_static! { | |
static ref ALLOWED_IP_ADDRESSES: HashSet<&'static str> = HashSet::from([ | |
// localhost | |
"127.0.0.1", | |
"::1", | |
// link-local cloud provider metadata server addresses | |
"169.254.169.254", | |
"fd00:ec2::254" | |
]); | |
static ref PREFIX_REGEX: Regex = Regex::new(r"^((?:dnspoll|ftp|file|http|https):/{2,3})").unwrap(); | |
} | |
static ALLOWED_IP_ADDRESSES: OnceLock<HashSet<&'static str>> = OnceLock::new(); | |
static PREFIX_REGEX: OnceLock<Regex> = OnceLock::new(); | |
} |
fn quantize_ip(s: &str) -> Option<String> { | ||
let (prefix, stripped_s) = split_prefix(s); | ||
if let Some((ip, suffix)) = parse_ip(stripped_s) { | ||
if !ALLOWED_IP_ADDRESSES.contains(ip) { |
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.
if !ALLOWED_IP_ADDRESSES.contains(ip) { | |
if !ALLOWED_IP_ADDRESSES | |
.get_or_init(|| { | |
HashSet::from([ | |
// localhost | |
"127.0.0.1", | |
"::1", | |
// link-local cloud provider metadata server addresses | |
"169.254.169.254", | |
"fd00:ec2::254", | |
]) | |
}) | |
.contains(ip) | |
{ | |
fn split_prefix(s: &str) -> (&str, &str) { | ||
if let Some(tail) = s.strip_prefix("ip-") { | ||
("ip-", tail) | ||
} else if let Some(protocol) = PREFIX_REGEX.find(s) { |
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.
} else if let Some(protocol) = PREFIX_REGEX.find(s) { | |
} else if let Some(protocol) = PREFIX_REGEX | |
.get_or_init(|| Regex::new(r"^((?:dnspoll|ftp|file|http|https):/{2,3})").unwrap()) | |
.find(s) | |
{ | |
@@ -14,6 +14,7 @@ serde = { version = "1.0.145", features = ["derive"] } | |||
serde_json = "1.0" | |||
url = "2.4.0" | |||
percent-encoding = "2.1" | |||
lazy_static = "1.4" |
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 would use OnceCell variants. It's part of the std so less dependencies and provides some advantages over lazy_static since it can accept closures as initializers, it's macro-free (I wouldn't count that as a massive adv) and, on certain scenarios, it could be more efficient regarding memory handling.
lazy_static = "1.4" |
What does this PR do?
Add IP quantization used to obfuscate peer-tags fields
Motivation
What inspired you to submit this pull request?
Additional Notes
Anything else we should know when reviewing?
How to test the change?
Describe here in detail how the change can be validated.