Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check that notifications don't exceed SQS message limit #2085

Closed
wants to merge 26 commits into from

Conversation

whabanks
Copy link
Contributor

@whabanks whabanks commented Jan 18, 2024

Summary | Résumé

Notifications payloads sent to /v2/notifications/{type} are now checked to ensure that their size in bytes does not exceed the SQS message payload size limit.

  • Add logging that identifies the largest piece of data when oversized payloads are attempted.
  • Add a message informing the API user of the size limit and pointing them to the largest item in their payload as a guide.
  • Add a recursive utility method to flatten a dict for easier processing in some situations.

SQS has a payload limit 262,144 bytes, or 256Kib. When Celery attempts to consume inflights that are greater than this size limit it will fail and the message is returned to the inflight inbox. This loop continues until the inflight is expired thus creating a lot of unnecessary Celery errors in our logs.

Related work

Test instructions | Instructions pour tester la modification

Test 1

  1. Send an email with an attachment via the API using attachment_content.txt for the personalisation.
  2. Note the following error is returned:
{
    "status_code": 413,
    "errors": [
        {
            "error": "BadRequestError",
            "message": "Notification size cannot exceed 256Kb. Consider reducing the size of: personalisation.link_to_file.filename"
        }
    ]
}

Test 2

  1. Add a variable to the template used in test 1
  2. Replace the filename content from the above attachment_content.txt with something reasonable like "filename" and move the previous content into the variable added in step 1
  3. Attempt the send
  4. Note that the pre-existing personalisation size validation logic still works as expected.

@whabanks whabanks changed the title Add validation to check that a notification does not exceed sqs messa… Add validation to check that notifications dont exceed sqs msg limit Jan 22, 2024
@whabanks whabanks marked this pull request as ready for review January 22, 2024 14:33
@whabanks whabanks marked this pull request as draft January 22, 2024 14:33
@whabanks whabanks marked this pull request as ready for review January 22, 2024 17:21
@jzbahrai
Copy link
Collaborator

@jzbahrai jzbahrai marked this pull request as draft January 24, 2024 20:01
@whabanks whabanks changed the title Add validation to check that notifications dont exceed sqs msg limit Check that notifications don't exceed SQS message limit Jan 6, 2025
@smcmurtry
Copy link
Contributor

Test 1
Running Test 1 on the main branch of notification-api running locally, there no celery errors and everything works as expected, I receive the email with the attachment. So unless I'm missing something, I don't think the SQS message payload limit needs to limit our attachment size to 256Kb.

Test 2
Running Test 2 on the main branch locally, I get the error message:

{'status_code': 400,
 'errors': [{'error': 'ValidationError',
   'message': 'Personalisation variables size of 422422 bytes is greater than allowed limit of 51200 bytes.'}]}

So we have an existing error that handles this case already.

@whabanks
Copy link
Contributor Author

Closing as investigations determined that we no longer need this additional validation / error messages bubbled up to the front end.

@whabanks whabanks closed this Jan 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants