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

DPL-058-01: Versioned API #392

Merged
merged 9 commits into from
Jul 21, 2021
Merged

DPL-058-01: Versioned API #392

merged 9 commits into from
Jul 21, 2021

Conversation

sdjmchattie
Copy link
Contributor

@sdjmchattie sdjmchattie commented Jul 20, 2021

Closes: #394

Decided it was best to start with the Crawler API since it's much smaller and lets us focus on the architecture of the solution. The V1 blueprint is the only one at the moment and gets served at both https://crawler-url.sanger/cherrypick-test-data and also at https://crawler-url.sanger/v1/cherrypick-test-data.

In practice I will update the URL being used by Lighthouse and then I'll drop the unversioned endpoint.

When adding a /v2/ API, the common logic for the existing endpoint can go in another module that isn't decorated. Each of the two blueprints (v1 and v2) can then call that common module to keep things clean. If the new endpoint is significantly different, then the logic flow can be directed as needed from these blueprints.

@codecov
Copy link

codecov bot commented Jul 20, 2021

Codecov Report

Merging #392 (df80b90) into develop (44daa62) will increase coverage by 0.02%.
The diff coverage is 100.00%.

Impacted file tree graph

@@             Coverage Diff             @@
##           develop     #392      +/-   ##
===========================================
+ Coverage    88.24%   88.26%   +0.02%     
===========================================
  Files           38       39       +1     
  Lines         2723     2728       +5     
  Branches       318      318              
===========================================
+ Hits          2403     2408       +5     
  Misses         280      280              
  Partials        40       40              
Impacted Files Coverage Δ
crawler/routes/common/cherrypicker_test_data.py 100.00% <100.00%> (ø)
crawler/routes/v1/routes.py 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 44daa62...df80b90. Read the comment docs.

Copy link
Contributor

@pjvv pjvv left a comment

Choose a reason for hiding this comment

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

Nice and clean! I understand the reasoning behind starting in crawler but we were more concerned about versioning APIs which we don't consume ourselves - the few in lighthouse are the most pertinent. When we consume our own APIs we can usually make any required changes in the calling services. I prefer the structure from the stackoverflow post (using routes.py etc.) in the lighthouse issue, what did you think of that structure?

README.md Show resolved Hide resolved
crawler/__init__.py Show resolved Hide resolved
from crawler.blueprints.v1 import cherrypicker_test_data as cptd_v1

app.register_blueprint(cptd_v1.bp, url_prefix="/v1")
app.register_blueprint(cptd_v1.bp) # Also serve v1 at the root of the host for now
Copy link
Contributor

Choose a reason for hiding this comment

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

I think it's worth making the change in lighthouse now to prevent this TODO kicking around for too long.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will do ... I just need to make that update in another branch then this will be coming out immediately

dependencies/down.sh Show resolved Hide resolved
tests/blueprints/v1/test_cherrypicker_data_blueprint.py Outdated Show resolved Hide resolved
pjvv
pjvv previously approved these changes Jul 21, 2021
@sdjmchattie sdjmchattie changed the title DPL-058: Versioned API DPL-058-01: Versioned API Jul 21, 2021
harrietc52
harrietc52 previously approved these changes Jul 21, 2021
Copy link
Contributor

@harrietc52 harrietc52 left a comment

Choose a reason for hiding this comment

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

Looks good, only thought is the use of "cherrypicker", could it be "cherrypick" to be consistent?

yield process


@pytest.mark.parametrize("json", [{}, {"run_id": None}])
def test_generate_endpoint_invalid_json(json, client, logger_messages):
response = client.post("/cherrypick-test-data", json=json)
@pytest.mark.parametrize("endpoint_path", ENDPOINT_PATHS)
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this post to both root and v1 endpoints?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes they both get tested. Of course they should be identical, but I will be removing the root endpoint as soon as I've changed Lighthouse and I'll strip this back to just the v1 endpoint in the test.

@sdjmchattie sdjmchattie dismissed stale reviews from harrietc52 and pjvv via df80b90 July 21, 2021 13:54
@sdjmchattie
Copy link
Contributor Author

Looks good, only thought is the use of "cherrypicker", could it be "cherrypick" to be consistent?

Thanks @harrietc52 . I think I'll not rename it at this stage. It's been cherrypicker in the module names since just after I started working on Crawler and not relevant to the change I'm making here. The endpoints are at least cherrypick-test-data. I didn't know enough about the naming preferences when I started a couple weeks back.

@sdjmchattie sdjmchattie merged commit b465b26 into develop Jul 21, 2021
@sdjmchattie sdjmchattie deleted the dpl-058-versioned-api branch July 21, 2021 14:06
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.

DPL-058-01 Add endpoint versioning
3 participants