Skip to content

Commit 75be9d0

Browse files
authored
feat(aws): AWSX-1891 Migrate route53 to logs-backend (#978)
Signed-off-by: Vincent Boutour <[email protected]>
1 parent 81515f3 commit 75be9d0

File tree

7 files changed

+6
-234
lines changed

7 files changed

+6
-234
lines changed

aws/logs_monitoring/steps/enrichment.py

Lines changed: 3 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,10 @@
1-
import logging
21
import json
2+
import logging
33
import os
44
import re
5-
from settings import (
6-
DD_SOURCE,
7-
DD_SERVICE,
8-
DD_HOST,
9-
DD_CUSTOM_TAGS,
10-
)
5+
116
from enhanced_lambda_metrics import parse_lambda_tags_from_arn
7+
from settings import DD_CUSTOM_TAGS, DD_HOST, DD_SERVICE, DD_SOURCE
128
from steps.enums import AwsEventSource
139

1410
HOST_IDENTITY_REGEXP = re.compile(
@@ -30,7 +26,6 @@ def enrich(events, cache_layer):
3026
extract_ddtags_from_message(event)
3127
extract_host_from_cloudtrails(event)
3228
extract_host_from_guardduty(event)
33-
extract_host_from_route53(event)
3429

3530
return events
3631

@@ -220,19 +215,3 @@ def extract_host_from_guardduty(event):
220215
host = host.get("instanceDetails", {}).get("instanceId")
221216
if host is not None:
222217
event[DD_HOST] = host
223-
224-
225-
def extract_host_from_route53(event):
226-
if event is not None and event.get(DD_SOURCE) == str(AwsEventSource.ROUTE53):
227-
message = event.get("message", {})
228-
if isinstance(message, str):
229-
try:
230-
message = json.loads(message)
231-
except json.JSONDecodeError:
232-
logger.debug("Failed to decode Route53 message")
233-
return
234-
235-
if isinstance(message, dict):
236-
host = message.get("srcids", {}).get("instance")
237-
if host is not None:
238-
event[DD_HOST] = host

aws/logs_monitoring/steps/enums.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ class AwsEventSource(Enum):
1414
MSK = "msk"
1515
MYSQL = "mysql"
1616
POSTGRESQL = "postgresql"
17-
ROUTE53 = "route53"
1817
S3 = "s3"
1918
SNS = "sns"
2019
STEPFUNCTION = "stepfunction"
@@ -30,7 +29,6 @@ def cloudwatch_sources():
3029
AwsEventSource.ELASTICSEARCH,
3130
AwsEventSource.FARGATE,
3231
AwsEventSource.MSK,
33-
AwsEventSource.ROUTE53,
3432
]
3533

3634

@@ -46,8 +44,6 @@ def __init__(self, string, event_source):
4644
GUARDDUTY = ("guardduty", AwsEventSource.GUARDDUTY)
4745
KINESIS = ("amazon_kinesis", AwsEventSource.KINESIS)
4846
MSK = ("amazon_msk", AwsEventSource.MSK)
49-
# e.g. AWSLogs/123456779121/vpcdnsquerylogs/vpc-********/2021/05/11/vpc-********_vpcdnsquerylogs_********_20210511T0910Z_71584702.log.gz
50-
ROUTE53 = ("vpcdnsquerylogs", AwsEventSource.ROUTE53)
5147

5248
def __str__(self):
5349
return f"{self.string}"

aws/logs_monitoring/tests/test_enrichment.py

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
import json
2-
32
import unittest
43
from unittest.mock import MagicMock
54

6-
from caching.cache_layer import CacheLayer
75
from approvaltests.approvals import verify_as_json
6+
7+
from caching.cache_layer import CacheLayer
88
from steps.enrichment import (
99
add_metadata_to_lambda_log,
10+
extract_ddtags_from_message,
1011
extract_host_from_cloudtrails,
1112
extract_host_from_guardduty,
12-
extract_host_from_route53,
13-
extract_ddtags_from_message,
1413
)
1514

1615

@@ -169,14 +168,6 @@ def test_parse_source_guardduty(self):
169168
extract_host_from_guardduty(event)
170169
self.assertEqual(event["host"], "i-99999999")
171170

172-
def test_parse_source_route53(self):
173-
event = {
174-
"ddsource": "route53",
175-
"message": {"srcids": {"instance": "i-99999999"}},
176-
}
177-
extract_host_from_route53(event)
178-
self.assertEqual(event["host"], "i-99999999")
179-
180171

181172
class TestLambdaMetadataEnrichment(unittest.TestCase):
182173
def test_empty_event(self):

aws/logs_monitoring/tests/test_parsing.py

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -134,24 +134,6 @@ def test_redshift_gov_event(self):
134134
str(AwsEventSource.S3),
135135
)
136136

137-
def test_route53_event(self):
138-
self.assertEqual(
139-
parse_event_source(
140-
{"awslogs": "logs"},
141-
"my-route53-loggroup123",
142-
),
143-
str(AwsEventSource.ROUTE53),
144-
)
145-
146-
def test_vpcdnsquerylogs_event(self):
147-
self.assertEqual(
148-
parse_event_source(
149-
{"Records": ["logs-from-s3"]},
150-
"AWSLogs/123456779121/vpcdnsquerylogs/vpc-********/2021/05/11/vpc-********_vpcdnsquerylogs_********_20210511T0910Z_71584702.log.gz",
151-
),
152-
str(AwsEventSource.ROUTE53),
153-
)
154-
155137
def test_fargate_event(self):
156138
self.assertEqual(
157139
parse_event_source(

aws/logs_monitoring/tools/integration_tests/snapshots/cloudwatch_log_route53.json

Lines changed: 0 additions & 16 deletions
This file was deleted.

aws/logs_monitoring/tools/integration_tests/snapshots/cloudwatch_log_route53.json~snapshot

Lines changed: 0 additions & 155 deletions
This file was deleted.

aws/logs_monitoring/tools/integration_tests/tester/test_snapshots.py

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -159,11 +159,6 @@ def test_cloudwatch_log_lambda_invocation(self):
159159
snapshot_filename = f"{input_filename}~snapshot"
160160
self.compare_snapshot(input_filename, snapshot_filename)
161161

162-
def test_cloudwatch_log_route53(self):
163-
input_filename = f"{snapshot_dir}/cloudwatch_log_route53.json"
164-
snapshot_filename = f"{input_filename}~snapshot"
165-
self.compare_snapshot(input_filename, snapshot_filename)
166-
167162
def test_cloudwatch_log_timeout(self):
168163
input_filename = f"{snapshot_dir}/cloudwatch_log_timeout.json"
169164
snapshot_filename = f"{input_filename}~snapshot"

0 commit comments

Comments
 (0)