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

JS-7167 Add fcm api support #13

Merged
merged 5 commits into from
May 22, 2024
Merged

JS-7167 Add fcm api support #13

merged 5 commits into from
May 22, 2024

Conversation

nat-aryucharoen
Copy link

@nat-aryucharoen nat-aryucharoen commented May 2, 2024

This PR: in progress

Comment on lines 8 to 9
PROJECT_ID = Settings.firebase.fcm_push_notification.project_id
ENDPOINT = "https://fcm.googleapis.com/v1/projects/#{PROJECT_ID}/messages:send".freeze

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Question/Blocker]: Is there a reason why this is being set here? I think either of these should be configurable from outside of this project

The library shouldn't be dependent on Settings.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like this should be stored in the rpush_apps table. It uses STI, so we'd need to add a new column for it to do it properly.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment on lines 21 to 22
validates_with Rpush::Client::ActiveModel::PayloadDataSizeValidator, limit: 4096
validates_with Rpush::Client::ActiveModel::RegistrationIdsCountValidator, limit: 1000

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[NOTE]: These are the same validations as current GCM, so we're good. I think this is good.

@danielnho22
Copy link

I think as it stands, the PR mostly works. I'd like to see if we can find away around not passing accessing Settings directly.

I also don't know how data is set in this case..

@danielnho22 danielnho22 requested a review from v7chan May 14, 2024 18:52
@danielnho22
Copy link

@v7chan Could you take a look too?

Comment on lines 8 to 9
# TODO: Add whatever validation is needed here
# validates :auth_key, presence: true
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should fill this in to make it clear which columns we need for Fcm (presumably with the new column for project_id)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also need other columns also to make OAuth logic for fetching an access token self-contained in the Rpush: https://github.com/Codefied/housecall-web/pull/51155/files#diff-ad01b5deb18c1010b83f08165e8b3bdedd5e72e17a62a2c644506a8617f1b2ffR9

looks ok?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added validates :fcm_json_token, presence: true

fcm_access_token and fcm_access_token_expiration will be filled in with the first call, so i guess i cannot add the validation here

validates :priority, inclusion: { in: FCM_PRIORITIES }, allow_nil: true

validates_with Rpush::Client::ActiveModel::PayloadDataSizeValidator, limit: 4096
validates_with Rpush::Client::ActiveModel::RegistrationIdsCountValidator, limit: 1000
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't registration_ids not be set for FCM notifications? GCM allowed for multiple as array, but it looks like we want to use the device_token (singular) field here

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fcm does not use registration_ids, i can remove this validation

Comment on lines 105 to 115
def priority_for_notification
case priority
when 0 then 'PRIORITY_UNSPECIFIED'
when 1 then 'PRIORITY_MIN'
when 2 then 'PRIORITY_LOW'
when 5 then 'PRIORITY_DEFAULT'
when 6 then 'PRIORITY_HIGH'
when 10 then 'PRIORITY_MAX'
else
'PRIORITY_DEFAULT'
end
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if I'm following this correctly. priority= only allows the values of 10 and 5, do we need to handle these other values?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can remove this since we remove the duplicate override

json = {
'notification' => android_notification,
}
json['data'] = data if data
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this need to be duplicated here? I think this is only for Android-specific override if necessary and since we are not using FCM to deliver to both platforms, not having to duplicate this key makes the payload smaller

I see similar duplicated values like notification_priority within the Android overrides. In general, I think the first phase of FCM we are adding is only to deliver to Android, Apns8 will continue to be used for iOS. So we can avoid duplicating platform-overrides for now.

How we use rpush will need to change if we are to deliver to both iOS and Android via FCM and that's not the intention right now anyway.

Comment on lines 61 to 63
# Android does not appear to handle content_available anymore. Instead "priority" should be used
# with "low" being a background only message. APN however should support this field.
# json['content_available'] = content_available if content_available
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should either map this or disallow this field from being set, this comment won't be visible to users of rpush

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks like we are not currently using 'content_available' for sending push to android, if the anyone add this to the fcm notification, the NotificationKeysInAllowedListValidator will catch it.

Comment on lines +38 to +41
when 400
bad_request(response)
when 401
unauthorized
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As we roll this out, it's worth catching up with the 400/401s we've been facing from Firebase in our web push. As far as I remember, there was a bit of intermittent nature to them and I don't know if Voice ever got to the bottom of it

https://housecall.atlassian.net/browse/VOICE-6463

At the very least we'll need to monitor closely to know if we're failing to deliver more than normal on FCM v1 compared to legacy.

Copy link

@danielnho22 danielnho22 May 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's worth catching up with the 400/401s

What do you mean by "catch up with"? As in have visibility into why they happen? We'll ensure we have some monitoring before we roll out.

Since failures get logged to sumologic we can add some reporting there. If needed, we can also add some metrics to datadog with the Reflections API, but I figured the sumologic logs should be good enough.

Copy link

@v7chan v7chan May 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As in have visibility into why they happen?

Yeah, just chat with Voice and/or read the investigations they've left behind. There was some number of mysterious errors that I don't know if they ever got to the bottom of, just don't want us to assume all requests will magically work

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

might be this? for 401: https://firebase.google.com/docs/reference/fcm/rest/v1/ErrorCode

THIRD_PARTY_AUTH_ERROR (HTTP error code = 401) APNs certificate or web push auth key was invalid or missing. | A message targeted to an iOS device or a web push registration could not be sent. Check the validity of your development and production credentials

Comment on lines +38 to +41
when 400
bad_request(response)
when 401
unauthorized
Copy link

@danielnho22 danielnho22 May 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's worth catching up with the 400/401s

What do you mean by "catch up with"? As in have visibility into why they happen? We'll ensure we have some monitoring before we roll out.

Since failures get logged to sumologic we can add some reporting there. If needed, we can also add some metrics to datadog with the Reflections API, but I figured the sumologic logs should be good enough.

lib/rpush/daemon/fcm/delivery.rb Show resolved Hide resolved
@danielnho22 danielnho22 merged commit 2c7cfdd into branch54 May 22, 2024
@danielnho22 danielnho22 deleted the JS-7167-add-fcm branch May 22, 2024 22:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants