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

feat: health check - can connect to firestore #97

Merged
merged 1 commit into from
Jul 25, 2023

Conversation

subfuzion
Copy link
Member

Adds a health check GET endpoint that confirms app can connect to Firestore: /api/fscheck
The endpoint returns either an HTTP 200 or 503.

@subfuzion subfuzion requested review from a team as code owners July 25, 2023 21:20
@github-actions github-actions bot added type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design. component: app labels Jul 25, 2023
@subfuzion subfuzion requested a review from rogerthatdev July 25, 2023 21:21
@pattishin pattishin self-requested a review July 25, 2023 22:08
@rogerthatdev rogerthatdev merged commit c9345be into main Jul 25, 2023
@rogerthatdev rogerthatdev deleted the feat/firestore-connected-check branch July 25, 2023 23:23
Copy link
Contributor

@pattishin pattishin left a comment

Choose a reason for hiding this comment

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

Hi Tony, was just browsing through and I understand this was already submitted, but wanted to revisit. Just a suggestion, thoughts on swapping out using Promise.race and setTimeout (in src/lib/database.ts) and leverage setInterval? So you can poll this.db.listCollections a certain amount of times rather than giving an arbitrary number for the db to race against? That path could tighten up your isConnected function.

// eslint-disable-next-line no-undef
let timerId: NodeJS.Timeout;

const timer = new Promise<boolean>((resolve) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

If you are keeping setTimeout, could you add a unit test or 2 to ensure this is working as expected would be nice. Make sure edgecases are handled.

Copy link
Member Author

@subfuzion subfuzion Jul 26, 2023

Choose a reason for hiding this comment

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

Not sure I understand. No need to poll; if listCollections resolves first, it "wins" the race and the function returns. Are you saying you'd like to have a certain number of retries, or perhaps exponential backoff or something? Originally @rogerthatdev said he was happy with the API's default timeout (60s); that just seemed a bit too long, so I parameterized it. If you think there's a need for retries, do you mind opening an issue?

Copy link
Contributor

@pattishin pattishin Jul 26, 2023

Choose a reason for hiding this comment

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

Or for sure, will file one 👍🏼 Also I know I'm coming in from left-field a bit - ty for the explanation 🎊

});

} catch (err) {
// GoogleError: Total timeout of API google.firestore.v1.Firestore
Copy link
Contributor

Choose a reason for hiding this comment

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

Not a fan of silent errors. Anyway to capture the errors rather than just seeing isConnected returned false.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, I thought about that. Bottom line is it's not healthy yet. If not the expected error, it could be logged if this turns out to be problematic.

Copy link
Contributor

Choose a reason for hiding this comment

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

Mind if I file an issue for this as well to do a revisit?

) {
const fs = new Database();
let isConnected = await fs.isConnected();
let statusCode = isConnected ? 200 : 503;
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: could this possibly return some information about the firestore and if errors were emitted that could get bundled in like:

{
   status: 503,
   error: {...} // Emitted error after polling is completed without firestore connection
}

Copy link
Member Author

Choose a reason for hiding this comment

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

Hmm, not sure I really see a need for this. This is specifically what the fscheck health check checks; either it can connect (200) or it can't (503). I even considered just doing this as a HEAD request, but figured a GET might be easier for some callers to check. If you think more is needed, please open an issue.

Copy link
Contributor

Choose a reason for hiding this comment

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

Can do 👍🏼

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: app type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants