Skip to content

Commit

Permalink
[Debugger] Enable python tests (#3685)
Browse files Browse the repository at this point in the history
[DEBUG-2759], [DEBUG-2898]
  • Loading branch information
shurivich authored Dec 16, 2024
1 parent 344f884 commit 315196d
Show file tree
Hide file tree
Showing 7 changed files with 168 additions and 101 deletions.
6 changes: 5 additions & 1 deletion manifests/python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -594,7 +594,11 @@ tests/:
test_debugger_exception_replay.py:
Test_Debugger_Exception_Replay: missing_feature
test_debugger_expression_language.py:
Test_Debugger_Expression_Language: bug (DEBUG-2898)
Test_Debugger_Expression_Language:
'*': missing_feature
flask-poc: v2.11.0
uds-flask: v2.11.0
uwsgi-poc: v2.11.0
test_debugger_pii.py:
Test_Debugger_PII_Redaction:
'*': missing_feature
Expand Down
188 changes: 120 additions & 68 deletions tests/debugger/test_debugger_expression_language.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import tests.debugger.utils as debugger
import re, json
from utils import scenarios, features, bug, context
from utils import scenarios, features, bug, missing_feature, context


@features.debugger_expression_language
Expand Down Expand Up @@ -49,6 +49,12 @@ def _validate_expression_language_messages(self, expected_message_map):
f" Evaluation error in probe id {probe_id}: {error['expr']} - {error['message']}\n"
)

evaluation_errors = snapshot["debugger"]["snapshot"].get("evaluationErrors", [])
for error in evaluation_errors:
error_messages.append(
f" Evaluation error in probe id {probe_id}: {error['expr']} - {error['message']}\n"
)

not_found_list = "\n".join(not_found_ids)
assert not error_messages, "Errors occurred during validation:\n" + "\n".join(error_messages)
assert not not_found_ids, f"The following probes were not found:\n{not_found_list}"
Expand Down Expand Up @@ -126,7 +132,7 @@ def setup_expression_language_comparison_operators(self):
["intValue ne 5", False, Dsl("ne", [Dsl("ref", "intValue"), 5])],
["intValue le 0", False, Dsl("le", [Dsl("ref", "intValue"), 0])],
["intValue ge 10", False, Dsl("ge", [Dsl("ref", "intValue"), 10])],
["floatValue ne 0", True, Dsl("ne", [Dsl("ref", "floatValue"), 3.14])],
["floatValue ne 0", True, Dsl("ne", [Dsl("ref", "floatValue"), 0])],
["floatValue ne 0.1", True, Dsl("ne", [Dsl("ref", "floatValue"), 0.1])],
["floatValue lt 10", True, Dsl("lt", [Dsl("ref", "floatValue"), 10])],
["floatValue lt 10.10", True, Dsl("lt", [Dsl("ref", "floatValue"), 10.10])],
Expand Down Expand Up @@ -185,9 +191,14 @@ def setup_expression_language_instance_of(self):
Dsl("instanceof", [Dsl("ref", "strValue"), self._get_type("string")]),
],
[
"this instanceof controller",
"pii instanceof pii",
True,
Dsl("instanceof", [Dsl("ref", "this"), self._get_type("controller")]),
Dsl("instanceof", [Dsl("ref", "pii"), self._get_type("pii")]),
],
[
"pii instanceof pii base",
True,
Dsl("instanceof", [Dsl("ref", "pii"), self._get_type("pii")]),
],
[
"intValue instanceof float",
Expand All @@ -204,7 +215,7 @@ def setup_expression_language_instance_of(self):
False,
Dsl("instanceof", [Dsl("ref", "strValue"), self._get_type("float")]),
],
["this instanceof string", False, Dsl("instanceof", [Dsl("ref", "this"), self._get_type("string")])],
["pii instanceof string", False, Dsl("instanceof", [Dsl("ref", "pii"), self._get_type("string")])],
],
)

Expand Down Expand Up @@ -299,34 +310,93 @@ def test_expression_language_string_operations(self):
self._assert(expected_response=200)

############ collection operations ############
## at the app there are 3 types of collections are created - array, list and hash.
## the number at the end of variable means the length of the collection
## all collection are filled with incremented number values (e.g at the [0] = 0; [1] = 1)

def setup_expression_language_collection_operations(self):
message_map, probes = self._create_expression_probes(
methodName="CollectionOperations",
expressions=[
### at the app there are 3 types of collections are created - array, list and hash.
### the number at the end of variable means the length of the collection
### all collection are filled with incremented number values (e.g at the [0] = 0; [1] = 1)
##### len
["Array0 len", 0, Dsl("len", Dsl("ref", "a0"))],
["Array1 len", 1, Dsl("len", Dsl("ref", "a1"))],
["Array5 len", 5, Dsl("len", Dsl("ref", "a5"))],
["List0 len", 0, Dsl("len", Dsl("ref", "l0"))],
["List1 len", 1, Dsl("len", Dsl("ref", "l1"))],
["List5 len", 5, Dsl("len", Dsl("ref", "l5"))],
["Hash0 len", 0, Dsl("len", Dsl("ref", "h0"))],
["Hash1 len", 1, Dsl("len", Dsl("ref", "h1"))],
["Hash5 len", 5, Dsl("len", Dsl("ref", "h5"))],
##### index
["Array5 index 4", 4, Dsl("index", [Dsl("ref", "a5"), 4])],
["List5 index 4", 4, Dsl("index", [Dsl("ref", "l5"), 4])],
["Hash5 index 4", 4, Dsl("index", [Dsl("ref", "h5"), 4])],
##### any
["Array0 any gt 1", False, Dsl("any", [Dsl("ref", "a0"), Dsl("gt", [Dsl("ref", "@it"), 1])])],
["Array1 any gt 1", False, Dsl("any", [Dsl("ref", "a1"), Dsl("gt", [Dsl("ref", "@it"), 1])])],
["Array5 any gt 1", True, Dsl("any", [Dsl("ref", "a5"), Dsl("gt", [Dsl("ref", "@it"), 1])])],
["List0 any gt 1", False, Dsl("any", [Dsl("ref", "l0"), Dsl("gt", [Dsl("ref", "@it"), 1])])],
["List1 any gt 1", False, Dsl("any", [Dsl("ref", "l1"), Dsl("gt", [Dsl("ref", "@it"), 1])])],
["List5 any gt 1", True, Dsl("any", [Dsl("ref", "l5"), Dsl("gt", [Dsl("ref", "@it"), 1])])],
##### all
["Array0 all ge 0", True, Dsl("all", [Dsl("ref", "a0"), Dsl("ge", [Dsl("ref", "@it"), 0])])],
["Array1 all ge 0", True, Dsl("all", [Dsl("ref", "a1"), Dsl("ge", [Dsl("ref", "@it"), 0])])],
["Array5 all ge 1", False, Dsl("all", [Dsl("ref", "a5"), Dsl("ge", [Dsl("ref", "@it"), 1])])],
["List0 all ge 0", True, Dsl("all", [Dsl("ref", "l0"), Dsl("ge", [Dsl("ref", "@it"), 0])])],
["List1 all ge 0", True, Dsl("all", [Dsl("ref", "l1"), Dsl("ge", [Dsl("ref", "@it"), 0])])],
["List5 all ge 1", False, Dsl("all", [Dsl("ref", "l5"), Dsl("ge", [Dsl("ref", "@it"), 1])])],
##### filter
[
"Array0 len filter lt 2",
0,
Dsl("len", Dsl("filter", [Dsl("ref", "a0"), Dsl("lt", [Dsl("ref", "@it"), 2])])),
],
[
"Array1 len filter lt 2",
1,
Dsl("len", Dsl("filter", [Dsl("ref", "a1"), Dsl("lt", [Dsl("ref", "@it"), 2])])),
],
[
"Array5 len filter lt 2",
2,
Dsl("len", Dsl("filter", [Dsl("ref", "a5"), Dsl("lt", [Dsl("ref", "@it"), 2])])),
],
[
"List0 len filter lt 2",
0,
Dsl("len", Dsl("filter", [Dsl("ref", "l0"), Dsl("lt", [Dsl("ref", "@it"), 2])])),
],
[
"List1 len filter lt 2",
1,
Dsl("len", Dsl("filter", [Dsl("ref", "l1"), Dsl("lt", [Dsl("ref", "@it"), 2])])),
],
[
"List5 len filter lt 2",
2,
Dsl("len", Dsl("filter", [Dsl("ref", "l5"), Dsl("lt", [Dsl("ref", "@it"), 2])])),
],
],
)

self.message_map = message_map
self._setup(probes, "/debugger/expression/collections")

@bug(library="dotnet", reason="DEBUG-2602")
def test_expression_language_collection_operations(self):
self._assert(expected_response=200)

def setup_expression_language_hash_operations(self):
message_map, probes = self._create_expression_probes(
methodName="CollectionOperations",
expressions=[
## at the app there are 3 types of collections are created - array, list and hash.
## the number at the end of variable means the length of the collection
## all collection are filled with incremented number values (e.g at the [0] = 0; [1] = 1)
#### len
["Hash0 len", 0, Dsl("len", Dsl("ref", "h0"))],
["Hash1 len", 1, Dsl("len", Dsl("ref", "h1"))],
["Hash5 len", 5, Dsl("len", Dsl("ref", "h5"))],
##### index
["Hash5 index 4", 4, Dsl("index", [Dsl("ref", "h5"), 4])],
##### any
[
"Hash0 any gt 1",
False,
Expand Down Expand Up @@ -361,12 +431,6 @@ def setup_expression_language_collection_operations(self):
),
],
##### all
["Array0 all ge 0", True, Dsl("all", [Dsl("ref", "a0"), Dsl("ge", [Dsl("ref", "@it"), 0])])],
["Array1 all ge 0", True, Dsl("all", [Dsl("ref", "a1"), Dsl("ge", [Dsl("ref", "@it"), 0])])],
["Array5 all ge 1", False, Dsl("all", [Dsl("ref", "a5"), Dsl("ge", [Dsl("ref", "@it"), 1])])],
["List0 all ge 0", True, Dsl("all", [Dsl("ref", "l0"), Dsl("ge", [Dsl("ref", "@it"), 0])])],
["List1 all ge 0", True, Dsl("all", [Dsl("ref", "l1"), Dsl("ge", [Dsl("ref", "@it"), 0])])],
["List5 all ge 1", False, Dsl("all", [Dsl("ref", "l5"), Dsl("ge", [Dsl("ref", "@it"), 1])])],
[
"Hash0 all ge 0",
True,
Expand Down Expand Up @@ -401,36 +465,6 @@ def setup_expression_language_collection_operations(self):
),
],
##### filter
[
"Array0 len filter lt 2",
0,
Dsl("len", Dsl("filter", [Dsl("ref", "a0"), Dsl("lt", [Dsl("ref", "@it"), 2])])),
],
[
"Array1 len filter lt 2",
1,
Dsl("len", Dsl("filter", [Dsl("ref", "a1"), Dsl("lt", [Dsl("ref", "@it"), 2])])),
],
[
"Array5 len filter lt 2",
2,
Dsl("len", Dsl("filter", [Dsl("ref", "a5"), Dsl("lt", [Dsl("ref", "@it"), 2])])),
],
[
"List0 len filter lt 2",
0,
Dsl("len", Dsl("filter", [Dsl("ref", "l0"), Dsl("lt", [Dsl("ref", "@it"), 2])])),
],
[
"List1 len filter lt 2",
1,
Dsl("len", Dsl("filter", [Dsl("ref", "l1"), Dsl("lt", [Dsl("ref", "@it"), 2])])),
],
[
"List5 len filter lt 2",
2,
Dsl("len", Dsl("filter", [Dsl("ref", "l5"), Dsl("lt", [Dsl("ref", "@it"), 2])])),
],
[
"Hash0 len filter lt 2",
0,
Expand Down Expand Up @@ -489,7 +523,8 @@ def setup_expression_language_collection_operations(self):
self._setup(probes, "/debugger/expression/collections")

@bug(library="dotnet", reason="DEBUG-2602")
def test_expression_language_collection_operations(self):
@missing_feature(library="python", reason="DEBUG-3240")
def test_expression_language_hash_operations(self):
self._assert(expected_response=200)

############ nulls ############
Expand All @@ -512,51 +547,66 @@ def test_expression_language_nulls_true(self):

def setup_expression_language_nulls_false(self):
message_map, probes = self._create_expression_probes(
methodName="ExpressionOperators",
methodName="Nulls",
expressions=[
["intValue eq null", False, Dsl("eq", [Dsl("ref", "intValue"), None])],
["floatValue eq null", False, Dsl("eq", [Dsl("ref", "floatValue"), None])],
["strValue eq null", False, Dsl("eq", [Dsl("ref", "strValue"), None])],
["this eq null", False, Dsl("eq", [Dsl("ref", "this"), None])],
["pii eq null", False, Dsl("eq", [Dsl("ref", "pii"), None])],
],
)

self.message_map = message_map
self._setup(probes, "/debugger/expression/operators?intValue=5&floatValue=3.14&strValue=haha")
self._setup(probes, "/debugger/expression/null?intValue=5&strValue=haha&boolValue=true")

@bug(library="dotnet", reason="DEBUG-2618")
def test_expression_language_nulls_false(self):
self._assert(expected_response=200)

############ helpers ############
def _get_type(self, value_type):
intance_type = ""
instance_type = ""

if self.get_tracer()["language"] == "dotnet":
if value_type == "int":
intance_type = "System.Int32"
instance_type = "System.Int32"
elif value_type == "float":
intance_type = "System.Single"
instance_type = "System.Single"
elif value_type == "string":
intance_type = "System.String"
elif value_type == "controller":
intance_type = "weblog.DebuggerController"
instance_type = "System.String"
elif value_type == "pii":
instance_type = "weblog.Models.Debugger.Pii"
elif value_type == "pii_base":
instance_type = "weblog.Models.Debugger.PiiBase"
else:
intance_type = value_type
instance_type = value_type
elif self.get_tracer()["language"] == "java":
if value_type == "int":
intance_type = "java.lang.Integer"
instance_type = "java.lang.Integer"
elif value_type == "float":
intance_type = "java.lang.Float"
instance_type = "java.lang.Float"
elif value_type == "string":
intance_type = "java.lang.String"
elif value_type == "controller":
intance_type = "com.datadoghq.system_tests.springboot.DebuggerController"
instance_type = "java.lang.String"
elif value_type == "pii":
instance_type = "com.datadoghq.system_tests.springboot.PiiBase"
else:
intance_type = value_type
instance_type = value_type
elif self.get_tracer()["language"] == "python":
if value_type == "int":
instance_type = "int"
elif value_type == "float":
instance_type = "float"
elif value_type == "string":
instance_type = "str"
elif value_type == "pii":
instance_type = "debugger.pii.Pii"
elif value_type == "pii":
instance_type = "debugger.pii.PiiBase"
else:
instance_type = value_type
else:
intance_type = value_type
return intance_type
instance_type = value_type

return instance_type

def _get_hash_value_property_name(self):
if self.get_tracer()["language"] == "dotnet":
Expand All @@ -574,6 +624,8 @@ def _create_expression_probes(self, methodName, expressions):

if isinstance(expected_result, bool):
expected_result = "[Tt]rue" if expected_result else "[Ff]alse"
elif isinstance(expected_result, str) and expected_result and expected_result != "":
expected_result = f"[']?{expected_result}[']?"
else:
expected_result = str(expected_result)

Expand Down
4 changes: 0 additions & 4 deletions tests/debugger/test_debugger_probe_snapshot.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ def _validate_spans(self):
def setup_log_method_probe_snaphots(self):
self._setup("probe_snapshot_log_method", "/debugger/log")

@bug(library="python", reason="DEBUG-2708, DEBUG-2709")
def test_log_method_probe_snaphots(self):
self._assert()
self._validate_snapshots()
Expand All @@ -55,7 +54,6 @@ def test_log_method_probe_snaphots(self):
def setup_span_method_probe_snaphots(self):
self._setup("probe_snapshot_span_method", "/debugger/span")

@bug(library="python", reason="DEBUG-2708, DEBUG-2709")
def test_span_method_probe_snaphots(self):
self._assert()
self._validate_spans()
Expand All @@ -64,7 +62,6 @@ def test_span_method_probe_snaphots(self):
def setup_span_decoration_method_probe_snaphots(self):
self._setup("probe_snapshot_span_decoration_method", "/debugger/span-decoration/asd/1")

@bug(library="python", reason="DEBUG-2708, DEBUG-2709")
@missing_feature(context.library == "ruby", reason="Not yet implemented")
def test_span_decoration_method_probe_snaphots(self):
self._assert()
Expand Down Expand Up @@ -93,7 +90,6 @@ def test_span_decoration_line_probe_snaphots(self):
def setup_mix_probe(self):
self._setup("probe_snapshot_log_mixed", "/debugger/mix/asd/1")

@bug(library="python", reason="DEBUG-2710")
def test_mix_probe(self):
self._assert()
self._validate_snapshots()
5 changes: 0 additions & 5 deletions tests/test_schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,6 @@ def test_library_schema_full(self):
("/telemetry/proxy/api/v2/apmtelemetry", "$.payload.configuration[]"),
("/telemetry/proxy/api/v2/apmtelemetry", "$.payload"), # APPSEC-52845
("/telemetry/proxy/api/v2/apmtelemetry", "$.payload.configuration[].value"), # APMS-12697
("/debugger/v1/input", "$[].dd.span_id"), # DEBUG-2743
("/debugger/v1/input", "$[].dd.trace_id"), # DEBUG-2743
("/debugger/v1/input", "$[].debugger.snapshot.probe.location.lines[]"), # DEBUG-2743
("/debugger/v1/input", "$[].debugger.snapshot.captures"), # DEBUG-2743
("/debugger/v1/diagnostics", "$[].content"), # DEBUG-2864
]

Expand All @@ -48,7 +44,6 @@ def test_python_debugger_line_number(self):
def test_library_diagnostics_content(self):
interfaces.library.assert_schema_point("/debugger/v1/diagnostics", "$[].content")

@bug(context.library == "python", reason="DEBUG-2743")
def test_library_schema_debugger(self):
interfaces.library.assert_schema_point("/debugger/v1/input", "$[].dd.span_id")
interfaces.library.assert_schema_point("/debugger/v1/input", "$[].dd.trace_id")
Expand Down
Loading

0 comments on commit 315196d

Please sign in to comment.