Skip to content

Commit 809f0ee

Browse files
authored
Safely extractt service tag (#511)
* Safely extractt service tag * Add tests
1 parent 90e181b commit 809f0ee

File tree

2 files changed

+23
-3
lines changed

2 files changed

+23
-3
lines changed

aws/logs_monitoring/parsing.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -220,9 +220,8 @@ def get_service_from_tags(metadata):
220220
# Get service from dd_custom_tags if it exists
221221
tagsplit = metadata[DD_CUSTOM_TAGS].split(",")
222222
for tag in tagsplit:
223-
tag_name, tag_value = tag.split(":")
224-
if tag_name == "service":
225-
return tag_value
223+
if tag.startswith("service:"):
224+
return tag[8:]
226225

227226
# Default service to source value
228227
return metadata[DD_SOURCE]

aws/logs_monitoring/tests/test_parsing.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@
2020
parse_event_source,
2121
separate_security_hub_findings,
2222
parse_aws_waf_logs,
23+
get_service_from_tags,
24+
)
25+
from settings import (
26+
DD_CUSTOM_TAGS,
27+
DD_SOURCE,
2328
)
2429

2530
env_patch.stop()
@@ -718,5 +723,21 @@ def test_awslogs_handler_rds_postgresql(self):
718723
)
719724

720725

726+
class TestGetServiceFromTags(unittest.TestCase):
727+
def test_get_service_from_tags(self):
728+
metadata = {
729+
DD_SOURCE: "ecs",
730+
DD_CUSTOM_TAGS: "env:dev,tag,stack:aws:ecs,service:web,version:v1",
731+
}
732+
self.assertEqual(get_service_from_tags(metadata), "web")
733+
734+
def test_get_service_from_tags_default_to_source(self):
735+
metadata = {
736+
DD_SOURCE: "ecs",
737+
DD_CUSTOM_TAGS: "env:dev,tag,stack:aws:ecs,version:v1",
738+
}
739+
self.assertEqual(get_service_from_tags(metadata), "ecs")
740+
741+
721742
if __name__ == "__main__":
722743
unittest.main()

0 commit comments

Comments
 (0)