Skip to content
This repository has been archived by the owner on Jun 8, 2023. It is now read-only.

Commit

Permalink
Merge pull request #62 from forseti-security/add_logging_for_message_age
Browse files Browse the repository at this point in the history
Log message publish time, receive time, and age
  • Loading branch information
rvandegrift authored Mar 4, 2021
2 parents 122e258 + 6751f2f commit 56e067e
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions app/run.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ def callback(pubsub_message):

# We use the message ID in all logs we emit
message_id = pubsub_message.message_id
message_publish_ts = pubsub_message.publish_time.timestamp()
message_receive_ts = time.time()

# Only one message parser should be able to parse a given message, lets capture which one it is
parser_match = None
Expand Down Expand Up @@ -143,6 +145,10 @@ def callback(pubsub_message):
pubsub_message.ack()
return

# Inject some metadata we want for all messages
parsed_message.metadata['message_publish_timestamp'] = message_publish_ts
parsed_message.metadata['message_receive_timestamp'] = message_receive_ts

for resource in parsed_message.resources:

try:
Expand Down Expand Up @@ -227,6 +233,7 @@ def callback(pubsub_message):
'enforce': decision.enforce,
'non_enforcement_conditions': decision.reasons,
'timestamp': eval_time,
'age_from_publish': eval_time - message_publish_ts
}

logger(evaluation_log)
Expand All @@ -253,6 +260,7 @@ def callback(pubsub_message):
'policy_id': enforcement.evaluation.policy_id,
'resource_data': resource.to_dict(),
'timestamp': remediation_timestamp,
'age_from_publish': remediation_timestamp - message_publish_ts
}

logger(remediation_log)
Expand Down

0 comments on commit 56e067e

Please sign in to comment.