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

Ensure git commit sha and repo url are sent to remote config and instrumentation-telemetry #3212

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
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
15 changes: 15 additions & 0 deletions tests/parametric/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,21 @@ def wait_for_telemetry_event(self, event_name: str, clear: bool = False, wait_lo
time.sleep(0.01)
raise AssertionError("Telemetry event %r not found" % event_name)

def wait_for_rc_request(self, wait_loops: int = 1000):
"""Wait for the first RemoteConfig request to be received by the test agent."""
rc_reqs = []
for i in range(wait_loops):
try:
rc_reqs = self.rc_requests()
except requests.exceptions.RequestException:
pass
else:
if rc_reqs:
return rc_reqs[0]
time.sleep(0.01)
total_wait_time = wait_loops * 0.01
raise AssertionError(f"No RemoteConfig request found after waiting for {total_wait_time} seconds")

def wait_for_rc_apply_state(
self, product: str, state: remoteconfig.APPLY_STATUS, clear: bool = False, wait_loops: int = 100
):
Expand Down
51 changes: 50 additions & 1 deletion tests/parametric/test_tracer.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from utils.parametric.spec.trace import find_span
from utils.parametric.spec.trace import find_first_span_in_trace_payload
from utils.parametric.spec.trace import find_root_span
from utils import missing_feature, context, rfc, scenarios, features
from utils import missing_feature, context, rfc, scenarios, features, bug

from .conftest import _TestAgentAPI
from .conftest import APMLibrary
Expand Down Expand Up @@ -155,6 +155,55 @@ def test_tracer_repository_url_strip_credentials(

assert first_span["meta"]["_dd.git.repository_url"] == library_env["expected_repo_url"]

@pytest.mark.parametrize(
"library_env",
[
{
"DD_GIT_COMMIT_SHA": "a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6q7r8s9t0",
"DD_GIT_REPOSITORY_URL": "https://github.com/Datadog/system-tests",
}
],
)
@bug(library="golang", reason="DEBUG-2977")
@bug(library="java", reason="DEBUG-2978")
def test_git_metadata_is_sent_to_instrumentation_telemetry(self, library_env, test_agent, test_library):

event = test_agent.wait_for_telemetry_event("app-started", wait_loops=400)
configuration = event["payload"]["configuration"]
configuration_by_name = {item["name"]: item for item in configuration}

assert configuration_by_name.get("DD_GIT_COMMIT_SHA").get("value") == "a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6q7r8s9t0"
assert configuration_by_name.get("DD_GIT_REPOSITORY_URL").get("value") == "https://github.com/Datadog/system-tests"

@pytest.mark.parametrize(
"library_env",
[
{
"DD_GIT_COMMIT_SHA": "a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6q7r8s9t0",
"DD_GIT_REPOSITORY_URL": "https://github.com/Datadog/system-tests",
"DD_REMOTE_CONFIG_POLL_INTERVAL_SECONDS": "0.2",
}
],
)
@bug(library="golang", reason="DEBUG-2975")
@bug(library="php", reason="DEBUG-2976")
def test_git_metadata_is_sent_to_remote_config(self, library_env, test_agent, test_library):
"""
Test that git commit SHA and repository URL are included in the remote config request when set via the DD_GIT_COMMIT_SHA and DD_GIT_REPOSITORY_URL environment variables
At the moment, Dynamic Instrumentation is the only product that relies on this behavior, though that may change in the future
"""

rc_request = test_agent.wait_for_rc_request()
tags_in_rc_request = rc_request["body"]["client"]["client_tracer"]["tags"]

required_tags = [
"git.commit.sha:a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6q7r8s9t0",
"git.repository_url:https://github.com/Datadog/system-tests",
]

for tag in required_tags:
assert any(tag in rc_tag for rc_tag in tags_in_rc_request), f"Missing tag: {tag}"


@scenarios.parametric
class Test_TracerUniversalServiceTagging:
Expand Down
Loading