Skip to content

Commit

Permalink
Add init support for SF log stream
Browse files Browse the repository at this point in the history
  • Loading branch information
nine5two7 committed Nov 1, 2024
1 parent 4fda68f commit cf47361
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
5 changes: 5 additions & 0 deletions aws/logs_monitoring/customized_log_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ def is_lambda_customized_log_group(logstream_name):
)


# For both default and customzied Step Functions log groups, the log_stream starts with "states/"
def is_step_functions_log_group(logstream_name):
return logstream_name.startswith("states/")


def get_lambda_function_name_from_logstream_name(logstream_name):
try:
# Not match the pattern for customized Lambda log group
Expand Down
1 change: 0 additions & 1 deletion aws/logs_monitoring/steps/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,6 @@ def __init__(self, string, event_source):
RDS = ("/aws/rds", AwsEventSource.RDS)
# e.g. sns/us-east-1/123456779121/SnsTopicX
SNS = ("sns/", AwsEventSource.SNS)
STEPFUNCTION = ("/aws/vendedlogs/states", AwsEventSource.STEPFUNCTION)
TRANSITGATEWAY = ("tgw-attach", AwsEventSource.TRANSITGATEWAY)

def __str__(self):
Expand Down
8 changes: 5 additions & 3 deletions aws/logs_monitoring/steps/handlers/awslogs_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
)
from customized_log_group import (
is_lambda_customized_log_group,
is_step_functions_log_group,
get_lambda_function_name_from_logstream_name,
)
from steps.handlers.aws_attributes import AwsAttributes
Expand Down Expand Up @@ -108,6 +109,10 @@ def set_source(self, event):
if is_lambda_customized_log_group(log_stream):
self.metadata[DD_SOURCE] = str(AwsEventSource.LAMBDA)

# Special handling for Step Functions log groups. Regardless of whether the log group is customized, the corresponding log stream starts with 'states/'."
if is_step_functions_log_group(log_stream):
self.metadata[DD_SOURCE] = str(AwsEventSource.STEPFUNCTION)

def add_cloudwatch_tags_from_cache(self):
log_group_arn = self.aws_attributes.get_log_group_arn()
formatted_tags = self.cache_layer.get_cloudwatch_log_group_tags_cache().get(
Expand Down Expand Up @@ -159,9 +164,6 @@ def handle_rds_source(self):
)

def handle_step_function_source(self):
if not self.aws_attributes.get_log_stream().startswith("states/"):
return

state_machine_arn = self.get_state_machine_arn()
if not state_machine_arn:
return
Expand Down

0 comments on commit cf47361

Please sign in to comment.