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

[ENH] Add an init method that eagerly reports errors with the tenant or DB #2537

Merged
merged 2 commits into from
Jul 19, 2024

Conversation

AlabasterAxe
Copy link
Contributor

@AlabasterAxe AlabasterAxe commented Jul 18, 2024

Description of changes

This PR puts some initialization work in an init function, and then awaits that work in every async method so that those issues are reported to callers regardless of which call they make.

Test plan

How are these changes tested?

  • Tests pass locally with pytest for python, yarn test for js, cargo test for rust

Documentation Changes

Are all docstrings for user-facing APIs updated if required? Do we need to make documentation changes in the docs repository?

Copy link

Reviewer Checklist

Please leverage this checklist to ensure your code review is thorough before approving

Testing, Bugs, Errors, Logs, Documentation

  • Can you think of any use case in which the code does not behave as intended? Have they been tested?
  • Can you think of any inputs or external events that could break the code? Is user input validated and safe? Have they been tested?
  • If appropriate, are there adequate property based tests?
  • If appropriate, are there adequate unit tests?
  • Should any logging, debugging, tracing information be added or removed?
  • Are error messages user-friendly?
  • Have all documentation changes needed been made?
  • Have all non-obvious changes been commented?

System Compatibility

  • Are there any potential impacts on other parts of the system or backward compatibility?
  • Does this change intersect with any items on our roadmap, and if so, is there a plan for fitting them together?

Quality

  • Is this code of a unexpectedly high quality (Readability, Modularity, Intuitiveness)

@@ -74,10 +74,6 @@ export class AdminClient {
...this.api.options.headers,
...this.authProvider.authenticate(),
};
this.api.options.headers = {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

These lines are exactly the same as the four above so should have no effect, I think.

expect(version).toMatch(/^[0-9]+\.[0-9]+\.[0-9]+$/);
});

test("it should get the heartbeat without auth needed", async () => {
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 because the validation logic fails the auth check.

Copy link
Contributor

Choose a reason for hiding this comment

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

maybe we should keep these routes unprotected if there's test cases making these assertions?

cloudPort: PORT,
cloudHost: "http://localhost",
});
export const chromaBasic = () =>
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've changed these to be factory methods because it seems like there is a race condition between when these are constructed and when the tenant/database becomes available. If we initialize the client in the test, the tenant and database exist by that point and the validation check succeeds.

An alternative approach here would be to always validate before every call but that seems like a lot of unnecessary overhead only to catch the IMO rare case that either the database and tenant are being created simultaneously with the client or the database / tenant is being deleted, in which case, the requests will start failing anyway.

@@ -1,5 +1,3 @@
version: '3.9'
Copy link
Contributor Author

Choose a reason for hiding this comment

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

according to the logs when running the tests, "version is obsolete"

Comment on lines +16 to +24
export const chromaTokenBearer = () =>
new ChromaClient({
path: URL,
auth: {
provider: "token",
credentials: "test-token",
tokenHeaderType: "AUTHORIZATION",
},
});
Copy link
Contributor Author

Choose a reason for hiding this comment

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

It looks like the token header type was dropped off of this config in the previous PR but let me know if this configuration is no longer necessary:

https://github.com/chroma-core/chroma/pull/1970/files#diff-a6a9add9fb7cdb9cd98f93430b5c049f2352f497ac1213141f05dc3cc473cb3bL19

Copy link
Contributor

@codetheweb codetheweb left a comment

Choose a reason for hiding this comment

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

lgtm outside of comments

@AlabasterAxe
Copy link
Contributor Author

Okay, I've stopped calling the validation function for the version and heartbeat methods and switched to calling the validation function lazily so that we don't wind up with an unhandle exception in the case that the user is calling methods that don't require the tenant and database to exist.

Copy link
Contributor

@codetheweb codetheweb left a comment

Choose a reason for hiding this comment

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

looks great! good to go after checks pass

edit: I think the go tests are being flaky? I triggered a re-run

@codetheweb codetheweb merged commit 63207d5 into chroma-core:main Jul 19, 2024
65 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants