Skip to content
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
@@ -1,12 +1,13 @@
import os
import signal
import sys
import types

from django.http import HttpResponse
from django.http import HttpRequest, HttpResponse
from django.conf.urls import url


def handle_sigterm(signo, sf):
def handle_sigterm(signo: int, sf: types.FrameType | None) -> None:
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Keep Python 2.7 django app annotation-free

This module now adds runtime type annotations (for example def handle_sigterm(signo: int, ...)) even though lib-injection/build/docker/python/dd-lib-python-init-test-django-27/Dockerfile runs it with FROM python:2.7. Python 2.7 cannot parse function annotations, so the Django settings module will fail to import and this auto-injection variant will fail to start before any tests execute.

Useful? React with 👍 / 👎.

sys.exit(0)


Expand All @@ -20,7 +21,7 @@ def handle_sigterm(signo, sf):
ALLOWED_HOSTS = ["*"]


def index(request):
def index(request: HttpRequest):
return HttpResponse("test")


Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import os
import signal
import sys
import types

from django.core.wsgi import get_wsgi_application
from django.http import HttpResponse
from django.http import HttpRequest, HttpResponse
from django.urls import path


def handle_sigterm(signo, sf):
def handle_sigterm(signo: int, sf: types.FrameType | None) -> None:
sys.exit(0)


Expand All @@ -20,7 +21,7 @@ def handle_sigterm(signo, sf):
ALLOWED_HOSTS = ["*"]


def index(request):
def index(request: HttpRequest):
return HttpResponse("test")


Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import os
import signal
import sys
import types

from django.core.wsgi import get_wsgi_application
from django.http import HttpResponse
from django.http import HttpRequest, HttpResponse
from django.urls import path


def handle_sigterm(signo, sf):
def handle_sigterm(signo: int, sf: types.FrameType | None) -> None:
sys.exit(0)


Expand All @@ -20,7 +21,7 @@ def handle_sigterm(signo, sf):
ALLOWED_HOSTS = ["*"]


def index(request):
def index(request: HttpRequest):
return HttpResponse("test")


Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import os
import signal
import sys
import types

from django.http import HttpResponse
from django.http import HttpRequest, HttpResponse
from django.urls import path


def handle_sigterm(signo, sf):
def handle_sigterm(signo: int, sf: types.FrameType | None) -> None:
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P1 Badge Replace PEP 604 unions in Python 3.9 weblog apps

The new annotation types.FrameType | None requires Python 3.10+, but this file (and dd-lib-python-init-test-protobuf-old/django_app.py) is executed in images based on Python 3.9 (.../dd-lib-python-init-test-django-preinstalled/Dockerfile and .../dd-lib-python-init-test-protobuf-old/Dockerfile). On those variants this introduces a syntax error at import time, so the weblog process cannot boot.

Useful? React with 👍 / 👎.

sys.exit(0)


Expand All @@ -20,7 +21,7 @@ def handle_sigterm(signo, sf):
ALLOWED_HOSTS = ["*"]


def index(request):
def index(request: HttpRequest):
import ddtrace

if ddtrace.__version__ != "1.12.0":
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import os
import signal
import sys
import types

from django.http import HttpResponse
from django.http import HttpRequest, HttpResponse
from django.urls import path


def handle_sigterm(signo, sf):
def handle_sigterm(signo: int, sf: types.FrameType | None) -> None:
sys.exit(0)


Expand All @@ -20,7 +21,7 @@ def handle_sigterm(signo, sf):
ALLOWED_HOSTS = ["*"]


def index(request):
def index(request: HttpRequest):
return HttpResponse("test")


Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import os
import signal
import sys
import types

from django.core.asgi import get_asgi_application
from django.http import HttpResponse
from django.http import HttpRequest, HttpResponse
from django.urls import path


def handle_sigterm(signo, sf):
def handle_sigterm(signo: int, sf: types.FrameType | None) -> None:
sys.exit(0)


Expand All @@ -21,7 +22,7 @@ def handle_sigterm(signo, sf):
ALLOWED_HOSTS = ["*"]


def index(request):
def index(request: HttpRequest):
return HttpResponse("test")


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@
import signal
import sys
import time
import types

from django.http import HttpResponse
from django.http import HttpRequest, HttpResponse
from django.urls import path


def handle_sigterm(signo, sf):
def handle_sigterm(signo: int, sf: types.FrameType | None) -> None:
sys.exit(0)


Expand All @@ -22,15 +23,15 @@ def handle_sigterm(signo, sf):
ALLOWED_HOSTS = ["*"]


def index(request):
def index(request: HttpRequest):
return HttpResponse("test")


def crashme(request):
def crashme(request: HttpRequest):
ctypes.string_at(0)


def fork_and_crash(request):
def fork_and_crash(request: HttpRequest):
pid = os.fork()
if pid > 0:
# Parent process
Expand All @@ -43,7 +44,7 @@ def fork_and_crash(request):
return HttpResponse("Nobody should see this")


def child_pids(request):
def child_pids(request: HttpRequest):
current_pid = os.getpid()
child_pids = []

Expand Down Expand Up @@ -71,7 +72,7 @@ def child_pids(request):
return HttpResponse(f"Error: {e!s}", status=500, content_type="text/plain")


def zombies(request):
def zombies(request: HttpRequest):
zombie_processes = []

# Iterate over all directories in /proc to look for PIDs
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import os
import signal
import sys
import types

from django.http import HttpResponse
from django.http import HttpRequest, HttpResponse
from django.urls import path

import addressbook_pb2


def handle_sigterm(signo, sf):
def handle_sigterm(signo: int, sf: types.FrameType | None) -> None:
sys.exit(0)


Expand All @@ -22,7 +23,7 @@ def handle_sigterm(signo, sf):
ALLOWED_HOSTS = ["*"]


def index(request):
def index(request: HttpRequest):
# Do some stuff with the protobuf
person = addressbook_pb2.Person()
person.id = 1234
Expand Down
11 changes: 0 additions & 11 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,6 @@ ignore = [
# 2. on each line, comment with the rule name, and a comment, either TODO, or a reason why the rule is ignored

"lib-injection/build/docker/python/*" = [
"ANN001", # missing-type-function-argument
"ANN201", # missing-return-type-undocumented-public-function
"ARG001", # unused-function-argument
"INP001", # implicit-namespace-package
Expand Down Expand Up @@ -203,8 +202,6 @@ ignore = [
"SIM108", # if-else-block-instead-of-if-exp: ternary operator nay be harder to read on long statements
]
"tests/auto_inject/*" = [
"ANN001", # missing-type-function-argument: TODO
"RUF059", # unused-unpacked-variable: TODO
"SLF001", # private-member-access: TODO
]
"tests/fuzzer/*" = [
Expand All @@ -224,11 +221,9 @@ ignore = [
"S605", # start-process-with-a-shell: test the test needs to run shell commands
]
"utils/_context/_scenarios/auto_injection.py" = [
"ANN001", # missing-type-function-argument: TODO
"PLC0415", # import-outside-top-level TODO
]
"utils/{_context/_scenarios/docker_ssi.py,docker_ssi/docker_ssi_matrix_utils.py}" = [
"ANN001", # missing-type-function-argument: TODO
"E501", # line-too-long: TODO
"T201", # print: TODO
"RET504", # unnecessary-assign: TODO
Expand All @@ -242,11 +237,6 @@ ignore = [
"ANN205" # missing-return-type-static-method: obvious decorators
]
"utils/build/*" = ["ALL"] # mostly python weblog code. it may be a good idea to enable rules here
"utils/docker_ssi/*" = [
"ANN001", # missing-type-function-argument: TODO
"ANN201", # missing-return-type-undocumented-public-function: TODO
"ANN205", # issing-return-type-static-method: TODO
]

"utils/{k8s_lib_injection/*,_context/_scenarios/k8s_lib_injection.py}" = [
"ANN003", # missing-type-kwargs: TODO
Expand Down Expand Up @@ -288,7 +278,6 @@ ignore = [
"UP017", # datetime-timezone-utc: TODO
]
"utils/scripts/ssi_wizards/aws_onboarding_wizard_utils.py" = [
"ANN001", # missing-type-function-argument: TODO
"PLR2004", # magic-value-comparison: TODO
]

Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ setuptools==75.8.0
shellcheck-py==0.11.0.1
types-aiofiles==24.1.0.20241221
types-mock==5.2.0.20250924
types-paramiko==4.0.0.20250822
types-protobuf==5.29.1.20241207
types-python-dateutil==2.9.0.20241206
types-PyYAML==6.0.12.20241230
Expand Down
4 changes: 2 additions & 2 deletions tests/auto_inject/test_auto_inject_chaos.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@


class BaseAutoInjectChaos(base.AutoInjectBaseTest):
def _test_removing_things(self, virtual_machine: _VirtualMachine, evil_command):
def _test_removing_things(self, virtual_machine: _VirtualMachine, evil_command: str):
"""Test break the installation and restore it.
After breaking the installation, the app should be still working (but no sending traces to the backend).
After breaking the installation, we can restart the app
Expand Down Expand Up @@ -64,7 +64,7 @@ def _test_removing_things(self, virtual_machine: _VirtualMachine, evil_command):
logger.info("Restoring installation using the command:: ")
apm_inject_restore = f"{prefix_env} {apm_inject_restore}"
logger.info(apm_inject_restore)
_, stdout, stderr = virtual_machine.get_ssh_connection().exec_command(apm_inject_restore)
_, stdout, _stderr = virtual_machine.get_ssh_connection().exec_command(apm_inject_restore)
stdout.channel.set_combine_stderr(True)

# Read the output line by line
Expand Down
3 changes: 2 additions & 1 deletion tests/auto_inject/test_blocklist_auto_inject.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import uuid
import paramiko
from scp import SCPClient

from utils import scenarios, context, features, irrelevant, logger
Expand All @@ -8,7 +9,7 @@
class _AutoInjectWorkloadSelectionBaseTest:
"""Base class to test workload selection policies on auto instrumentation."""

def _execute_remote_command(self, ssh_client, command):
def _execute_remote_command(self, ssh_client: paramiko.SSHClient, command: str):
"""Execute remote command and get remote log file from the vm. You can use this method using env variables or using injection config file"""

unique_log_name = f"host_injection_{uuid.uuid4()}.log"
Expand Down
Loading
Loading