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

[Tracing] Refactor DD_TAGS test cases for clarity #3954

Merged
Merged
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
52 changes: 22 additions & 30 deletions tests/parametric/test_config_consistency.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,30 +281,36 @@ def test_setting_trace_rate_limit(self, library_env, test_agent, test_library):
), "Expected at least one trace to be rate-limited with sampling priority -1."


def tag_scenarios():
env1: dict = {"DD_TAGS": "key1:value1,key2:value2"}
env2: dict = {"DD_TAGS": "key1:value1 key2:value2"}
env3: dict = {"DD_TAGS": "env:test aKey:aVal bKey:bVal cKey:"}
env4: dict = {"DD_TAGS": "env:test,aKey:aVal,bKey:bVal,cKey:"}
env5: dict = {"DD_TAGS": "env:test,aKey:aVal bKey:bVal cKey:"}
env6: dict = {"DD_TAGS": "env:test bKey :bVal dKey: dVal cKey:"}
env7: dict = {"DD_TAGS": "env :test, aKey : aVal bKey:bVal cKey:"}
env8: dict = {"DD_TAGS": "env:keyWithA:Semicolon bKey:bVal cKey"}
env9: dict = {"DD_TAGS": "env:keyWith: , , Lots:Of:Semicolons "}
env10: dict = {"DD_TAGS": "a:b,c,d"}
env11: dict = {"DD_TAGS": "a,1"}
env12: dict = {"DD_TAGS": "a:b:c:d"}
return parametrize("library_env", [env1, env2, env3, env4, env5, env6, env7, env8, env9, env10, env11, env12])
tag_scenarios: dict = {
"key1:value1,key2:value2": [("key1", "value1"), ("key2", "value2")],
"key1:value1 key2:value2": [("key1", "value1"), ("key2", "value2")],
"env:test aKey:aVal bKey:bVal cKey:": [("env", "test"), ("aKey", "aVal"), ("bKey", "bVal"), ("cKey", "")],
"env:test,aKey:aVal,bKey:bVal,cKey:": [("env", "test"), ("aKey", "aVal"), ("bKey", "bVal"), ("cKey", "")],
"env:test,aKey:aVal bKey:bVal cKey:": [("env", "test"), ("aKey", "aVal bKey:bVal cKey:")],
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 also add some test scenarios for keys/values as numbers, booleans, special characters, and other edge cases?

Suggested change
"env:test,aKey:aVal bKey:bVal cKey:": [("env", "test"), ("aKey", "aVal bKey:bVal cKey:")],
"env:test,aKey:aVal bKey:bVal cKey:": [("env", "test"), ("aKey", "aVal bKey:bVal cKey:")],
"numKey:1,1:numVal,boolKey:true,true:boolVal": [("numKey", "1"), ("1", "numVal"), ("boolKey", "true"), ("true", "boolVal") ],
"": [],
"sp%key:value,key:sp#value": [], # I'm not sure what belongs here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, but I would prefer to do this in a separate PR. Some of the existing test cases are confusing to me, so I want to revisit the existing test cases and add to them as we build consensus

Copy link
Contributor

Choose a reason for hiding this comment

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

SGTM

"env:test bKey :bVal dKey: dVal cKey:": [
("env", "test"),
("bKey", ""),
("dKey", ""),
("dVal", ""),
("cKey", ""),
],
"env :test, aKey : aVal bKey:bVal cKey:": [("env", "test"), ("aKey", "aVal bKey:bVal cKey:")],
"env:keyWithA:Semicolon bKey:bVal cKey": [("env", "keyWithA:Semicolon"), ("bKey", "bVal"), ("cKey", "")],
"env:keyWith: , , Lots:Of:Semicolons ": [("env", "keyWith:"), ("Lots", "Of:Semicolons")],
"a:b,c,d": [("a", "b"), ("c", ""), ("d", "")],
"a,1": [("a", ""), ("1", "")],
"a:b:c:d": [("a", "b:c:d")],
}


@scenarios.parametric
@features.tracing_configuration_consistency
class Test_Config_Tags:
@tag_scenarios()
@parametrize("library_env", [{"DD_TAGS": key} for key in tag_scenarios.keys()])
def test_comma_space_tag_separation(self, library_env, test_agent, test_library):
expected_local_tags = []
if "DD_TAGS" in library_env:
expected_local_tags = _parse_dd_tags(library_env["DD_TAGS"])
expected_local_tags = tag_scenarios[library_env["DD_TAGS"]]
with test_library:
with test_library.dd_start_span(name="sample_span"):
pass
Expand Down Expand Up @@ -336,20 +342,6 @@ def test_dd_service_override(self, library_env, test_agent, test_library):
assert span["meta"]["version"] == "5.2.0"


def _parse_dd_tags(tags):
result = []
key_value_pairs = tags.split(",") if "," in tags else tags.split() # First try to split by comma, then by space
for pair in key_value_pairs:
if ":" in pair:
key, value = pair.split(":", 1)
else:
key, value = pair, ""
key, value = key.strip(), value.strip()
if key:
result.append((key, value))
return result


@scenarios.parametric
@features.tracing_configuration_consistency
class Test_Config_Dogstatsd:
Expand Down
Loading