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

[RSPEED-427] Add systems endpoint #14

Merged
merged 1 commit into from
Jan 17, 2025

Conversation

hosekadam
Copy link
Contributor

@hosekadam hosekadam commented Jan 15, 2025

Add endpoint for returning RHEL systems start/end dates

TODO:

  • create the unit tests more complex - just tried how them works
  • comment the code
  • improve the endpoints using some FastAPI features, I just basically test how this works

@codecov-commenter
Copy link

codecov-commenter commented Jan 15, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 89.39%. Comparing base (4d551b0) to head (2e8f957).
Report is 4 commits behind head on develop.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop      #14      +/-   ##
===========================================
+ Coverage    80.82%   89.39%   +8.57%     
===========================================
  Files            9       17       +8     
  Lines           73      132      +59     
===========================================
+ Hits            59      118      +59     
  Misses          14       14              
Flag Coverage Δ
unittests 89.39% <100.00%> (+8.57%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

@samdoran samdoran left a comment

Choose a reason for hiding this comment

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

Looking good so far!

Makefile Outdated Show resolved Hide resolved
app/v1/lifecycle/systems/endpoints.py Outdated Show resolved Hide resolved
@hosekadam hosekadam force-pushed the add-systems-endpoint branch from 5dab81d to 25c0548 Compare January 17, 2025 11:41
@hosekadam hosekadam marked this pull request as ready for review January 17, 2025 11:43
.pre-commit-config.yaml Outdated Show resolved Hide resolved
@hosekadam hosekadam force-pushed the add-systems-endpoint branch from 25c0548 to cbc7fdf Compare January 17, 2025 19:02
v1_router = APIRouter()


@v1_router.get("/systems")
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: REST API endpoints should have a trailing slash. Resources can omit the trailing slash (such as a request with path parameters).

This is a highly contentious topic and that's just my opinion.

Internally, FastAPI registers both routes (with and without a trailing slash) and issues a 307 redirect to get to real endpoint.

Add endpoint for returning RHEL systems start/end dates
@hosekadam hosekadam force-pushed the add-systems-endpoint branch from cbc7fdf to 2e8f957 Compare January 17, 2025 20:35

@v1_router.get("/systems/{major}")
async def get_systems_major(major: int = Path(..., description="Major version number")):
systems = get_systems_data(major)
Copy link
Contributor

Choose a reason for hiding this comment

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

This is a call to a sync function from an async function. I need to look into this more, but I think this blocks the event loop.

I think the correct way to call sync code from within async code is to use the default event loop with a Future object.

Suggested change
systems = get_systems_data(major)
loop = asyncio.get_running_loop()
systems = await loop.run_in_executor(None, get_systems_data(major))

This isn't a problem currently because the blocking sync code is fast. But for a real IO or CPU bound operation, this could cause perceptible performance degradation.

Comment on lines +24 to +25
major: int = Path(..., description="Major version number"),
minor: int = Path(..., description="Minor version number"),
Copy link
Contributor

@samdoran samdoran Jan 17, 2025

Choose a reason for hiding this comment

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

A better way to handle this is to use Annotated.

Suggested change
major: int = Path(..., description="Major version number"),
minor: int = Path(..., description="Minor version number"),
import typing as t
major: t.Annotated[int, Path(description="Major version number", ge=8, le=10)],
minor: t.Annotated[int, Path(description="Minor version number", ge=0, le=99)],

It's also unnecessary to pass the ellipsis to Path.

@samdoran samdoran merged commit e71efb1 into RedHatInsights:develop Jan 17, 2025
4 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.

3 participants