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

Khanayan123/add consistent config system tests #3745

Draft
wants to merge 42 commits into
base: main
Choose a base branch
from

Conversation

khanayan123
Copy link
Contributor

@khanayan123 khanayan123 commented Dec 25, 2024

Motivation

Adds new system tests to assert config consistency

Changes

Adds system tests for DD_TRACE_SAMPLING_RULES, DD_LOG_INEJCTION, DD_RUNTIME_METRICS_ENABLED, & DD_TRACE_128_BIT_TRACEID_LOGGING_ENABLED, DD_TRACE_AGENT_URL, as per https://docs.google.com/document/d/1kI-gTAKghfcwI7YzKhqRv2ExUstcHqADIWA4-TZ387o/edit?usp=sharing

DD_TRACE_128_BIT_TRACEID_LOGGING_ENABLED tests were tested against this PR:
DataDog/dd-trace-js#5021

@khanayan123 khanayan123 requested a review from mabdinur January 2, 2025 21:12
@khanayan123 khanayan123 marked this pull request as ready for review January 3, 2025 01:28
@khanayan123 khanayan123 requested review from a team as code owners January 3, 2025 01:28
@khanayan123 khanayan123 requested review from christophe-papazian, manuel-alvarez-alvarez, jandro996 and cataphract and removed request for a team January 3, 2025 01:28
@@ -241,8 +241,14 @@ tests/:
Test_Config_HttpServerErrorStatuses_FeatureFlagCustom: missing_feature
Test_Config_IntegrationEnabled_False: missing_feature
Test_Config_IntegrationEnabled_True: missing_feature
Test_Config_LogInjection_128Bit_TradeId_Default: missing_feature
Copy link
Contributor

@mabdinur mabdinur Jan 3, 2025

Choose a reason for hiding this comment

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

Instead of missing feature can we use

* `@incomplete_test_app` (sublass of `missing feature`): There is a deficit in the weblog/parametric apps or testing interface that prevents us from validating a feature across different applications.
. Some of these fail because the the weblog apps do not implement the new endpoint.

@DataDog DataDog deleted a comment from mabdinur Jan 3, 2025
Copy link
Collaborator

@cbeauchesne cbeauchesne left a comment

Choose a reason for hiding this comment

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

could you update your branch? it'll fix the issue on ruby

Comment on lines 178 to 179
@missing_feature(library="cpp", reason="Not implemented")
@missing_feature(library="nodejs", reason="Not implemented")
Copy link
Contributor

Choose a reason for hiding this comment

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

Should this be a "bug"?

],
)
def test_trace_sampling_rules_format_not_needed(self, test_agent, test_library):
"""Glob should work by default without specifying the format"""
Copy link
Contributor

Choose a reason for hiding this comment

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

The assertions/spans in this test look identical to test_field_case_insensitivity. S
hould we add the library_env in this test to test_field_case_insensitivity parameterized test? This way we have one test with 5 scenarios.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I could just remove it from all the tests since I believe no language currently requires the glob environment variable


def test_log_injection_enabled(self):
assert self.r.status_code == 200
pattern = rf'"dd":\{{"trace_id":"[^"]+","span_id":"\d+","service":"[^"]+","version":"[^"]+","env":"[^"]+"\}},"msg":"{self.message}"'
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we make this pattern more permissive? If there's whitespace between the entries then the pattern will fail to match. Also it requires log correlation fields to be wrapped in curly brackets and the message to printed after a comma. Also the values may not always be wrapped in quotes.

This is an example of a log message generated by the python tracer:

Python docs: https://docs.datadoghq.com/tracing/other_telemetry/connect_logs_and_traces/python/

import ddtrace
import logging

FORMAT = ('%(asctime)s %(levelname)s [%(name)s] [%(filename)s:%(lineno)d] '
          '[dd.service=%(dd.service)s dd.env=%(dd.env)s dd.version=%(dd.version)s dd.trace_id=%(dd.trace_id)s dd.span_id=%(dd.span_id)s] '
          '- %(message)s')
logging.basicConfig(format=FORMAT)

log = logging.getLogger(__name__)

with ddtrace.tracer.trace("test"):
    log.error("test")

Output:
2025-01-06 17:21:00,421 ERROR [__main__] [reproduction.py:20] [dd.service=Downloads dd.env= dd.version= dd.trace_id=677c574c000000001679fe710d0f33ba dd.span_id=10973182204132464872] - test

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think the other way to solve this issue is to have weblog apps send json formatted logs

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That would make parsing easier

@khanayan123 khanayan123 marked this pull request as draft January 7, 2025 04:12
@khanayan123 khanayan123 marked this pull request as ready for review January 9, 2025 21:04
@khanayan123 khanayan123 requested a review from mabdinur January 9, 2025 21:04
@@ -554,3 +517,19 @@ class Test_Config_RuntimeMetrics_Default:
def test_config_runtimemetrics_default(self):
data = list(interfaces.library.get_data("/dogstatsd/v2/proxy"))
assert len(data) == 0

def parse_log_injection_message(log_message):
Copy link
Collaborator

Choose a reason for hiding this comment

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

Could you document a little bit the object of this function?

Comment on lines 523 to 524
json_string = json.dumps(data)
parsed_data = json.loads(json_string)
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't get the purpose of those two line 🤔

class Test_Config_RuntimeMetrics_Enabled:
# This test verifies runtime metrics by asserting the prescene of a metric in the dogstatsd endpoint
def test_config_runtimemetrics_enabled(self):
data = list(interfaces.library.get_data("/dogstatsd/v2/proxy"))[0]
Copy link
Contributor

Choose a reason for hiding this comment

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

There might be a race condition here. At least in .NET we submit runtime metrics every 10s, so we'll need to add some sort of wait or configure the delay in a similar fashion for both the Enabled case and the Default case

@khanayan123 khanayan123 marked this pull request as draft January 10, 2025 21:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants