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

Fix mypy warning #3548

Merged
merged 1 commit into from
Nov 25, 2024
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
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ allow_no_jira_ticket_for_bugs = [
[tool.mypy]
files = ["utils/parametric", "tests/parametric"]
ignore_missing_imports = true
check_untyped_defs = true
disable_error_code = ["no-redef"]
exclude = 'utils/parametric/_library_client\.py|^(?!utils/parametric|tests/parametric).*$'
follow_imports = "skip"
Expand Down
6 changes: 3 additions & 3 deletions tests/parametric/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,17 +297,17 @@ def snapshot_context(self, token, ignores=None):
resp = self._session.get(self._url("/test/session/start?test_session_token=%s" % token))
if resp.status_code != 200:
# The test agent returns nice error messages we can forward to the user.
raise RuntimeError(resp.text.decode("utf-8"), returncode=1)
raise RuntimeError(resp.text.decode("utf-8"))
except Exception as e:
raise RuntimeError(f"Could not connect to test agent: {e}", returncode=1)
raise RuntimeError(f"Could not connect to test agent: {e}") from e
else:
yield self
# Query for the results of the test.
resp = self._session.get(
self._url("/test/session/snapshot?ignores=%s&test_session_token=%s" % (",".join(ignores), token))
)
if resp.status_code != 200:
raise RuntimeError(resp.text.decode("utf-8"), returncode=1)
raise RuntimeError(resp.text.decode("utf-8"))

def wait_for_num_traces(
self, num: int, clear: bool = False, wait_loops: int = 30, sort_by_start: bool = True
Expand Down
8 changes: 4 additions & 4 deletions tests/parametric/test_config_consistency.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@


def enable_tracing_enabled():
env1 = {}
env2 = {"DD_TRACE_ENABLED": "true"}
env1: dict = {}
env2: dict = {"DD_TRACE_ENABLED": "true"}
return parametrize("library_env", [env1, env2])


Expand Down Expand Up @@ -63,8 +63,8 @@ def test_trace_log_directory_configured_with_existing_directory(self, library_en


def set_service_version_tags():
env1 = {}
env2 = {"DD_SERVICE": "test_service", "DD_VERSION": "5.2.0"}
env1: dict = {}
env2: dict = {"DD_SERVICE": "test_service", "DD_VERSION": "5.2.0"}
return parametrize("library_env", [env1, env2])


Expand Down
2 changes: 1 addition & 1 deletion tests/parametric/test_headers_baggage.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def test_baggage_inject_header_D004(self, test_library):
headers = test_library.dd_inject_headers(span.span_id)

assert any("baggage" in header for header in headers)
baggage_list = next((header for header in headers if header[0] == "baggage"), [])
baggage_list: list = next((header for header in headers if header[0] == "baggage"), [])
baggage_items = baggage_list[1].split(",") # baggage items may not be in order
assert len(baggage_items) == 5
assert "foo=bar" in baggage_items
Expand Down
1 change: 1 addition & 0 deletions tests/parametric/test_library_tracestats.py
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,7 @@ def test_relative_error_TS008(self, library_env, test_agent, test_library):
durations: List[int] = []
for trace in traces:
span = find_root_span(trace)
assert span is not None
durations.append(span["duration"])

requests = test_agent.v06_stats_requests()
Expand Down
13 changes: 12 additions & 1 deletion tests/parametric/test_otel_api_interoperability.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,9 @@ def test_otel_start_after_datadog_span(self, test_agent, test_library):

root = find_root_span(trace)
span = find_span(trace, otel_span.span_id)
assert root is not None
assert span is not None
assert span.get("resource") == "otel_span"

assert span.get("parent_id") == root.get("span_id")

def test_has_ended(self, test_agent, test_library):
Expand Down Expand Up @@ -116,9 +117,11 @@ def test_datadog_start_after_otel_span(self, test_agent, test_library):
assert len(trace) == 2

root = find_root_span(trace)
assert root is not None
assert root.get("resource") == "otel_span"

span = find_span(trace, dd_span.span_id)
assert span is not None
assert span.get("parent_id") == root.get("span_id")

def test_set_update_remove_meta(self, test_agent, test_library):
Expand Down Expand Up @@ -262,6 +265,8 @@ def test_concurrent_traces_in_order(self, test_agent, test_library):

root1 = find_root_span(trace1)
root2 = find_root_span(trace2)
assert root1 is not None
assert root2 is not None
assert root1["resource"] == "otel_root"
assert root2["name"] == "dd_root"

Expand Down Expand Up @@ -308,6 +313,8 @@ def test_concurrent_traces_nested_otel_root(self, test_agent, test_library):

root1 = find_root_span(trace1)
root2 = find_root_span(trace2)
assert root1 is not None
assert root2 is not None
assert root1["resource"] == "otel_root"
assert root2["name"] == "dd_root"

Expand Down Expand Up @@ -354,6 +361,8 @@ def test_concurrent_traces_nested_dd_root(self, test_agent, test_library):

root1 = find_root_span(trace1)
root2 = find_root_span(trace2)
assert root1 is not None
assert root2 is not None
assert root1["resource"] == "otel_root"
assert root2["name"] == "dd_root"

Expand Down Expand Up @@ -452,6 +461,7 @@ def test_set_attribute_from_otel(self, test_agent, test_library):
assert len(trace) == 1

root = find_root_span(trace)
assert root is not None
assert root["metrics"]["int"] == 1
assert root["metrics"]["float"] == 1.0
assert root["meta"]["bool"] == "true"
Expand Down Expand Up @@ -491,6 +501,7 @@ def test_set_attribute_from_datadog(self, test_agent, test_library):
assert len(trace) == 1

root = find_root_span(trace)
assert root is not None
assert root["metrics"]["int"] == 1
assert root["metrics"]["float"] == 1.0
assert root["meta"]["bool"] == "true"
Expand Down
27 changes: 15 additions & 12 deletions tests/parametric/test_telemetry.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import copy
import json
import time
from typing import Any
import uuid

import pytest
Expand Down Expand Up @@ -150,18 +151,20 @@ def test_library_settings(self, library_env, test_agent, test_library):
configuration_by_name = {item["name"]: item for item in configuration}

# # Check that the tags name match the expected value
assert configuration_by_name.get("DD_ENV").get("value") == "dev"
assert configuration_by_name.get("DD_SERVICE").get("value") == "service_test"
assert configuration_by_name.get("DD_VERSION").get("value") == "5.2.0"
assert configuration_by_name.get("DD_TRACE_RATE_LIMIT").get("value") == "10"
assert configuration_by_name.get("DD_ENV", {}).get("value") == "dev"
assert configuration_by_name.get("DD_SERVICE", {}).get("value") == "service_test"
assert configuration_by_name.get("DD_VERSION", {}).get("value") == "5.2.0"
assert configuration_by_name.get("DD_TRACE_RATE_LIMIT", {}).get("value") == "10"
assert (
configuration_by_name.get("DD_TRACE_HEADER_TAGS").get("value") == "User-Agent:my-user-agent,Content-Type."
configuration_by_name.get("DD_TRACE_HEADER_TAGS", {}).get("value")
== "User-Agent:my-user-agent,Content-Type."
)
assert configuration_by_name.get("DD_TRACE_ENABLED").get("value") == True
assert configuration_by_name.get("DD_TRACE_ENABLED", {}).get("value") is True
assert (
configuration_by_name.get("DD_TRACE_OBFUSCATION_QUERY_STRING_REGEXP").get("value") == r"\d{3}-\d{2}-\d{4}"
configuration_by_name.get("DD_TRACE_OBFUSCATION_QUERY_STRING_REGEXP", {}).get("value")
== r"\d{3}-\d{2}-\d{4}"
)
assert configuration_by_name.get("DD_TRACE_CLIENT_IP_HEADER").get("value") == "random-header-name"
assert configuration_by_name.get("DD_TRACE_CLIENT_IP_HEADER", {}).get("value") == "random-header-name"

@pytest.mark.parametrize(
"library_env",
Expand All @@ -184,11 +187,11 @@ def test_library_settings_2(self, library_env, test_agent, test_library):
configuration = event["payload"]["configuration"]
configuration_by_name = {item["name"]: item for item in configuration}

assert configuration_by_name.get("DD_TRACE_LOG_DIRECTORY").get("value") == "/some/temporary/directory"
assert configuration_by_name.get("DD_TRACE_HTTP_CLIENT_ERROR_STATUSES").get("value") == "200-250"
assert configuration_by_name.get("DD_TRACE_HTTP_SERVER_ERROR_STATUSES").get("value") == "250-200"
assert configuration_by_name.get("DD_TRACE_LOG_DIRECTORY", {}).get("value") == "/some/temporary/directory"
assert configuration_by_name.get("DD_TRACE_HTTP_CLIENT_ERROR_STATUSES", {}).get("value") == "200-250"
assert configuration_by_name.get("DD_TRACE_HTTP_SERVER_ERROR_STATUSES", {}).get("value") == "250-200"
assert (
configuration_by_name.get("DD_TRACE_HTTP_CLIENT_TAG_QUERY_STRING").get("value") == False
configuration_by_name.get("DD_TRACE_HTTP_CLIENT_TAG_QUERY_STRING", {}).get("value") is False
) # No telemetry received, tested with Python and Java(also tried: DD_HTTP_CLIENT_TAG_QUERY_STRING)


Expand Down
2 changes: 1 addition & 1 deletion tests/parametric/test_tracer_flare.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ def _set_log_level(test_agent, log_level: str) -> str:
return cfg_id


def _clear_log_level(test_agent, cfg_id: int) -> None:
def _clear_log_level(test_agent, cfg_id: str) -> None:
"""Helper to clear a previously set "flare-log-level" config from RC."""
test_agent.set_remote_config(path=f"datadog/2/AGENT_CONFIG/{cfg_id}/config", payload={})
test_agent.wait_for_rc_apply_state("AGENT_CONFIG", state=2, clear=True, post_only=True)
Expand Down
2 changes: 1 addition & 1 deletion utils/parametric/spec/tracecontext.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ class Tracestate:
def __init__(self, *args, **kwds):
if len(args) == 1 and not kwds:
if isinstance(args[0], str):
self._traits = OrderedDict()
self._traits: OrderedDict = OrderedDict()
self.from_string(args[0])
return
if isinstance(args[0], Tracestate):
Expand Down