Netflix / dispatch

All of the ad-hoc things you're doing to manage incidents today, done for you, and much more!
Apache License 2.0
5.15k stars 515 forks source link

feat(dispatch aws plugin): adds support for decompressing signals #5523

Open mvilanova opened 1 week ago

mvilanova commented 1 week ago

Summary of Changes in plugin.py

Imports

New Function

def decompress_json(compressed_str: str) -> str:
    """Decompress a base64 encoded gzipped JSON string."""
    decoded = base64.b64decode(compressed_str)
    decompressed = gzip.decompress(decoded)
    return decompressed.decode("utf-8")

Class AWSSQSSignalConsumerPlugin

Detailed Changes

if message_attributes.get("compressed", {}).get("StringValue") == "gzip":
    # Message is compressed, decompress it
    message_body = decompress_json(message_body)
log.warning(
    f"Received a signal instance that does not conform to the `SignalInstanceCreate` structure. Skipping creation: {e}"
)
log.info(
    f"Received a signal instance that already exists in the database. Skipping creation: {signal_instance_in.raw['id']}"
)
log.exception(
    f"Encountered an Integrity error when trying to create a signal instance: {e}"
)
log.exception(f"Unable to create signal instance: {e}")
log.debug(
    f"Received a signal with name {signal_instance.signal.name} and id {signal_instance.signal.id}"
)

These changes enhance the functionality of the AWSSQSSignalConsumerPlugin by adding support for compressed messages and improving the clarity and consistency of log messages.