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

Additional service checks for ingestion server health endpoint #3590

Merged
merged 5 commits into from
Jan 17, 2024

Conversation

AetherUnbound
Copy link
Collaborator

@AetherUnbound AetherUnbound commented Dec 26, 2023

Fixes

Fixes #2019 by @sarayourfriend

Description

This PR adds checks for Elasticsearch and both databases to the ingestion server health check endpoint behind the check_deps query parameter. This also refactors the database connection into a db_helpers module similar to the es_helpers one that already exists. This helped simplify some of the code and centralize where the database connection logic was being defined.

The failed response has a status field with a list of possible failures due to the number of upstream services to be checked. If there's a better way to structure that, let me know!

Testing Instructions

  1. just i to start the stack
  2. Run curl -L http://localhost:50281/ and verify the output is {"status": "200 OK"}
  3. Run curl -L http://localhost:50281/?check_deps=true and verify the output is {"status": "200 OK"}
  4. Run docker stop openverse-db-1 openverse-es-1 openverse-upstream_db-1 to simulate the resources becoming unavailable
  5. Run curl -L http://localhost:50281/ and verify the output is {"status": "200 OK"} (unaffected)
  6. Run curl -L http://localhost:50281/?check_deps=true and verify the output is {"status": "503 Service Unavailable", "dependencies": {"es": ["Elasticsearch could not be reached"], "db": ["Database connection for 'upstream' could not be established", "Database connection for 'api' could not be established"]}} (error messages shown)

Checklist

  • My pull request has a descriptive title (not a vague title likeUpdate index.md).
  • My pull request targets the default branch of the repository (main) or a parent feature branch.
  • My commit messages follow best practices.
  • My code follows the established code style of the repository.
  • I added or updated tests for the changes I made (if applicable).
  • I added or updated documentation (if applicable).
  • I tried running the project locally and verified that there are no visible errors.
  • I ran the DAG documentation generator (if applicable).

Developer Certificate of Origin

Developer Certificate of Origin
Developer Certificate of Origin
Version 1.1

Copyright (C) 2004, 2006 The Linux Foundation and its contributors.
1 Letterman Drive
Suite D4700
San Francisco, CA, 94129

Everyone is permitted to copy and distribute verbatim copies of this
license document, but changing it is not allowed.


Developer's Certificate of Origin 1.1

By making a contribution to this project, I certify that:

(a) The contribution was created in whole or in part by me and I
    have the right to submit it under the open source license
    indicated in the file; or

(b) The contribution is based upon previous work that, to the best
    of my knowledge, is covered under an appropriate open source
    license and I have the right under that license to submit that
    work with modifications, whether created in whole or in part
    by me, under the same open source license (unless I am
    permitted to submit under a different license), as indicated
    in the file; or

(c) The contribution was provided directly to me by some other
    person who certified (a), (b) or (c) and I have not modified
    it.

(d) I understand and agree that this project and the contribution
    are public and that a record of the contribution (including all
    personal information I submit with it, including my sign-off) is
    maintained indefinitely and may be redistributed consistent with
    this project or the open source license(s) involved.

@AetherUnbound AetherUnbound requested a review from a team as a code owner December 26, 2023 23:29
@github-actions github-actions bot added the 🧱 stack: ingestion server Related to the ingestion/data refresh server label Dec 26, 2023
@openverse-bot openverse-bot added 🟨 priority: medium Not blocking but should be addressed soon ✨ goal: improvement Improvement to an existing user-facing feature 💻 aspect: code Concerns the software code in the repository labels Dec 26, 2023
Copy link
Collaborator

@sarayourfriend sarayourfriend left a comment

Choose a reason for hiding this comment

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

This LGTM, it would be nice to add unit tests, though.

I know I opened the issue... but I was initially a little sceptical about whether this is actually needed. We never ended up using the API healthcheck features. But I've got the answer wrong, really. After adding these, we should go back and actually start using the API and these ones somewhere, maybe in the load balancer healthcheck for the API, and we can update the ingestion server healthcheck playbook to use these new parameters (not sure where else we actually use the ingestion server healthcheck).

@openverse-bot
Copy link
Collaborator

Based on the medium urgency of this PR, the following reviewers are being gently reminded to review this PR:

@obulat
@dhruvkb
This reminder is being automatically generated due to the urgency configuration.

Excluding weekend1 days, this PR was ready for review 13 day(s) ago. PRs labelled with medium urgency are expected to be reviewed within 4 weekday(s)2.

@AetherUnbound, if this PR is not ready for a review, please draft it to prevent reviewers from getting further unnecessary pings.

Footnotes

  1. Specifically, Saturday and Sunday.

  2. For the purpose of these reminders we treat Monday - Friday as weekdays. Please note that the operation that generates these reminders runs at midnight UTC on Monday - Friday. This means that depending on your timezone, you may be pinged outside of the expected range.

Copy link
Member

@dhruvkb dhruvkb left a comment

Choose a reason for hiding this comment

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

Functionally LGTM. In terms of the schema of the response, status as a collection of message strings feels a bit unstructured. This is my suggestion for a bit more structured (albeit verbose) way of conveying the info.

interface Response {
  status: "200 OK" | "503 Service Unavailable"
  dependencies: { // only if `check_deps=true`
    es: {
      isOk: boolean
      messages: string[]
    },
    // ...
  }
}

@AetherUnbound AetherUnbound force-pushed the feature/ingestion-server-health-checks branch from 327dbbf to 72263b3 Compare January 17, 2024 00:52
@AetherUnbound
Copy link
Collaborator Author

AetherUnbound commented Jan 17, 2024

Thanks for the suggestion @dhruvkb! I updated the response to the following, since the presence of the dependency in the response should indicate whether or not it's OK:

interface Response {
  status: "200 OK" | "503 Service Unavailable"
  dependencies: { // only if `check_deps=true`
    es: string[], // only if es problems
    db: string[]  // only if db problems
  }
}

@AetherUnbound AetherUnbound merged commit b1a1f6e into main Jan 17, 2024
39 checks passed
@AetherUnbound AetherUnbound deleted the feature/ingestion-server-health-checks branch January 17, 2024 01:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
💻 aspect: code Concerns the software code in the repository ✨ goal: improvement Improvement to an existing user-facing feature 🟨 priority: medium Not blocking but should be addressed soon 🧱 stack: ingestion server Related to the ingestion/data refresh server
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Add additional checks to ingestion server healthcheck endpoint
4 participants