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

[Debugger] Symdb tests #3761

Draft
wants to merge 6 commits 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
2 changes: 2 additions & 0 deletions manifests/cpp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ tests/:
Test_Debugger_Probe_Snaphots: irrelevant
test_debugger_probe_status.py:
Test_Debugger_Probe_Statuses: irrelevant
test_debugger_symdb.py:
Test_Debugger_SymDb: irrelevant
integrations/:
crossed_integrations/:
test_kafka.py:
Expand Down
2 changes: 2 additions & 0 deletions manifests/dotnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,8 @@ tests/:
Test_Debugger_Probe_Snaphots: v2.53.0
test_debugger_probe_status.py:
Test_Debugger_Probe_Statuses: v2.53.0
test_debugger_symdb.py:
Test_Debugger_SymDb: v2.53.0
integrations/:
crossed_integrations/:
test_kafka.py:
Expand Down
2 changes: 2 additions & 0 deletions manifests/golang.yml
Original file line number Diff line number Diff line change
Expand Up @@ -437,6 +437,8 @@ tests/:
Test_Debugger_Probe_Snaphots: missing_feature (feature not implented)
test_debugger_probe_status.py:
Test_Debugger_Probe_Statuses: missing_feature (feature not implented)
test_debugger_symdb.py:
Test_Debugger_SymDb: missing_feature (feature not implented)
integrations/:
crossed_integrations/:
test_kafka.py:
Expand Down
2 changes: 2 additions & 0 deletions manifests/java.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1476,6 +1476,8 @@ tests/:
spring-boot-undertow: v1.38.0
spring-boot-wildfly: v1.38.0
uds-spring-boot: v1.38.0
test_debugger_symdb.py:
Test_Debugger_SymDb: v1.38.0
integrations/:
crossed_integrations/:
test_kafka.py:
Expand Down
2 changes: 2 additions & 0 deletions manifests/nodejs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -648,6 +648,8 @@ tests/:
Test_Debugger_Probe_Snaphots: missing_feature (feature not implented)
test_debugger_probe_status.py:
Test_Debugger_Probe_Statuses: missing_feature (feature not implented)
test_debugger_symdb.py:
Test_Debugger_SymDb: missing_feature (feature not implented)
integrations/:
crossed_integrations/:
test_kafka.py:
Expand Down
2 changes: 2 additions & 0 deletions manifests/php.yml
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,8 @@ tests/:
Test_Debugger_Probe_Snaphots: irrelevant
test_debugger_probe_status.py:
Test_Debugger_Probe_Statuses: irrelevant
test_debugger_symdb.py:
Test_Debugger_SymDb: irrelevant
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this irrelevant and not missing feature?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmmm, you're right, I aligned with other definitions for this library.
I will fix it in separate PR.

integrations/:
crossed_integrations/:
test_kafka.py:
Expand Down
2 changes: 2 additions & 0 deletions manifests/python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -630,6 +630,8 @@ tests/:
flask-poc: v2.11.0
uds-flask: v2.11.0
uwsgi-poc: v2.11.0
test_debugger_symdb.py:
Test_Debugger_SymDb: v2.11.0
integrations/:
crossed_integrations/:
test_kafka.py:
Expand Down
4 changes: 4 additions & 0 deletions manifests/ruby.yml
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,10 @@ tests/:
Test_Debugger_Probe_Statuses:
"*": irrelevant
rails70: v2.8.0
test_debugger_symdb.py:
Test_Debugger_SymDb:
"*": irrelevant
rails70: missing_feature (feature not implemented)
integrations/:
crossed_integrations/:
test_kafka.py:
Expand Down
93 changes: 93 additions & 0 deletions tests/debugger/test_debugger_symdb.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
# Unless explicitly stated otherwise all files in this repository are licensed under the the Apache License Version 2.0.
# This product includes software developed at Datadog (https://www.datadoghq.com/).
# Copyright 2021 Datadog, Inc.

import gzip
import json
import tests.debugger.utils as debugger
from utils import features, scenarios, bug, context
from utils import remote_config as rc
from jsonschema import Draft7Validator


@features.debugger
@scenarios.debugger_symdb
class Test_Debugger_SymDb(debugger._Base_Debugger_Test):
############ setup ############
def _setup(self):
self.rc_state = rc.send_symdb_command()

############ assert ############
def _assert(self):
self.collect()
self.assert_rc_state_not_error()
self._assert_symbols_uploaded()

def _assert_symbols_uploaded(self):
assert len(self.symbols) > 0, "No symbol files were found"

symbol_type = {
"type": "object",
"required": ["line", "name", "symbol_type", "type"],
"properties": {
"language_specifics": {"type": "object"},
"line": {"type": "integer"},
"name": {"type": "string"},
"symbol_type": {"type": "string"},
"type": {"type": ["string", "null"]},
},
}

scope_type = {
"type": "object",
"required": ["end_line", "scope_type", "source_file", "start_line"],
"properties": {
"end_line": {"type": "integer"},
"language_specifics": {"type": ["object", "null"]},
"name": {"type": ["string", "null"]},
"scope_type": {"type": "string"},
"scopes": {"type": ["array", "null"], "items": {"$ref": "#/definitions/scope"}},
"source_file": {"type": "string"},
"start_line": {"type": "integer"},
"symbols": {"type": ["array", "null"], "items": {"$ref": "#/definitions/symbol"}},
},
}

schema = {
"type": "object",
"required": ["env", "language", "scopes", "service", "version"],
"properties": {
"env": {"type": "string", "const": "system-tests"},
"language": {"type": "string"},
"scopes": {"type": "array", "items": {"$ref": "#/definitions/scope"}},
"service": {"type": "string", "const": "weblog"},
"version": {"type": "string", "const": "1.0.0"},
},
"definitions": {"scope": scope_type, "symbol": symbol_type},
}

validator = Draft7Validator(schema)

for file_path in self.symbols:
assert file_path.endswith(".gz"), f"Symbol file {file_path} is not a .gz file"

try:
with gzip.open(file_path, "rb") as f:
content = json.loads(f.read().decode("utf-8"))
validation_errors = list(validator.iter_errors(content))
assert not validation_errors, f"Schema validation errors in {file_path}:\n" + "\n".join(
f"- {error.message} (at path: {' -> '.join(str(p) for p in error.path)})"
for error in validation_errors
)
except gzip.BadGzipFile:
assert False, f"File {file_path} is not a valid gzip archive"
except json.JSONDecodeError:
assert False, f"File {file_path} does not contain valid JSON"

############ test ############
def setup_symdb_upload(self):
self._setup()

@bug(context.library == "dotnet", reason="DEBUG-3298")
def test_symdb_upload(self):
self._assert()
15 changes: 15 additions & 0 deletions tests/debugger/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import os
import os.path
import uuid
import gzip
import io

from utils import interfaces, remote_config, weblog, context
from utils.tools import logger
Expand All @@ -17,6 +19,7 @@
_DEBUGGER_PATH = "/api/v2/debugger"
_LOGS_PATH = "/api/v2/logs"
_TRACES_PATH = "/api/v0.2/traces"
_SYMBOLS_PATH = "/symdb/v1/input"

_CUR_DIR = os.path.dirname(os.path.abspath(__file__))

Expand Down Expand Up @@ -65,6 +68,7 @@ class _Base_Debugger_Test:
probe_diagnostics = {}
probe_snapshots = {}
probe_spans = {}
symbols = []

rc_state = None
weblog_responses = []
Expand Down Expand Up @@ -259,6 +263,7 @@ def collect(self):
self._collect_probe_diagnostics()
self._collect_snapshots()
self._collect_spans()
self._collect_symbols()

def _collect_probe_diagnostics(self):
def _read_data():
Expand Down Expand Up @@ -380,6 +385,16 @@ def _get_spans_hash(self):

self.probe_spans = _get_spans_hash(self)

def _collect_symbols(self):
raw_data = list(interfaces.library.get_data(_SYMBOLS_PATH))

for data in raw_data:
if isinstance(data, dict) and "request" in data:
content = data["request"].get("content", [])
for part in content:
if isinstance(part, dict) and "system-tests-file-path" in part:
self.symbols.append(part["system-tests-file-path"])

def get_tracer(self):
if not _Base_Debugger_Test.tracer:
_Base_Debugger_Test.tracer = {
Expand Down
Loading
Loading