Skip to content

chore(perf-issues): Dedupe the evidence from URL parameters in experiment #92222

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ def _maybe_store_problem(self) -> None:
"repeating_spans_compact": get_span_evidence_value(self.spans[0], include_op=False),
"parameters": self._get_parameters()["query_params"],
"path_parameters": self._get_parameters()["path_params"],
"common_url": problem_description,
},
evidence_display=[
IssueEvidence(
Expand Down Expand Up @@ -215,9 +216,23 @@ def _get_parameters(self) -> dict[str, list[str]]:

for key, value in query_params.items():
query_dict[key] += value

path_params_list = [f"{', '.join(param_group)}" for param_group in path_params]
path_seen_set = set()
query_params_list = [f"{key}: {', '.join(values)}" for key, values in query_dict.items()]
query_param_set = set()
return {
"path_params": [f"{', '.join(param_group)}" for param_group in path_params],
"query_params": [f"{key}: {', '.join(values)}" for key, values in query_dict.items()],
# Use sets to deduplicate the lists, but still preserve the order.
"path_params": [
param
for param in path_params_list
if not (param in path_seen_set or path_seen_set.add(param))
],
"query_params": [
param
for param in query_params_list
if not (param in query_param_set or query_param_set.add(param))
],
}

def _get_parameterized_url(self, span: Span) -> str:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,14 +198,17 @@ def test_does_detect_problem_with_unparameterized_urls(self):
assert problem.fingerprint == f"1-{self.type_id}-bf7ad6b20bb345ae327362c849427956862bf839"

def test_does_detect_problem_with_parameterized_urls(self):
event = self.create_event(lambda i: f"GET /clients/{i}/info/{i*100}/")
event = self.create_event(lambda i: f"GET /clients/{i}/info/{i*100}/?id={i}")
[problem] = self.find_problems(event)
assert problem.desc == "/clients/*/info/*/"
assert problem.desc == "/clients/*/info/*/?id=*"
assert problem.evidence_data is not None
assert problem.evidence_data["common_url"] == "/clients/*/info/*/?id=*"
path_params = problem.evidence_data.get("path_parameters", [])
# It should sequentially store sets of path parameters on the evidence data
for i in range(len(path_params)):
assert path_params[i] == f"{i}, {i*100}"
query_params = problem.evidence_data.get("parameters", [])
assert query_params == ["id: 0, 1, 2, 3, 4, 5"]
assert problem.fingerprint == f"1-{self.type_id}-8bf177290e2d78550fef5a1f6e9ddf115e4b0614"

def test_does_not_detect_problem_with_concurrent_calls_to_different_urls(self):
Expand Down
Loading