Skip to content

Commit

Permalink
SLS-2070: Adds step function forwarding to forwarder (#546)
Browse files Browse the repository at this point in the history
Adds step functions logs forwarding
  • Loading branch information
IvanTopolcic committed May 3, 2022
1 parent fde8a24 commit 1e53fd7
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
16 changes: 16 additions & 0 deletions aws/logs_monitoring/parsing.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,9 @@ def find_cloudwatch_source(log_group):
):
return "apigateway"

if log_group.startswith("/aws/vendedlogs/states"):
return "stepfunction"

# e.g. dms-tasks-test-instance
if log_group.startswith("dms-tasks"):
return "dms"
Expand Down Expand Up @@ -482,6 +485,19 @@ def awslogs_handler(event, context, metadata):
if metadata[DD_SOURCE] == "cloudwatch" or metadata.get(DD_HOST, None) == None:
metadata[DD_HOST] = aws_attributes["aws"]["awslogs"]["logGroup"]

if metadata[DD_SOURCE] == "stepfunction" and logs["logStream"].startswith(
"states/"
):
try:
message = json.loads(logs["logEvents"][0]["message"])
if message.get("execution_arn") is not None:
execution_arn = message["execution_arn"]
arn_tokens = execution_arn.split(":")
arn_tokens[5] = "stateMachine"
metadata[DD_HOST] = ":".join(arn_tokens[:-1])
except Exception as e:
logger.debug("Unable to set stepfunction host: %s" % e)

# When parsing rds logs, use the cloudwatch log group name to derive the
# rds instance name, and add the log name of the stream ingested
if metadata[DD_SOURCE] in ["rds", "mariadb", "mysql", "postgresql"]:
Expand Down
8 changes: 8 additions & 0 deletions aws/logs_monitoring/tests/test_parsing.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,14 @@ def test_carbon_black_event(self):
"carbonblack",
)

def test_step_function_event(self):
self.assertEqual(
parse_event_source(
{"awslogs": "logs"}, "/aws/vendedlogs/states/MyStateMachine-Logs"
),
"stepfunction",
)

def test_cloudwatch_source_if_none_found(self):
self.assertEqual(parse_event_source({"awslogs": "logs"}, ""), "cloudwatch")

Expand Down

0 comments on commit 1e53fd7

Please sign in to comment.