Skip to content
This repository has been archived by the owner on Jul 12, 2023. It is now read-only.

Ping db on health instead of opening new connection #1503

Merged
merged 1 commit into from
Jan 4, 2021

Conversation

sethvargo
Copy link
Member

The previous logic relied on creating a new database connection. This would be a different database connection from the one the rest of the app is using, and could lead to false successes. This changes the health endpoint to use the same db that the other handlers use.

Additionally, since it's just a ping now (instead of a full config parsing), the limit is increased from 1/min to 1/sec. The response code when the limit is exceeded is now a 429 instead of silently falling through to 200.

Finally, the monitoring uptime checks are updated to use this endpoint instead of the generic /health. It's safe to say that the service is "down" if it cannot connect to the database.

Release Note

Ping db on /health instead of opening new connection

/assign @yegle
/assign @whaught

The previous logic relied on creating a new database connection. This
would be a different database connection from the one the rest of the
app is using, and could lead to false successes. This changes the health
endpoint to use the same db that the other handlers use.

Additionally, since it's just a ping now (instead of a full config
parsing), the limit is increased from 1/min to 1/sec. The response code
when the limit is exceeded is now a 429 instead of silently falling
through to 200.

Finally, the monitoring uptime checks are updated to use this endpoint
instead of the generic /health. It's safe to say that the service is
"down" if it cannot connect to the database.
@google-oss-robot
Copy link

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: sethvargo

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@googlebot googlebot added the cla: yes Auto: added by CLA bot when all committers have signed a CLA. label Jan 4, 2021
@whaught
Copy link
Contributor

whaught commented Jan 4, 2021

/lgtm

Maybe I'm lacking context of history, but I wonder why we were opening a connection here in the first place: your code looks a lot more like the rest of the service.

@google-oss-robot google-oss-robot merged commit 58d5cc0 into main Jan 4, 2021
@google-oss-robot google-oss-robot deleted the sethvargo/healthdb branch January 4, 2021 17:16
@sethvargo
Copy link
Member Author

I couldn't think of any reason nor could I find anything in the commits on that file. I suspect we wrote that before config parsing and config loading were separate functions?

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 6, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
cla: yes Auto: added by CLA bot when all committers have signed a CLA.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants