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

refactor(api): refactor purl API query code #2900

Open
wants to merge 9 commits into
base: master
Choose a base branch
from

Conversation

hogo6002
Copy link
Contributor

Converted PURL queries to package queries in do_query() to remove unnecessary code. Querying the Datastore directly with PURLs gives the same results as querying by package name, so we can simplify things by treating PURLs like regular package queries after extracting the package/ecosystem/version.

This will also resolve issue #2842 by rewriting the PURL-to-ecosystem logic. For most ecosystems, we can get the name from purl.type, but for Linux distributions, we need to use purl.namespace.

Copy link
Contributor

@andrewpollock andrewpollock left a comment

Choose a reason for hiding this comment

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

Nice simplification!

osv/purl_helpers.py Outdated Show resolved Hide resolved
Copy link
Member

@michaelkedar michaelkedar left a comment

Choose a reason for hiding this comment

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

Nice!

osv/purl_helpers.py Outdated Show resolved Hide resolved
osv/purl_helpers.py Outdated Show resolved Hide resolved
Copy link
Collaborator

@oliverchang oliverchang left a comment

Choose a reason for hiding this comment

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

very nice! Is there a way we can do some kind of testing to make sure we're not introducing any regressions on matching behaviour?

i.e. some kind of comprehensive comparison between test (with this deployed) and prod (without this deployed) for specific ecosystems?

osv/purl_helpers.py Outdated Show resolved Hide resolved
@hogo6002
Copy link
Contributor Author

very nice! Is there a way we can do some kind of testing to make sure we're not introducing any regressions on matching behaviour?

We have integration tests for the API (LONG_TESTS), which I have manually checked. These tests do not produce any 500 errors. Also, after checking in the test instance, it will be tested by performance testing, and I will monitor for any new 500 errors. I think this change should be safe.

'200:{"commit": "d374094d8c49b6b7d288f307e11217ec5a502391", "package": {"purl": "pkg:pypi/[email protected]", "version": "0.8.5"}}\n',
'200:{"commit": "d374094d8c49b6b7d288f307e11217ec5a502391", "package": {"purl": "pkg:pypi/[email protected]"}}\n',
'200:{"commit": "d374094d8c49b6b7d288f307e11217ec5a502391", "package": {"version": "0.8.5"}}\n',
[ '400:{"commit": "d374094d8c49b6b7d288f307e11217ec5a502391", "package": '
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This long test has been skipped and hasn't been updated in a long time (it is also failing for the master branch). The script is generated using the command TESTS_GENERATE=1. Most of the 400 failures are caused by querying both the PURL and package name at the same time, which is invalid.

We could also re-enable long tests on the pipeline (run after merge), it doesn't run too long (maybe 1 min)

gcp/api/server.py Show resolved Hide resolved
gcp/api/server.py Show resolved Hide resolved
gcp/api/server.py Outdated Show resolved Hide resolved
osv/purl_helpers.py Outdated Show resolved Hide resolved
osv/purl_helpers.py Outdated Show resolved Hide resolved
osv/purl_helpers.py Outdated Show resolved Hide resolved
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.

5 participants