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

Extend mypy scope #4002

Merged
merged 3 commits into from
Feb 5, 2025
Merged
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
3 changes: 0 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ exclude = [
"tests/fuzzer/.*",
"tests/test_the_test/.*",
"tests/test_telemetry.py",
"tests/test_profiling.py",
"tests/appsec/.*",
"tests/debugger/.*",
"tests/auto_inject/.*",
Expand All @@ -69,7 +68,6 @@ exclude = [
"tests/k8s_lib_injection/test_k8s_init_image_validator.py",
"utils/_context/_scenarios/auto_injection.py",
"utils/_context/_scenarios/k8s_lib_injection.py",
"utils/_context/containers.py",
"utils/_context/core.py",
"utils/_context/virtual_machines.py",
"utils/scripts/decode-rc.py",
Expand All @@ -78,7 +76,6 @@ exclude = [
"utils/onboarding/.*",
"utils/otel_validators/validator_trace.py",
"utils/proxy/_deserializer.py",
"utils/scripts/compute_impacted_scenario.py",
"utils/scripts/merge_gitlab_aws_pipelines.py",
"utils/virtual_machine/.*",
]
Expand Down
4 changes: 3 additions & 1 deletion tests/test_profiling.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@
class Test_Profile:
"""Basic testing of profiling"""

_is_set_up = False # used to do the setup only once

@staticmethod
def _common_setup():
if hasattr(Test_Profile, "_is_set_up"):
if Test_Profile._is_set_up:
return

Test_Profile._is_set_up = True
Expand Down
2 changes: 0 additions & 2 deletions utils/_context/_scenarios/endtoend.py
Original file line number Diff line number Diff line change
Expand Up @@ -402,8 +402,6 @@ def configure(self, config):
interfaces.library_dotnet_managed.configure(self.host_log_folder, self.replay)

for container in self.buddies:
# a little bit of python wizzardry to solve circular import
container.interface = getattr(interfaces, container.name)
container.interface.configure(self.host_log_folder, self.replay)

library = self.weblog_container.image.labels["system-tests-library"]
Expand Down
35 changes: 24 additions & 11 deletions utils/_context/containers.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from utils.tools import logger
from utils import interfaces
from utils.k8s_lib_injection.k8s_weblog import K8sWeblog
from utils.interfaces._library.core import LibraryInterfaceValidator

# fake key of length 32
_FAKE_DD_API_KEY = "0123456789abcdef0123456789abcdef"
Expand Down Expand Up @@ -100,13 +101,13 @@ def __init__(
# None: container did not tried to start yet, or hasn't be started for another reason
# False: container is not healthy
# True: container is healthy
self.healthy = None
self.healthy: bool | None = None

self.environment = environment or {}
self.kwargs = kwargs
self.depends_on: list[TestedContainer] = []
self._starting_lock = RLock()
self._starting_thread = None
self._starting_thread: Thread | None = None
self.stdout_interface = stdout_interface

def get_image_list(self, library: str, weblog: str) -> list[str]: # noqa: ARG002
Expand Down Expand Up @@ -444,7 +445,7 @@ def __init__(self, image_name: str, *, local_image_only: bool):
# local_image_only: boolean
# True if the image is only available locally and can't be loaded from any hub

self.env = None
self.env: dict[str, str] | None = None
self.labels: dict[str, str] = {}
self.name = image_name
self.local_image_only = local_image_only
Expand Down Expand Up @@ -557,7 +558,7 @@ def __init__(self, host_log_folder, *, use_proxy=True, environment=None) -> None
local_image_only=True,
)

self.agent_version = ""
self.agent_version: str | None = ""

def configure(self, replay):
super().configure(replay)
Expand Down Expand Up @@ -611,12 +612,17 @@ def __init__(self, name, image_name, host_log_folder, host_port, trace_agent_por
},
)

self.interface = None
_set_aws_auth_environment(self)

@property
def interface(self) -> LibraryInterfaceValidator:
result = getattr(interfaces, self.name)
assert result is not None, "Interface is not set"
return result


class WeblogContainer(TestedContainer):
appsec_rules_file: str
appsec_rules_file: str | None
_dd_rc_tuf_root: dict = {
"signed": {
"_type": "root",
Expand Down Expand Up @@ -728,7 +734,7 @@ def __init__(
base_environment["DD_TRACE_AGENT_PORT"] = self.trace_agent_port
else:
base_environment["DD_AGENT_HOST"] = "agent"
base_environment["DD_TRACE_AGENT_PORT"] = AgentContainer.apm_receiver_port
base_environment["DD_TRACE_AGENT_PORT"] = str(AgentContainer.apm_receiver_port)

# overwrite values with those set in the scenario
environment = base_environment | (environment or {})
Expand Down Expand Up @@ -759,7 +765,7 @@ def __init__(
self.additional_trace_header_tags = additional_trace_header_tags

self.weblog_variant = ""
self._library: LibraryVersion = None
self._library: LibraryVersion | None = None

@property
def trace_agent_port(self):
Expand All @@ -779,7 +785,7 @@ def _get_image_list_from_dockerfile(dockerfile) -> list[str]:

def get_image_list(self, library: str | None, weblog: str | None) -> list[str]:
"""Parse the Dockerfile and extract all images reference in a FROM section"""
result = []
result: list[str] = []

if not library or not weblog:
return result
Expand Down Expand Up @@ -822,7 +828,12 @@ def configure(self, replay):
if len(self.additional_trace_header_tags) != 0:
self.environment["DD_TRACE_HEADER_TAGS"] += f',{",".join(self.additional_trace_header_tags)}'

self.appsec_rules_file = (self.image.env | self.environment).get("DD_APPSEC_RULES", None)
if "DD_APPSEC_RULES" in self.environment:
self.appsec_rules_file = self.environment["DD_APPSEC_RULES"]
elif self.image.env is not None and "DD_APPSEC_RULES" in self.environment:
self.appsec_rules_file = self.image.env["DD_APPSEC_RULES"]
else:
self.appsec_rules_file = None

# Workaround: Once the dd-trace-go fix is merged that avoids a go panic for
# DD_TRACE_PROPAGATION_EXTRACT_FIRST=true when context propagation fails,
Expand Down Expand Up @@ -878,10 +889,12 @@ def post_start(self):

@property
def library(self) -> LibraryVersion:
assert self._library is not None, "Library version is not set"
return self._library

@property
def uds_socket(self):
assert self.image.env is not None, "No env set"
return self.image.env.get("DD_APM_RECEIVER_SOCKET", None)

@property
Expand Down Expand Up @@ -1214,7 +1227,7 @@ def __init__(self, host_log_folder) -> None:

def get_env(self, env_var):
"""Get env variables from the container"""
env = self.image.env | self.environment
env = (self.image.env or {}) | self.environment
return env.get(env_var)


Expand Down
4 changes: 2 additions & 2 deletions utils/scripts/compute_impacted_scenario.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
class Result:
def __init__(self) -> None:
self.scenarios = {"DEFAULT"} # always run the default scenario
self.scenarios_groups = set()
self.scenarios_groups: set[str] = set()

def add_scenario(self, scenario: str) -> None:
if scenario == "EndToEndScenario":
Expand All @@ -20,7 +20,7 @@ def add_scenario(self, scenario: str) -> None:
def add_scenario_group(self, scenario_group: str) -> None:
self.scenarios_groups.add(scenario_group)

def add_scenarios(self, scenarios: set[str]) -> None:
def add_scenarios(self, scenarios: set[str] | list[str]) -> None:
for scenario in scenarios:
self.add_scenario(scenario)

Expand Down
Loading