Skip to content

Realtime Fetch ID #4328

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 10 commits into from
Dec 1, 2022
Merged

Realtime Fetch ID #4328

merged 10 commits into from
Dec 1, 2022

Conversation

qdpham13
Copy link
Contributor

@qdpham13 qdpham13 commented Nov 15, 2022

Implementation of Realtime Fetch ID: go/realtime-rc-fetch-id

@google-oss-bot
Copy link
Contributor

1 Warning
⚠️ Did you forget to add a changelog entry? (Add the 'no-changelog' label to the PR to silence this warning.)

Generated by 🚫 Danger

@google-oss-bot
Copy link
Contributor

google-oss-bot commented Nov 15, 2022

Coverage Report 1

Affected Products

  • firebase-config

    Overall coverage changed from ? (8251c4a) to 79.99% (ba0ce7b) by ?.

    28 individual files with coverage change

    FilenameBase (8251c4a)Merge (ba0ce7b)Diff
    Code.java?0.00%?
    ConfigAutoFetch.java?88.51%?
    ConfigCacheClient.java?93.33%?
    ConfigContainer.java?93.06%?
    ConfigFetchHandler.java?92.86%?
    ConfigFetchHttpClient.java?86.21%?
    ConfigGetParameterHandler.java?96.45%?
    ConfigMetadataClient.java?90.63%?
    ConfigRealtimeHandler.java?21.57%?
    ConfigRealtimeHttpClient.java?33.82%?
    ConfigStorageClient.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?84.71%?
    RemoteConfigConstants.java?0.00%?
    RemoteConfigRegistrar.java?100.00%?

Test Logs

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

@github-actions
Copy link
Contributor

github-actions bot commented Nov 15, 2022

Unit Test Results

1 225 tests   1 225 ✔️  2m 15s ⏱️
     62 suites         0 💤
     62 files           0

Results for commit 1595a03.

♻️ This comment has been updated with latest results.

@google-oss-bot
Copy link
Contributor

google-oss-bot commented Nov 15, 2022

Size Report 1

Affected Products

  • firebase-config

    TypeBase (8251c4a)Merge (ba0ce7b)Diff
    aar84.0 kB85.4 kB+1.32 kB (+1.6%)
    apk (aggressive)119 kB120 kB+400 B (+0.3%)
    apk (release)743 kB744 kB+1.01 kB (+0.1%)

Test Logs

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

@qdpham13 qdpham13 changed the title Create overloaded fetch method specifically for realtime and add cust… Realtime Fetch ID Nov 17, 2022
@qdpham13 qdpham13 requested a review from danasilver November 17, 2022 20:59
@qdpham13 qdpham13 changed the title Realtime Fetch ID Realtime Fetch Id Nov 21, 2022
@@ -195,7 +195,8 @@ public void run() {

@VisibleForTesting
public synchronized void fetchLatestConfig(int remainingAttempts, long targetVersion) {
Task<ConfigFetchHandler.FetchResponse> fetchTask = configFetchHandler.fetch(0L);
Task<ConfigFetchHandler.FetchResponse> fetchTask =
configFetchHandler.realtimeFetch(0L, FETCH_RETRY - remainingAttempts + 1);
Copy link
Contributor

Choose a reason for hiding this comment

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

This could use a comment since the math is a bit cryptic on its own. Maybe even worth just keeping a separate attempts counter?

Slightly related, FETCH_RETRIES_ALLOWED or INITIAL_FETCH_RETRIES would be more descriptive as a variable name.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated.

* with the configs fetched from the backend. If the backend was not called or the backend had
* no updates, the {@link FetchResponse}'s configs will be {@code null}.
*/
public Task<FetchResponse> realtimeFetch(
Copy link
Contributor

Choose a reason for hiding this comment

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

It feels a bit off to me that half the header comes from calling a particular method (realtimeFetch) and half from a param passed the method (fetchAttemptNumber). It also breaks the encapsulation of fetch within realtime to have realtime implementation details here.

Since the type and attempt are fetch details and realtime is just making use of them, passing both in (i.e. fetchWithMetadata(long minimumFetchIntervalInSeconds, FetchType fetchType, int fetchAttempt)) could make sense. A FetchType enum could make sure the value passed in makes sense.

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 guess this makes sense. I updated it to create a new method that isn't so closely tied to Realtime.

@@ -337,6 +337,22 @@ public void fetchWithExpiration_cacheHasNotExpired_doesNotFetchFromBackend() thr
verifyBackendIsNeverCalled();
}

@Test
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice realtime tests! 😄 Mind splitting the ones that aren't for the fetch id into their own PR to make this a bit easier to review? Also, I'm not sure I see a test for the header being set?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed and will move to a separate PR

@qdpham13 qdpham13 requested a review from danasilver November 22, 2022 20:34
@qdpham13 qdpham13 changed the title Realtime Fetch Id Realtime Fetch ID Nov 23, 2022
* @return A {@link Task} representing an immediate fetch call that returns a {@link
* FetchResponse} with the configs fetched from the backend. If the backend was not called or
* the backend had no updates, the {@link FetchResponse}'s configs will be {@code null}.
* FetchType and fetchAttemptNumber help detail what started the fetch call.
Copy link
Contributor

Choose a reason for hiding this comment

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

This line would make more sense in a @params comment rather than @return

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated.

@@ -626,4 +691,14 @@ public ConfigContainer getFetchedConfigs() {
int LOCAL_STORAGE_USED = 2;
}
}

public enum FetchType {
BASE,
Copy link
Contributor

Choose a reason for hiding this comment

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

The enum value can be stored in an instance field, which is more clear to read and makes it independent of the enum itself, i.e.

BASE("Base"),
...

private final int value;

FetchType(value) {
  this.value = value;
}

String getValue() {
  return value;
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated.

@qdpham13 qdpham13 merged commit c335504 into realtime-rc-merge Dec 1, 2022
@qdpham13 qdpham13 deleted the realtime-rc-fetch-id branch December 1, 2022 01:01
danasilver pushed a commit that referenced this pull request Dec 20, 2022
* Create overloaded fetch method specifically for realtime and add custom headers

* Add comments for vars

* Update header name

* Change realtimeFetch name and params

* Remove fetchHandler tests and move them to seperate PR

* Remove unused vars and revert tests

* Format tests

* Add comments

* Format files
@firebase firebase locked and limited conversation to collaborators Dec 31, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants