Skip to content

Commit 185d315

Browse files
authored
VED-806 (Follow-up) Fix batch filter lambda bug (#963)
1 parent c3bce7b commit 185d315

File tree

4 files changed

+15
-4
lines changed

4 files changed

+15
-4
lines changed

lambdas/batch_processor_filter/src/batch_processor_filter_service.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
from batch_file_repository import BatchFileRepository
88
from common.clients import get_sqs_client, logger
99
from common.log_firehose import send_log_to_firehose
10-
from constants import QUEUE_URL, FileNotProcessedReason, FileStatus
10+
from constants import QUEUE_URL, SPLUNK_FIREHOSE_STREAM_NAME, FileNotProcessedReason, FileStatus
1111
from exceptions import EventAlreadyProcessingForSupplierAndVaccTypeError
1212

1313
BATCH_AUDIT_REPOSITORY = BatchAuditRepository()
@@ -72,4 +72,7 @@ def apply_filter(self, batch_file_created_event: BatchFileCreatedEvent) -> None:
7272

7373
successful_log_message = f"File forwarded for processing by ECS. Filename: {filename}"
7474
logger.info(successful_log_message)
75-
send_log_to_firehose({**batch_file_created_event, "message": successful_log_message})
75+
send_log_to_firehose(
76+
stream_name=SPLUNK_FIREHOSE_STREAM_NAME,
77+
log_data={**batch_file_created_event, "message": successful_log_message},
78+
)

lambdas/batch_processor_filter/tests/test_lambda_handler.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
AUDIT_TABLE_FILENAME_GSI,
2727
AUDIT_TABLE_NAME,
2828
AUDIT_TABLE_QUEUE_NAME_GSI,
29+
SPLUNK_FIREHOSE_STREAM_NAME,
2930
AuditTableKeys,
3031
FileStatus,
3132
)
@@ -299,7 +300,8 @@ def test_lambda_handler_processes_event_successfully(self):
299300
]
300301
)
301302
self.mock_firehose_send_log.assert_called_once_with(
302-
{**self.default_batch_file_event, "message": expected_success_log_message}
303+
stream_name=SPLUNK_FIREHOSE_STREAM_NAME,
304+
log_data={**self.default_batch_file_event, "message": expected_success_log_message},
303305
)
304306

305307
def test_lambda_handler_processes_event_successfully_when_event_for_same_supplier_and_vacc_already_processed(
@@ -345,4 +347,6 @@ def test_lambda_handler_processes_event_successfully_when_event_for_same_supplie
345347
call(expected_success_log_message),
346348
]
347349
)
348-
self.mock_firehose_send_log.assert_called_once_with({**test_event, "message": expected_success_log_message})
350+
self.mock_firehose_send_log.assert_called_once_with(
351+
stream_name=SPLUNK_FIREHOSE_STREAM_NAME, log_data={**test_event, "message": expected_success_log_message}
352+
)

lambdas/batch_processor_filter/tests/testing_utils.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
"FILE_NAME_GSI": "filename_index",
1111
"QUEUE_NAME_GSI": "queue_name_index",
1212
"SOURCE_BUCKET_NAME": "immunisation-batch-internal-dev-data-sources",
13+
"SPLUNK_FIREHOSE_STREAM_NAME": "immunisation-batch-internal-dev-splunk-stream",
1314
"ACK_BUCKET_NAME": "immunisation-batch-internal-dev-data-destinations",
1415
}
1516

lambdas/shared/src/common/log_firehose.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
)
77

88

9+
# Not keen on including blocking calls in function code to forward log data to Splunk (via Firehose)
10+
# Consider simply logging and setting up CW subscription filters to forward to Firehose
11+
# https://docs.aws.amazon.com/firehose/latest/dev/writing-with-cloudwatch-logs.html
912
def send_log_to_firehose(stream_name: str, log_data: dict) -> None:
1013
"""Sends the log_message to Firehose"""
1114
try:

0 commit comments

Comments
 (0)