Skip to content

Add updated params to the Realtime listener callback. #4339

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

Merged
merged 20 commits into from
Dec 19, 2022

Conversation

danasilver
Copy link
Contributor

@danasilver danasilver commented Nov 18, 2022

Add the Set<String> of updated config parameter keys as a param in the ConfigUpdateListener callback. Keys are added if their presence, value, or metadata has changed. The callback is only called when there is an update; the set should never be empty.

Internal: b/258843184

@google-oss-bot
Copy link
Contributor

google-oss-bot commented Nov 18, 2022

Coverage Report 1

Affected Products

  • firebase-config

    Overall coverage changed from ? (993673e) to 79.61% (4231d09) by ?.

    30 individual files with coverage change

    FilenameBase (993673e)Merge (4231d09)Diff
    AutoValue_ConfigUpdate.java?29.41%?
    Code.java?0.00%?
    ConfigAutoFetch.java?84.26%?
    ConfigCacheClient.java?93.33%?
    ConfigContainer.java?93.33%?
    ConfigFetchHandler.java?92.86%?
    ConfigFetchHttpClient.java?86.21%?
    ConfigGetParameterHandler.java?96.45%?
    ConfigMetadataClient.java?90.63%?
    ConfigRealtimeHandler.java?23.08%?
    ConfigRealtimeHttpClient.java?34.31%?
    ConfigStorageClient.java?100.00%?
    ConfigUpdate.java?100.00%?
    ConfigUpdateListener.java?0.00%?
    ConfigUpdateListenerRegistration.java?0.00%?
    DefaultsXmlParser.java?0.00%?
    FirebaseRemoteConfig.java?87.83%?
    FirebaseRemoteConfigClientException.java?75.00%?
    FirebaseRemoteConfigException.java?95.65%?
    FirebaseRemoteConfigFetchThrottledException.java?100.00%?
    FirebaseRemoteConfigInfo.java?0.00%?
    FirebaseRemoteConfigInfoImpl.java?100.00%?
    FirebaseRemoteConfigServerException.java?84.21%?
    FirebaseRemoteConfigSettings.java?61.54%?
    FirebaseRemoteConfigValue.java?0.00%?
    FirebaseRemoteConfigValueImpl.java?84.62%?
    Personalization.java?91.43%?
    RemoteConfigComponent.java?85.06%?
    RemoteConfigConstants.java?0.00%?
    RemoteConfigRegistrar.java?100.00%?

Test Logs

  1. https://storage.googleapis.com/firebase-sdk-metric-reports/LgDyp0KD2J.html

@google-oss-bot
Copy link
Contributor

The public api surface has changed for the subproject firebase-config:
error: Removed method com.google.firebase.remoteconfig.ConfigUpdateListener.onEvent() [RemovedMethod]
error: Added method com.google.firebase.remoteconfig.ConfigUpdateListener.onUpdate(java.util.Set<java.lang.String>) [AddedAbstractMethod]

Please update the api.txt files for the subprojects being affected by this change by running ./gradlew ${subproject}:generateApiTxtFile. Also perform a major/minor bump accordingly.

@github-actions
Copy link
Contributor

github-actions bot commented Nov 18, 2022

Unit Test Results

1 235 tests   1 235 ✔️  1m 58s ⏱️
     63 suites         0 💤
     63 files           0

Results for commit 154da4b.

♻️ This comment has been updated with latest results.

@google-oss-bot
Copy link
Contributor

google-oss-bot commented Nov 18, 2022

Size Report 1

Affected Products

  • firebase-config

    TypeBase (993673e)Merge (4231d09)Diff
    aar85.4 kB88.7 kB+3.29 kB (+3.8%)
    apk (aggressive)120 kB121 kB+848 B (+0.7%)
    apk (release)744 kB746 kB+1.20 kB (+0.2%)

Test Logs

  1. https://storage.googleapis.com/firebase-sdk-metric-reports/GSUSNh4EbQ.html

@google-oss-bot
Copy link
Contributor

The public api surface has changed for the subproject firebase-config:
error: Removed method com.google.firebase.remoteconfig.ConfigUpdateListener.onEvent() [RemovedMethod]
error: Added method com.google.firebase.remoteconfig.ConfigUpdateListener.onUpdate(java.util.Set<java.lang.String>) [AddedAbstractMethod]

Please update the api.txt files for the subprojects being affected by this change by running ./gradlew ${subproject}:generateApiTxtFile. Also perform a major/minor bump accordingly.

@google-oss-bot
Copy link
Contributor

The public api surface has changed for the subproject firebase-config:
error: Removed method com.google.firebase.remoteconfig.ConfigUpdateListener.onEvent() [RemovedMethod]
error: Added method com.google.firebase.remoteconfig.ConfigUpdateListener.onUpdate(java.util.Set<java.lang.String>) [AddedAbstractMethod]

Please update the api.txt files for the subprojects being affected by this change by running ./gradlew ${subproject}:generateApiTxtFile. Also perform a major/minor bump accordingly.

danasilver added a commit that referenced this pull request Dec 1, 2022
Allows the executor to be injected for testing. This came up testing Add updated params to the Realtime listener callback. #4339.
Prepares Realtime to integrate with Firebase Executors.
"Failed to auto-fetch config update.", fetchTask.getException()));
}

if (!activatedConfigsTask.isSuccessful()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

If the fetch is successful but getting the activated params isn't, do you think we should still execute the listener onUpdate callback but with all of the fetch params? B/c in this case the SDK would have the most up to date configs in it's fetched cache.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'd prefer to return an error here rather than catch it since we might obscure a problem and return incomplete results (ex. a deleted param wouldn't show up).

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah returning an error makes sense here but I just wanted to bring up a potential edge case where the fetch is successful but getting the activated configs is not. In this case the new fetched config/template version will be saved on the device but the user's listener wouldn't be notified of it and so it would seem like the app never got the Config Update but it actually did. It would need to wait until the next event that incremented the template version before it gets another invalidation signal. Doesn't need to be resolved now, just wanted to bring up the possibility.

Copy link
Contributor

Choose a reason for hiding this comment

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

Just wanted to bring up this possible scenario

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah... that's a good call out. Since we'd still surface the error, it seems right to raise it rather than change the SDK behavior in this case. Devs can still decide if they want to manually fetch/activate when they get an error from realtime.

return Tasks.forResult(null);
}

if (fetchResponse.getFetchedConfigs() == null) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of checking the configs for null could we check the response status for BACKEND_HAS_NO_UPDATES?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It looked like getFetchedConfigs() might return a value when the state is BACKEND_HAS_NO_UPDATES, since it's constructed with one here:

.

It also seemed safer to check for null before getting the value later on in this method.

Copy link
Contributor

@qdpham13 qdpham13 Dec 7, 2022

Choose a reason for hiding this comment

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

I don't think there is a scenario anymore where the response returns a null fetchedConfigs, due to the change where we added the template version to the NO_CHANGE response. Plus in the fetchResponseisUpToDate method it checks the fetchedConfig for null and the only way to return true for when the fetchedConfig is null is if the status is BACKEND_HAS_NO_UPDATES. So maybe just remove this check altogether

Copy link
Contributor

Choose a reason for hiding this comment

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

Wondered if we could remove this check?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point it likely isn't necessary. I'd keep it for now since getFetchedConfigs() isn't annotated @Nonnull so it could be null and checking for null keeps with the assumptions that the rest of the SDK is written with right now. We might change that separately later.

@@ -136,6 +139,10 @@ public long getTemplateVersionNumber() {
return templateVersionNumber;
}

public ConfigContainer getCopy() throws JSONException {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we just directly use the getCopy method on line 94?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We can, yeah. It seemed a bit better in terms of OO to not use another instance's private variables, but Java lets you and I can't find any strong reasoning against it. I updated this

@qdpham13 qdpham13 self-requested a review December 12, 2022 21:25
Copy link
Contributor

@qdpham13 qdpham13 left a comment

Choose a reason for hiding this comment

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

Just had some other questions about somethings from the last review. Other then this it LGTM.

return Tasks.forResult(null);
}

if (fetchResponse.getFetchedConfigs() == null) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Wondered if we could remove this check?

"Failed to auto-fetch config update.", fetchTask.getException()));
}

if (!activatedConfigsTask.isSuccessful()) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Just wanted to bring up this possible scenario

@qdpham13 qdpham13 self-requested a review December 19, 2022 23:07
Copy link
Contributor

@qdpham13 qdpham13 left a comment

Choose a reason for hiding this comment

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

LGTM!

@danasilver danasilver merged commit e40042a into realtime-rc-merge Dec 19, 2022
@danasilver danasilver deleted the ds-realtime-updatedparams branch December 19, 2022 23:19
danasilver added a commit that referenced this pull request Dec 20, 2022
Allows the executor to be injected for testing. This came up testing Add updated params to the Realtime listener callback. #4339.
Prepares Realtime to integrate with Firebase Executors.
danasilver added a commit that referenced this pull request Dec 20, 2022
Add the et updated config parameter keys as a param in the ConfigUpdateListener callback. Keys are added if their presence, value, or metadata has changed. The callback is only called when there is an update; the set should never be empty.
@firebase firebase locked and limited conversation to collaborators Jan 19, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants