cds-snc / notification-planning-core

Project planning for GC Notify Core Team
0 stars 0 forks source link

Revive the Pinpoint implementation to send SMS notifications #286

Open jimleroyer opened 4 months ago

jimleroyer commented 4 months ago

Description

As a system ops, I need to send a notification through a designated pool of code so that I can isolate codes depending on services and usage, i.e. short code versus dedicated long code or random pool of codes.

As a product manager, I need to send notifications through the short code, So that GCNotify gains more trust, reliability and throughput.

As a policy maker, I need to send notifications through the short code, so that 2fa notifications are only sent through it as agreed upon with the telecoms (assuming our short code stays exclusive for the 2FA usage).

WHY are we building?

WHAT are we building?

VALUE created by our solution

Out of scope

Acceptance Criteria

Red flags

🚩 The SMS delivery receipts might come from a different source than the one for SNS, according to past investigation. If this turns out to be true, feel free to put this card to blocked and create a new task to tackle the new source of notifications with proper plumbing.

Additional information

jimleroyer commented 2 months ago

Starting work on this today! 🕺

sastels commented 2 months ago

Clickops'd a pinpoint pool in staging with a new long code. Can send with it with

aws pinpoint-sms-voice-v2 send-text-message --destination-phone-number +<number> --origination-identity pool-090efa2fefab4cb5b10fa12125998266 --message-body "hi2me from pinpoint pool"

Started roughing in some pinpoint code: https://github.com/cds-snc/notification-api/pull/2152

ben851 commented 2 months ago

@sastels to look into creating the pinpoint infrastructure with Terraform

sastels commented 2 months ago

Sadly it appears that terraform does not yet support Pinpoint V2 (including dealing with pools)

sastels commented 2 months ago
ben851 commented 2 months ago

Pinpoint could possibly be implemented with CloudFormation instead.

sastels commented 2 months ago

looks like we can send delivery receipts to SNS or CloudWatch as well

sastels commented 2 months ago

pinpoint-sms-voice-v2 added on 2022-03-31

Looks like it's not supported in terraform nor cloudformation yet.

sastels commented 2 months ago

WIP PR for a bunch of stuff

sastels commented 2 months ago

All that IAM stuff in the PR actually works and I can send through a pinpoint pool and see it appear in the logs (tested in dev)! And in the logs we even get the actual phone number used to send.

sastels commented 2 months ago

made a log group for pinpoint failures too and have failures redirected there.

sastels commented 2 months ago

Ok! So we have

Some parts of some of this have been tested locally or on dev merging any or all of these in should not affect how the system runs, ie the old SNS flow is still there and unchanged. The pinpoint bits will only be used if we set the AWSPINPOINT* variables in api and send using one of the designated templates.

sastels commented 2 months ago

work continues...

sastels commented 2 months ago

ready for review! https://github.com/cds-snc/notification-lambdas/pull/73 https://github.com/cds-snc/notification-terraform/pull/1246

sastels commented 2 months ago
sastels commented 2 months ago

reworked terraform PR a bit more, bootstrapped the ecr repo on dev, and got the lambda applying as well. Ready for another look through by Ben.

jimleroyer commented 2 months ago

TF PR is ready for another look for infrastructure review. After that, Steve will play with the API and polish the PR. We will need to test in staging environment afterward with preconfigured pools of codes.

sastels commented 2 months ago

TF merged and looks good in staging. Can use AWS CLI to send an email to the new pool and the delivery gets logged, lambda triggered, and task scheduled.

Next step is finishing the api PR that contains the new pinpoint receipt processing task and logic to determine whether to send via pinpoint or not

sastels commented 2 months ago

api PR looks good, just going to give it another look over then it'll be ready for review.

sastels commented 2 months ago

api pr ready for review https://github.com/cds-snc/notification-api/pull/2152

jimleroyer commented 2 months ago

Jimmy and team to review the PR.

P0NDER0SA commented 1 month ago

Steve has the puck... he. turned it over at the blue line now it's back in progress

sastels commented 1 month ago

Still have a few of Jimmy's comments to address

ben851 commented 1 month ago

Steve will get back to this this week to address Jimmy's comments

sastels commented 1 month ago

I think this is ready for Jimmy to take another look! https://github.com/cds-snc/notification-api/pull/2152

sastels commented 1 month ago

Another PR! https://github.com/cds-snc/notification-manifests/pull/2558

Update: PR merged into staging.

sastels commented 1 month ago

API PR approved. Will merge tomorrow after release and test if staging still works (ie with empty variables). If yes, the PR is ready for release.

Then will sent the staging variables to the shortcode pool and template and test with templates in and not in the shortcode template list.

sastels commented 1 month ago

Started PR for useing Pinpoint for non-shortcode templates as well https://github.com/cds-snc/notification-api/pull/2173 (WIP)

sastels commented 1 month ago

api PR merged into staging and tested. Nothing's different :tada:

Now will turn on PinPoint in staging and see if all these new tasks and lambdas work together 😬 https://github.com/cds-snc/notification-manifests/pull/2602

Shortcode pool

pinpoint_to_sqs_sms_callbacks callback lambda

sastels commented 1 month ago

alrighty! tested in staging.

Oddly the SMS was retried 5 minutes later and sent with SNS - should look into this

sastels commented 1 month ago

ok! This PR added the action that was needed https://github.com/cds-snc/notification-terraform/pull/1314

And this time the pinpoint message was sent with pinpoint!

The lambda processed the receipt, but I see in the celery logs

[2024-05-08 20:21:37,476: ERROR/MainProcess] Received unregistered task of type 'process-pinpoint-result'.
The message has been ignored and discarded.

Possibly a name mismatch? Or I forgot to register the task... that sounds more likely.

In any case, progress!

sastels commented 1 month ago

ok, locally when I start celery I see the task listed

...
  . process-job
  . process-pinpoint-result
  . process-ses-result
  . process-sns-result
  . process-virus-scan-error
...

BUT looking at when celery pod celery-sms-send-scalable-77bcd554b8-5jcbf starts up I don't see the pinpoint task listed!

...
  . process-job
  . process-ses-result
  . process-sns-result
  . process-virus-scan-error
...

So! what's the difference between starting locally and in staging?

Both start with sh scripts/run_celery_send_sms.sh

Note that in the celery pod the code is there in process_pinpoint_receipts_tasks.py

If I run that script on an api node in k8s then I get the same results (ie no process-pinpoint-result)

AFAIK this is where we tell celery what the tasks are

    CELERY_IMPORTS = (
        "app.celery.tasks",
        "app.celery.scheduled_tasks",
        "app.celery.reporting_tasks",
        "app.celery.nightly_tasks",
    )

But process-sns-result isn't in there? it's in app.celery.process_sns_receipts_tasks. So how is it registered?

UPDATE: now I can't see the new task locally either.

ok, but at least I can fix it locally then. https://github.com/cds-snc/notification-api/pull/2175

sastels commented 1 month ago

It's working!

but successful pinpoint sends generate two receipts, one to say it's gone to the carrier, and one to say it's gone to the phone. We want to ignore the one to the carrier. https://github.com/cds-snc/notification-api/pull/2176

sastels commented 1 month ago

the ProviderDetails table has a pinpoint provider still there, it's at the end (priority 50) and inactive. Locally I:

We'd probably want a proper db migration to do this.

sastels commented 1 month ago

ok! this new PR actually works!

Have to add a test or two around this still but can see the light at the end of the tunnel!

sastels commented 1 month ago

Added code to fall back to SNS if

Also added a bunch of tests for all this. Unfortunately tests are not all passing in CI despite passing locally.

sastels commented 1 month ago

ok, got the tests working and tested again locally. I think this is ready for :eyes: https://github.com/cds-snc/notification-api/pull/2173

P0NDER0SA commented 1 month ago

REady for review -- someone will look at it today. Probably Jimmy

jimleroyer commented 1 month ago

Reviewed, left a few questions and comments but nothing major to change. Looks good overall.

sastels commented 1 month ago

Steve will review today!

jimleroyer commented 1 month ago

Jimmy to review the review of the review.

jimleroyer commented 1 month ago

Jimmy approved the PR, Steve will merge after the release is done this morning to test it a bit in staging.

sastels commented 1 month ago

Code merged into staging, and released to prod. SNS still used by both (as env vars are not set).

P0NDER0SA commented 1 month ago

Scope was reduced on this card, so we need to review/QA this one and determine if it's ready to be closed.

sastels commented 1 month ago

Had to turn Pinpoint off in staging, will turn back on today hopefully and we can then QA

jimleroyer commented 4 weeks ago

Removed the QA steps: we will test this feature in the "QA flags" cards that turn this feature on.