Skip to content

Commit

Permalink
feat: add process discovery tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dmehala committed Feb 11, 2025
1 parent 28b2d98 commit 4789a86
Show file tree
Hide file tree
Showing 11 changed files with 242 additions and 19 deletions.
1 change: 1 addition & 0 deletions manifests/dotnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,7 @@ tests/:
Test_Parametric_OtelSpan_Set_Name: bug (APMAPI-778) # updates the operation name of the span not the resource name
Test_Parametric_Otel_Baggage: incomplete_test_app (otel baggage endpoints are not implemented)
Test_Parametric_Otel_Current_Span: incomplete_test_app (otel current span endpoint are not implemented)
test_process_discovery.py: missing_feature
test_span_events.py: missing_feature
test_span_links.py: missing_feature
test_telemetry.py:
Expand Down
1 change: 1 addition & 0 deletions manifests/golang.yml
Original file line number Diff line number Diff line change
Expand Up @@ -568,6 +568,7 @@ tests/:
Test_Otel_Env_Vars: v1.66.0
test_otel_span_with_baggage.py:
Test_Otel_Span_With_Baggage: missing_feature
test_process_discovery.py: missing_feature
test_parametric_endpoints.py:
Test_Parametric_DDSpan_Add_Link: missing_feature (add_link endpoint is not implemented)
Test_Parametric_DDSpan_Set_Resource: missing_feature (does not support setting a resource name after span creation)
Expand Down
1 change: 1 addition & 0 deletions manifests/java.yml
Original file line number Diff line number Diff line change
Expand Up @@ -1609,6 +1609,7 @@ tests/:
'*': incomplete_test_app (endpoint not implemented)
spring-boot: v1.39.0
parametric/:
test_process_discovery.py: missing_feature
test_config_consistency.py:
Test_Config_Dogstatsd: missing_feature (default hostname is inconsistent)
Test_Config_RateLimit: v1.41.1
Expand Down
1 change: 1 addition & 0 deletions manifests/nodejs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -799,6 +799,7 @@ tests/:
express4: *ref_5_26_0
express5: *ref_5_26_0
parametric/:
test_process_discovery.py: missing_feature
test_128_bit_traceids.py:
Test_128_Bit_Traceids: *ref_3_0_0
test_config_consistency.py:
Expand Down
1 change: 1 addition & 0 deletions manifests/php.yml
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,7 @@ tests/:
test_context_propagation.py:
Test_Otel_Context_Propagation_Default_Propagator_Api: incomplete_test_app (endpoint not implemented)
parametric/:
test_process_discovery.py: missing_feature
test_128_bit_traceids.py:
Test_128_Bit_Traceids: v0.84.0
test_config_consistency.py:
Expand Down
1 change: 1 addition & 0 deletions manifests/python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -771,6 +771,7 @@ tests/:
'*': incomplete_test_app (endpoint not implemented)
flask-poc: v2.19.0
parametric/:
test_process_discovery.py: missing_feature
test_128_bit_traceids.py:
Test_128_Bit_Traceids: v2.6.0
test_config_consistency.py:
Expand Down
1 change: 1 addition & 0 deletions manifests/ruby.yml
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,7 @@ tests/:
'*': incomplete_test_app (endpoint not implemented)
rails70: v2.0.0
parametric/:
test_process_discovery.py: missing_feature
test_config_consistency.py:
Test_Config_Dogstatsd: missing_feature
Test_Config_RateLimit: v2.0.0
Expand Down
74 changes: 74 additions & 0 deletions tests/parametric/test_process_discovery.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
"""
Test the instrumented process discovery mechanism feature.
"""

import pytest
import json
import msgpack
from jsonschema import validate as validation_jsonschema
from utils import features, scenarios


def find_dd_memfds(test_library, pid: int) -> list[str]:
rc, out = test_library.container_exec_run(f"find /proc/{pid}/fd -lname '/memfd:datadog-tracer-info*'")
if rc == False:
return []

memfds = out.split()
return memfds


def validate_schema(input: str) -> bool:
schema = None
with open("utils/interfaces/schemas/library/process-discovery.json", "r") as f:
schema = json.load(f)

try:
validation_jsonschema(input, schema)
return True
except Exception:
return False


def read_memfd(test_library, memfd_path: str):
rc, output = test_library.container_exec_run_raw(f"cat {memfd_path}")
if not rc:
return rc, output

return rc, msgpack.unpackb(output)


@scenarios.parametric
@features.process_discovery
class Test_ProcessDiscovery:
@pytest.mark.parametrize(
"library_env",
[
{"DD_SERVICE": "a", "DD_ENV": "test", "DD_VERSION": "0.1.0"},
{"DD_SERVICE": "b", "DD_ENV": "second-test", "DD_VERSION": "0.2.0"},
],
)
def test_metadata_content(self, test_library, library_env):
"""
Verify the content of the memfd file matches the expected metadata format and structure
"""
with test_library:
# NOTE(@dmehala): the server is started on container is always pid 1.
# That's a strong assumption :hehe:
# Maybe we should use `pidof pidof parametric-http-server` instead.
memfds = find_dd_memfds(test_library, 1)
assert len(memfds) == 1

rc, tracer_metadata = read_memfd(test_library, memfds[0])
assert rc == True
assert validate_schema(tracer_metadata) == True

assert tracer_metadata["schema_version"] == 1
assert tracer_metadata["runtime_id"]
# assert tracer_metadata["hostname"]
# TODO(@dmehala): how to get the version?
# assert tracer_metadata["tracer_version"] ==
assert tracer_metadata["tracer_language"] == test_library.lang
assert tracer_metadata["service_name"] == library_env["DD_SERVICE"]
assert tracer_metadata["service_version"] == library_env["DD_VERSION"]
assert tracer_metadata["service_env"] == library_env["DD_ENV"]
26 changes: 22 additions & 4 deletions utils/_features.py
Original file line number Diff line number Diff line change
Expand Up @@ -1724,7 +1724,9 @@ def semantic_core_validations(test_object):
return test_object

@staticmethod
def aws_sqs_span_creationcontext_propagation_via_xray_header_with_dd_trace(test_object):
def aws_sqs_span_creationcontext_propagation_via_xray_header_with_dd_trace(
test_object,
):
"""[AWS-SQS][Span Creation][Context Propagation][AWS X-Ray] with dd-trace
https://feature-parity.us1.prod.dog/#/?feature=263
Expand All @@ -1733,7 +1735,9 @@ def aws_sqs_span_creationcontext_propagation_via_xray_header_with_dd_trace(test_
return test_object

@staticmethod
def aws_sqs_span_creationcontext_propagation_via_message_attributes_with_dd_trace(test_object):
def aws_sqs_span_creationcontext_propagation_via_message_attributes_with_dd_trace(
test_object,
):
"""[AWS-SQS][Span Creation][Context Propagation][AWS Message Attributes] with dd-trace
https://feature-parity.us1.prod.dog/#/?feature=264
Expand Down Expand Up @@ -1796,7 +1800,9 @@ def rabbitmq_span_creationcontext_propagation_with_dd_trace(test_object):
return test_object

@staticmethod
def aws_sns_span_creationcontext_propagation_via_message_attributes_with_dd_trace(test_object):
def aws_sns_span_creationcontext_propagation_via_message_attributes_with_dd_trace(
test_object,
):
"""[AWS-SNS][Span Creation][Context Propagation] with dd-trace
https://feature-parity.us1.prod.dog/#/?feature=271
Expand Down Expand Up @@ -1850,7 +1856,9 @@ def host_block_list(test_object):
return test_object

@staticmethod
def aws_kinesis_span_creationcontext_propagation_via_message_attributes_with_dd_trace(test_object):
def aws_kinesis_span_creationcontext_propagation_via_message_attributes_with_dd_trace(
test_object,
):
"""[AWS-Kinesis][Span Creation][Context Propagation] with dd-trace
https://feature-parity.us1.prod.dog/#/?feature=280
Expand Down Expand Up @@ -2390,5 +2398,15 @@ def otel_propagators_api(test_object):
pytest.mark.features(feature_id=361)(test_object)
return test_object

@staticmethod
def process_discovery(test_object):
"""Process Disocvery
https://feature-parity.us1.prod.dog/#/?feature=362
RFC: <https://docs.google.com/document/d/1kcW6BLdYxXeTSUz31cBqoqfW1Jjs0IDljfKeUfIRQp4/edit?tab=t.0>
"""
pytest.mark.features(feature_id=362)(test_object)
return test_object


features = _Features()
49 changes: 49 additions & 0 deletions utils/interfaces/schemas/library/process-discovery.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"$id": "/library/process-discovery.json",
"title": "Tracer Metadata",
"description": "Metadata format used for process discovery",
"type": "object",
"properties": {
"schema_version": {
"type": "integer",
"description": "Version of the schema"
},
"runtime_id": {
"type": "string",
"description": "Runtime UUID"
},
"tracer_version": {
"type": "string",
"description": "Version of the Datadog tracer library"
},
"tracer_language": {
"type": "string",
"description": "Programming language of the tracer library"
},
"hostname": {
"type": "string",
"description": "An identifier for the machine running the process"
},
"service_name": {
"type": "string",
"description": "Name of the service being instrumented"
},
"service_env": {
"type": "string",
"description": "Environment of the service being instrumented"
},
"service_version": {
"type": "string",
"description": "Version of the service being instrumented"
}
},
"required": [
"schema_version",
"tracer_version",
"tracer_language",
"hostname"
]
}


Loading

0 comments on commit 4789a86

Please sign in to comment.