-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
242 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
] | ||
} | ||
|
||
|
Oops, something went wrong.