Skip to content
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: tests for probe budgets #3910

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
20 changes: 20 additions & 0 deletions tests/debugger/probes/probe_snapshot_log_line_budgets.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[
{
"language": "",
"type": "",
"id": "log170aa-acda-4453-9111-1478a697line",
"version": 0,
"where": {
"typeName": null,
"sourceFile": "ACTUAL_SOURCE_FILE",
"lines": [
"141"
]
},
"captureSnapshot": true,
"capture": {
"maxFieldCount": 200
},
"tags": []
}
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
[
{
"language": "",
"type": "",
"id": "log170aa-acda-4453-9111-1478a697line",
"version": 0,
"where": {
"typeName": null,
"sourceFile": "ACTUAL_SOURCE_FILE",
"lines": [
"141"
]
},
"captureSnapshot": true,
"capture": {
"maxFieldCount": 200
},
"tags": [
"session_id: r3z0v"
]
}
]
32 changes: 10 additions & 22 deletions tests/debugger/test_debugger_expression_language.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def setup_expression_language_access_variables(self):
Dsl("index", [Dsl("getmember", [Dsl("ref", "testStruct"), "Dictionary"]), "two"]),
],
],
lines=self._method_and_language_to_line_number(method, language),
lines=self.method_and_language_to_line_number(method, language),
)

self.message_map = message_map
Expand Down Expand Up @@ -124,7 +124,7 @@ def setup_expression_language_access_exception(self):
message_map, probes = self._create_expression_probes(
methodName=method,
expressions=[["Accessing exception", ".*Hello from exception", Dsl("ref", "@exception")]],
lines=self._method_and_language_to_line_number(method, language),
lines=self.method_and_language_to_line_number(method, language),
)

self.message_map = message_map
Expand Down Expand Up @@ -187,7 +187,7 @@ def setup_expression_language_comparison_operators(self):
["strValue le a", False, Dsl("le", [Dsl("ref", "strValue"), "a"])],
["strValue ge z", False, Dsl("ge", [Dsl("ref", "strValue"), "z"])],
],
lines=self._method_and_language_to_line_number(method, language),
lines=self.method_and_language_to_line_number(method, language),
)

self.message_map = message_map
Expand Down Expand Up @@ -240,7 +240,7 @@ def setup_expression_language_instance_of(self):
],
["pii instanceof string", False, Dsl("instanceof", [Dsl("ref", "pii"), self._get_type("string")])],
],
lines=self._method_and_language_to_line_number(method, language),
lines=self.method_and_language_to_line_number(method, language),
)

self.message_map = message_map
Expand Down Expand Up @@ -279,7 +279,7 @@ def setup_expression_language_logical_operators(self):
],
["not intValue eq 10", False, Dsl("not", Dsl("eq", [Dsl("ref", "intValue"), 5]))],
],
lines=self._method_and_language_to_line_number(method, language),
lines=self.method_and_language_to_line_number(method, language),
)

self.message_map = message_map
Expand Down Expand Up @@ -327,7 +327,7 @@ def setup_expression_language_string_operations(self):
["emptyString matches empty", True, Dsl("matches", [Dsl("ref", "emptyString"), ""])],
["emptyString matches some", False, Dsl("matches", [Dsl("ref", "emptyString"), "foo"])],
],
lines=self._method_and_language_to_line_number(method, language),
lines=self.method_and_language_to_line_number(method, language),
)

self.message_map = message_map
Expand Down Expand Up @@ -403,7 +403,7 @@ def setup_expression_language_collection_operations(self):
Dsl("len", Dsl("filter", [Dsl("ref", "l5"), Dsl("lt", [Dsl("ref", "@it"), 2])])),
],
],
lines=self._method_and_language_to_line_number(method, language),
lines=self.method_and_language_to_line_number(method, language),
)

self.message_map = message_map
Expand Down Expand Up @@ -548,7 +548,7 @@ def setup_expression_language_hash_operations(self):
),
],
],
lines=self._method_and_language_to_line_number(method, language),
lines=self.method_and_language_to_line_number(method, language),
)

self.message_map = message_map
Expand All @@ -569,7 +569,7 @@ def setup_expression_language_nulls_true(self):
["strValue eq null", True, Dsl("eq", [Dsl("ref", "strValue"), None])],
["pii eq null", True, Dsl("eq", [Dsl("ref", "pii"), None])],
],
lines=self._method_and_language_to_line_number(method, language),
lines=self.method_and_language_to_line_number(method, language),
)

self.message_map = message_map
Expand All @@ -588,7 +588,7 @@ def setup_expression_language_nulls_false(self):
["strValue eq null", False, Dsl("eq", [Dsl("ref", "strValue"), None])],
["pii eq null", False, Dsl("eq", [Dsl("ref", "pii"), None])],
],
lines=self._method_and_language_to_line_number(method, language),
lines=self.method_and_language_to_line_number(method, language),
)

self.message_map = message_map
Expand Down Expand Up @@ -650,18 +650,6 @@ def _get_hash_value_property_name(self):
else:
return "value"

def _method_and_language_to_line_number(self, method, language):
"""_method_and_language_to_line_number returns the respective line number given the method and language"""
return {
"Expression": {"java": [71], "dotnet": [74], "python": [72]},
# The `@exception` variable is not available in the context of line probes.
"ExpressionException": {},
"ExpressionOperators": {"java": [82], "dotnet": [90], "python": [87]},
"StringOperations": {"java": [87], "dotnet": [97], "python": [96]},
"CollectionOperations": {"java": [114], "dotnet": [114], "python": [123]},
"Nulls": {"java": [130], "dotnet": [127], "python": [136]},
}.get(method, {}).get(language, [])

def _create_expression_probes(self, methodName, expressions, lines=[]):
probes = []
expected_message_map = {}
Expand Down
67 changes: 66 additions & 1 deletion tests/debugger/test_debugger_probe_snapshot.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,19 @@
@scenarios.debugger_probes_snapshot
class Test_Debugger_Probe_Snaphots(debugger._Base_Debugger_Test):
############ setup ############
def _setup(self, probes_name: str, request_path: str):
def _setup(self, probes_name: str, request_path: str, lines=None):
self.initialize_weblog_remote_config()

### prepare probes
probes = debugger.read_probes(probes_name)
if lines is not None:
for probe in probes:
if "methodName" in probe["where"]:
del probe["where"]["methodName"]
probe["where"]["lines"] = lines
probe["where"]["sourceFile"] = "ACTUAL_SOURCE_FILE"
probe["where"]["typeName"] = None

self.set_probes(probes)

### send requests
Expand Down Expand Up @@ -132,3 +140,60 @@ def test_code_origin_entry_present(self):
code_origins_entry_found = code_origin_type == "entry"

assert code_origins_entry_found

def setup_log_line_probe_snaphots_budgets(self):
self._setup(
"probe_snapshot_log_line_budgets",
"/debugger/budgets/20",
lines=self.method_and_language_to_line_number("Budgets", self.get_tracer()["language"]),
)

@missing_feature(
context.library == "java" and context.weblog_variant != "spring-boot", reason="Budget endpoint not implemented"
)
@missing_feature(context.library == "dotnet", reason="Probe snapshot budgets are not yet implemented")
@missing_feature(context.library == "nodejs", reason="Probe snapshot budgets are not yet implemented")
@missing_feature(context.library == "ruby", reason="Probe snapshot budgets are not yet implemented")
def test_log_line_probe_snaphots_budgets(self):
self._assert()
self._validate_snapshots()

snapshots = 0
for _id in self.probe_ids:
for span in self.probe_snapshots[_id]:
snapshot = span.get("debugger", {}).get("snapshot", None)
if snapshot is None:
continue

snapshots += 1

assert snapshots == 1, f"Expected 1 snapshots, got {snapshots}"

def setup_log_line_trigger_probe_snaphots_budgets(self):
self._setup(
"probe_snapshot_log_line_trigger_budgets",
"/debugger/budgets/20",
lines=self.method_and_language_to_line_number("Budgets", self.get_tracer()["language"]),
)

@missing_feature(
context.library == "java" and context.weblog_variant != "spring-boot", reason="Budget endpoint not implemented"
)
@missing_feature(context.library == "python", reason="Trigger probe snapshot waiting for next release")
@missing_feature(context.library == "dotnet", reason="Trigger probe snapshot budgets are not yet implemented")
@missing_feature(context.library == "nodejs", reason="Trigger probe snapshot budgets are not yet implemented")
@missing_feature(context.library == "ruby", reason="Trigger probe snapshot budgets are not yet implemented")
def test_log_line_trigger_probe_snaphots_budgets(self):
self._assert()
self._validate_snapshots()

snapshots = 0
for _id in self.probe_ids:
for span in self.probe_snapshots[_id]:
snapshot = span.get("debugger", {}).get("snapshot", None)
if snapshot is None:
continue

snapshots += 1

assert snapshots == 10, f"Expected 10 snapshots, got {snapshots}"
13 changes: 13 additions & 0 deletions tests/debugger/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,19 @@ def initialize_weblog_remote_config(self):
% (response.status_code)
)

def method_and_language_to_line_number(self, method, language):
"""method_and_language_to_line_number returns the respective line number given the method and language"""
return {
"Budgets": {"python": [142], "java": [138]},
"Expression": {"java": [71], "dotnet": [74], "python": [72]},
# The `@exception` variable is not available in the context of line probes.
"ExpressionException": {},
"ExpressionOperators": {"java": [82], "dotnet": [90], "python": [87]},
"StringOperations": {"java": [87], "dotnet": [97], "python": [96]},
"CollectionOperations": {"java": [114], "dotnet": [114], "python": [123]},
"Nulls": {"java": [130], "dotnet": [127], "python": [136]},
}.get(method, {}).get(language, [])

###### set #####
def set_probes(self, probes):
def _enrich_probes(probes):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,4 +131,12 @@ public String nulls(
". intValue is null: " + (intValue == null) +
". strValue is null: " + (strValue == null) + ".";
}

@GetMapping("/budgets/{loops}")
public String budgets(@PathVariable int loops) {
for (int i = 0; i < loops; i++) {
int noOp = 0; // Line probe is instrumented here.
}
return "Budgets";
}
}
7 changes: 7 additions & 0 deletions utils/build/docker/python/flask/debugger_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,3 +134,10 @@ def nulls():
pii = Pii()

return f"Pii is null {pii is None}. intValue is null {intValue is None}. strValue is null {strValue is None}."


@debugger_blueprint.route("/budgets/<int:loops>", methods=["GET"])
def budgets(loops):
for _ in range(loops):
pass
return "Budgets", 200
Loading