Skip to content

Commit

Permalink
feat(signal processing): adds better logging for troubleshooting purp…
Browse files Browse the repository at this point in the history
…oses (#5592)
  • Loading branch information
mvilanova authored Dec 10, 2024
1 parent c85f3b0 commit baf139d
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 13 deletions.
24 changes: 14 additions & 10 deletions src/dispatch/plugins/dispatch_aws/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,16 +74,20 @@ def consume(self, db_session: Session, project: Project) -> None:

entries: list[SqsEntries] = []
for message in response["Messages"]:
message_body = json.loads(message["Body"])
message_body_message = message_body.get("Message")
message_attributes = message_body.get("MessageAttributes", {})

if message_attributes.get("compressed", {}).get("Value") == "zlib":
# Message is compressed, decompress it
message_body_message = decompress_json(message_body_message)
signal_data = json.loads(message_body_message)
else:
signal_data = message_body_message
try:
message_body = json.loads(message["Body"])
message_body_message = message_body.get("Message")
message_attributes = message_body.get("MessageAttributes", {})

if message_attributes.get("compressed", {}).get("Value") == "zlib":
# Message is compressed, decompress it
message_body_message = decompress_json(message_body_message)
signal_data = json.loads(message_body_message)
else:
signal_data = message_body_message
except Exception as e:
log.exception(f"Unable to extract signal data from SQS message: {e}")
continue

try:
signal_instance_in = SignalInstanceCreate(
Expand Down
15 changes: 12 additions & 3 deletions src/dispatch/signal/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -544,9 +544,18 @@ def delete(*, db_session: Session, signal_id: int):
return signal_id


def is_valid_uuid(val):
def is_valid_uuid(value) -> bool:
"""
Checks if the provided value is a valid UUID.
Args:
val: The value to be checked.
Returns:
bool: True if the value is a valid UUID, False otherwise.
"""
try:
uuid.UUID(str(val), version=4)
uuid.UUID(str(value), version=4)
return True
except ValueError:
return False
Expand Down Expand Up @@ -587,7 +596,7 @@ def create_instance(
signal_instance.id = signal_instance_in.raw["id"]

if signal_instance.id and not is_valid_uuid(signal_instance.id):
msg = f"Invalid signal id format. Expecting UUID format. Received {signal_instance.id}."
msg = f"Invalid signal id format. Expecting UUIDv4 format. Signal id: {signal_instance.id}. Signal name/variant: {signal_instance.signal.name if signal_instance.signal and signal_instance.signal.name else signal_instance.signal.variant}"
log.warn(msg)
raise HTTPException(
status_code=status.HTTP_400_BAD_REQUEST,
Expand Down

0 comments on commit baf139d

Please sign in to comment.