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

Implement heartbeat controller #5723

Merged
merged 16 commits into from
Feb 24, 2022
Merged

Implement heartbeat controller #5723

merged 16 commits into from
Feb 24, 2022

Conversation

hsubox76
Copy link
Contributor

@hsubox76 hsubox76 commented Nov 11, 2021

Implement heartbeat controller.

Design doc (internal): go/firebasejssdk-heartbeat

@changeset-bot
Copy link

changeset-bot bot commented Nov 11, 2021

🦋 Changeset detected

Latest commit: 3125e64

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 3 packages
Name Type
@firebase/app Patch
@firebase/app-compat Patch
firebase Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@google-cla google-cla bot added the cla: yes label Nov 11, 2021
@google-oss-bot
Copy link
Contributor

google-oss-bot commented Nov 12, 2021

Size Report 1

Affected Products

  • @firebase/app

    TypeBase (13c0895)Merge (7c52a89)Diff
    browser7.74 kB13.9 kB+6.16 kB (+79.6%)
    esm59.37 kB18.8 kB+9.40 kB (+100.3%)
    main10.2 kB19.7 kB+9.54 kB (+93.4%)
    module7.74 kB13.9 kB+6.16 kB (+79.6%)
  • bundle

    43 size changes

    TypeBase (13c0895)Merge (7c52a89)Diff
    analytics (logEvent)34.7 kB41.8 kB+7.10 kB (+20.5%)
    app-check (CustomProvider)27.4 kB35.7 kB+8.26 kB (+30.2%)
    app-check (ReCaptchaEnterpriseProvider)29.6 kB37.9 kB+8.26 kB (+27.9%)
    app-check (ReCaptchaV3Provider)29.6 kB37.8 kB+8.26 kB (+27.9%)
    auth (Anonymous)56.9 kB65.3 kB+8.32 kB (+14.6%)
    auth (EmailAndPassword)61.0 kB69.3 kB+8.32 kB (+13.6%)
    auth (GoogleFBTwitterGitHubPopup)80.8 kB89.1 kB+8.32 kB (+10.3%)
    auth (GooglePopup)80.5 kB88.9 kB+8.32 kB (+10.3%)
    auth (GoogleRedirect)80.7 kB89.1 kB+8.32 kB (+10.3%)
    auth (Phone)67.0 kB75.3 kB+8.32 kB (+12.4%)
    database (Append to a list of data)137 kB146 kB+8.29 kB (+6.0%)
    database (Filtering data)136 kB144 kB+8.29 kB (+6.1%)
    database (Listen for child events)152 kB160 kB+8.29 kB (+5.4%)
    database (Listen for value events + Detach listeners)152 kB160 kB+8.29 kB (+5.4%)
    database (Listen for value events)152 kB160 kB+8.29 kB (+5.5%)
    database (Read data once)144 kB152 kB+8.29 kB (+5.8%)
    database (Save data as transactions)154 kB162 kB+8.29 kB (+5.4%)
    database (Sort data)138 kB146 kB+8.29 kB (+6.0%)
    database (Write data)136 kB145 kB+8.29 kB (+6.1%)
    firestore (Persistence)252 kB263 kB+11.3 kB (+4.5%)
    firestore (Query Cursors)192 kB203 kB+11.3 kB (+5.9%)
    firestore (Query)193 kB204 kB+11.3 kB (+5.9%)
    firestore (Read data once)181 kB193 kB+11.3 kB (+6.2%)
    firestore (Realtime updates)184 kB195 kB+11.3 kB (+6.2%)
    firestore (Transaction)166 kB177 kB+11.3 kB (+6.8%)
    firestore (Write data)165 kB177 kB+11.3 kB (+6.8%)
    firestore-lite (Query Cursors)56.9 kB68.3 kB+11.3 kB (+19.9%)
    firestore-lite (Query)60.0 kB71.3 kB+11.3 kB (+18.9%)
    firestore-lite (Read data once)44.5 kB55.8 kB+11.3 kB (+25.4%)
    firestore-lite (Transaction)61.8 kB73.1 kB+11.3 kB (+18.3%)
    firestore-lite (Write data)47.3 kB58.6 kB+11.3 kB (+23.9%)
    functions (call)18.3 kB29.6 kB+11.3 kB (+62.0%)
    messaging (send + receive)37.8 kB44.9 kB+7.10 kB (+18.8%)
    performance (trace)42.3 kB49.4 kB+7.10 kB (+16.8%)
    remote-config (getAndFetch)36.7 kB44.1 kB+7.47 kB (+20.4%)
    storage (getBytes)26.6 kB37.9 kB+11.3 kB (+42.5%)
    storage (getDownloadURL)28.7 kB40.0 kB+11.3 kB (+39.5%)
    storage (getMetadata)28.1 kB39.4 kB+11.3 kB (+40.2%)
    storage (list + listAll)27.5 kB38.9 kB+11.3 kB (+41.1%)
    storage (updateMetadata)28.4 kB39.7 kB+11.3 kB (+39.9%)
    storage (uploadBytes)32.9 kB44.3 kB+11.3 kB (+34.4%)
    storage (uploadBytesResumable)42.4 kB53.7 kB+11.3 kB (+26.7%)
    storage (uploadString)33.1 kB44.5 kB+11.3 kB (+34.1%)

  • firebase

    TypeBase (13c0895)Merge (7c52a89)Diff
    firebase-app-compat.js17.9 kB28.2 kB+10.3 kB (+57.6%)
    firebase-app.js51.4 kB84.2 kB+32.7 kB (+63.6%)
    firebase-compat.js775 kB779 kB+3.72 kB (+0.5%)
    firebase-performance-standalone-compat.es2017.js78.9 kB87.5 kB+8.60 kB (+10.9%)
    firebase-performance-standalone-compat.js57.0 kB65.7 kB+8.66 kB (+15.2%)

Test Logs

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

@google-oss-bot
Copy link
Contributor

google-oss-bot commented Nov 12, 2021

Size Analysis Report 1

This report is too large (193,683 characters) to be displayed here in a GitHub comment. Please use the below link to see the full report on Google Cloud Storage.

Test Logs

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

@hsubox76 hsubox76 changed the title WIP: Implement heartbeat controller Implement heartbeat controller Nov 15, 2021
reject((event.target as IDBRequest).error?.message);
};

request.onupgradeneeded = event => {
Copy link
Member

Choose a reason for hiding this comment

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

You'd want this callback to be provided by the users of this utility class because the upgrade logic varies from use case to use case, and thus can't be generalized.

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 in favor of using idb.

* limitations under the License.
*/

export class IndexedDbDatabaseService {
Copy link
Member

Choose a reason for hiding this comment

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

It might be worth considering using the idb library which is tiny and provides the convenient APIs instead of rolling our own solution.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

*/
heartbeatsCachePromise: Promise<HeartbeatsByUserAgent[]>;

/**
Copy link
Member

Choose a reason for hiding this comment

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

The comments are still useful.

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 put the comments on the class itself, do they need to be in both places?

Copy link
Member

Choose a reason for hiding this comment

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

I think so. The consumer of the component will only look at the interface definition.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Restored.

packages/app/src/heartbeatService.ts Outdated Show resolved Hide resolved
@Feiyang1 Feiyang1 assigned hsubox76 and unassigned Feiyang1 Nov 30, 2021
@hsubox76 hsubox76 assigned Feiyang1 and unassigned hsubox76 Dec 3, 2021
@allspain allspain self-requested a review December 6, 2021 23:04
@hsubox76 hsubox76 assigned allspain and unassigned Feiyang1 Dec 6, 2021
await heartbeatService.triggerHeartbeat();
expect(heartbeatService._heartbeatsCache?.length).to.equal(1);
const heartbeat1 = heartbeatService._heartbeatsCache?.[0];
expect(heartbeat1?.userAgent).to.equal('vs1/1.2.3 vs2/2.3.4');
Copy link

Choose a reason for hiding this comment

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

For hardcoded strings we expect to match do we typically enter than as raw compares rather than define them as constants at the top of the file?

This isn't a neccesary change, the ROI might be low but it would reduce typo mistakes

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, changed.

const monthString = month < 10 ? '0' + month : month.toString();
const date = today.getUTCDate();
const dayString = date < 10 ? '0' + date : date.toString();
return `${yearString}-${monthString}-${dayString}`;
Copy link

Choose a reason for hiding this comment

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

If you want to get rid of the custom logic here you could just do:

today.toISOString().substring(0,10)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks! Changed.

@allspain allspain removed their assignment Dec 7, 2021
@hsubox76 hsubox76 merged commit 1588990 into master Feb 24, 2022
@hsubox76 hsubox76 deleted the ch-heartbeat branch February 24, 2022 18:34
@google-oss-bot google-oss-bot mentioned this pull request Mar 3, 2022
@firebase firebase locked and limited conversation to collaborators Mar 27, 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.

4 participants