-
Notifications
You must be signed in to change notification settings - Fork 175
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
feat(system-server): add sqlite database and barebones HTTP server #12085
Conversation
Codecov Report
@@ Coverage Diff @@
## edge #12085 +/- ##
==========================================
- Coverage 74.48% 73.97% -0.51%
==========================================
Files 2180 2211 +31
Lines 59867 61071 +1204
Branches 6467 6477 +10
==========================================
+ Hits 44589 45176 +587
- Misses 13747 14358 +611
- Partials 1531 1537 +6
Flags with carried forward coverage won't be shown. Click here to find out more.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks solid to me!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Exciting! Various bits of feedback learned from robot-server
lessons.
persistence_directory = await get_persistence_directory(app.state) | ||
await get_sql_engine(app.state, persistence_directory) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we should call get_persistence_directory()
and get_sql_engine()
like this.
In robot-server
, where these function's definitions are copied from, these aren't normal functions—they're FastAPI dependency functions.
We need to draw a bright line between the two kinds of function and treat them as mutually exclusive. When you call a FastAPI dependency function as if it were a normal function, it's very easy to accidentally subvert static type safety and cause confusing breakage. This is a FastAPI trap that we (and others) have been bitten by before—see #8051.
In principle, I think eagerly initializing the database is the right thing to do, and we're moving in this direction in robot-server (#11615). But our code for this in robot-server is a highly-duplicated mess right now, so I don't think we have a good model for eager initialization just yet.
For the short term, what do you think about doing the default FastAPI thing and let the database be initialized lazily for the first HTTP request that requires it? We got away with that in robot-server for a while.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah that makes sense even if it makes me Big Sad.
I'm gonna add a fake little endpoint that depends on the database so it's possible to test the db generation.
Co-authored-by: Max Marrone <[email protected]>
…pentrons/opentrons into RCORE-508_system_server_sqlite
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with all of Max's feedback. I also have some specific feedback on the tests added in test_persistent_generation
assert not expected.exists() | ||
|
||
|
||
async def test_create_tmpdir(monkeypatch: MonkeyPatch, tmpdir: Path) -> None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
IMO this test inappropriately mixes mocking, implementation details, and logic testing. It'll likely be brittle over time and doesn't really test that things work, due to the mocks. It also brings in the entire world of FastAPI.
I recommend restructuring this so that the question "is it going to the expected directory?" is tested without mocks. For example, the suite could have:
- Test that checks the settings module has the correct directory value
- Test that checks the persistence module, given a value from settings, creates a directory at the given value
- Test, with mocks, that checks the settings module and persistence module are wired up to each other properly, but does not test any logic because mocks inherently compromise logic tests
- Acceptance test that does not use mocks and simply tests that resources are persisted.
- Thanks to the other tests, we don't really need to check in this test if they're persisted in the correct place, because that's covered by more specific tests
- Add a silly router endpoint to init the database
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One file leakage thing. Other than this, changes since my last review look good. Thanks!
Co-authored-by: Max Marrone <[email protected]>
* edge: (116 commits) feat(system-server): add sqlite database and barebones HTTP server (#12085) feat(ot3): add enableOT3FirmwareUpdates feature flag to gate firmware update functionality. (#12102) feat(app): add bare bones hardware section to protocol details (#12099) feat(app): Support failed calibrations in the calibration wizard (#12092) refactor(docs): clean up Versioning page (#12084) refactor(robot-server): Make run and protocol limits configurable at launch (#12094) feat(app): add robotServerVersion to display the current robot software version (#12096) fix(hardware): do not track tip motor positions (#12093) feat(engine): allow calibrateGripper command to save calibration data (#12046) feat(app, api-client, react-api-client): delete POC TLC calibration data from overflow menu (#12075) fix(api): actually update OT3 instrument calibration offset in cache instrument (#12089) fix(robot-server): correct the data returned from instruments endpoint (#12067) feat(api): add thermocycler plate lift to hardware controller (#12068) fix(app): reference moduleId from result not params (#12077) feat(app): create ODD protocol setup page (#12071) refactor(api): Deprecate presses and increment args when using PAPI pick_up_tip (#12079) fix(ot3): handle multiple responses for a tip action request (#12083) refactor(api): touch tip implementation for PAPIv2 engine core (#12053) refactor(app): Remove ssid parameter from OnDeviceRouteParams (#11930) fix(api): fix broken test in the api hardware controller (#12080) ...
Overview
This PR adds a SQLite database and an endpoint-less HTTP server to the system-server project.
/var/lib/opentrons-system-server
but can be overwritten with an environment variable like on the robot-server.registration
, which is intended to store long-term app registrations.(subject, agent, agent-id)
in order to simplify the logic for interacting with the database.migration
, for tracking any future database migrations needed by the system-server.Test Plan
This can be tested on an OT-2 with
make-push
since all the new python packages are already on the disk from the robot-server. To test on an OT-3, a new image has to be flashed because many of these libraries are only in/opt/opentrons-robot-server
.After getting this on a robot, ssh in and do the following:
Check with `systemctl status opentrons-system-server`` that the service is running
Check that
/var/lib/opentrons-system-server
has been created andsystem_server.db
existscurl
aPUT
request tolocalhost:32950/system/refresh
and make sure you get the text 'OK' and the persistent DB is generated.Talk to the robot through an app just to make sure the robot-server and update-server are still working fine
Test on OT-2
Test on OT-3
Changelog
persistence
submodule to create a persistent directory and generate a SQL databasesettings
submodule to get environment variable configuration settingsapp_setup
andapp_state
for barebones FastAPI HTTP server configuration, withrouter.py
as a placeholder router that does nothing so far.OT_SYSTEM_SERVER_persistent_directory
to the OT-2 systemd unit file. This has to be added separately in oe-core for OT-3.Review requests
Would it make sense to just get rid of the environment variable settings? I mostly pulled it in because that seems to be how we prefer configuring the robot-server, but since this server already has CLI options I think I might prefer to just put the persistent directory into the CLI options.Risk assessment
Low, as long as this doesn't interfere with other servers then it has no user-facing effects yet.