Repository navigation
[docs][nexus] Document the process for adding new endpoints - #2101
Conversation
| ** Output views are defined in https://github.com/oxidecomputer/omicron/blob/main/nexus/types/src/external_api/views.rs[views.rs] (https://github.com/oxidecomputer/omicron/blob/1dfe47c1b3122bc4f32a9c517cb31b1600581ea2/nexus/types/src/external_api/views.rs#L270-L274[Example]) | ||
|
|
||
| === **Lookup & Authorization** | ||
| * Declare a new resource-to-be-looked-up via `lookup_resource!` in xref:../nexus/src/db/lookup.rs[lookup.rs] (https://github.com/oxidecomputer/omicron/blob/1dfe47c1b3122bc4f32a9c517cb31b1600581ea2/nexus/src/db/lookup.rs#L557-L564[Example]) |
There was a problem hiding this comment.
Notes for myself:
- It's kinda weird that the
lookup_resourceandauthz_resourceare separate; I think they both need to be used together to be functional - Populating the list of resources in
oso_generic.rsfeels like it could be automated - Generating the lookup methods on
LookupPathfeels like it could be automated - I believe these structures actually depend on a
db::modelobject existing (after all, how else would they know what to fetch?), which is another layer of coupling that's subtle here. I wonder if there's a way to consolidate all these tightly coupled pieces a little better, or to actually make them more loosely coupled.
| * Authorization | ||
| ** There exists a https://github.com/oxidecomputer/omicron/blob/main/nexus/src/authz/policy_test[policy test] which compares all Oso objects against an expected policy. New resources are usually added to https://github.com/oxidecomputer/omicron/blob/main/nexus/src/authz/policy_test/resources.rs[resources.rs] to get coverage. | ||
| * openapi | ||
| ** Nexus generates a new openapi spec from the dropshot endpoints. If you modify endpoints, you'll usually need to `EXPECTORATE=overwrite cargo test` the following targets... | ||
| *** External API: `test_nexus_openapi` | ||
| *** Internal API: `test_nexus_openapi_internal` |
There was a problem hiding this comment.
These tests are good, in that they're getting so much coverage, but they also kinda suck from a developer UX point of view. Testing any API changes feels like it requires re-running cargo test with and without EXPECTORATE a bunch of times, especially since changing the openapi file causes different code generation, which means the next call to cargo test might not actually build...
There was a problem hiding this comment.
Was it faster to just run it manually without going via the tests, e.g.
$ cargo run -p omicron-nexus --bin nexus -- -I nexus/examples/config.toml > openapi/nexus-internal.json
$ cargo run -p omicron-nexus --bin nexus -- -O nexus/examples/config.toml > openapi/nexus.json
$ cargo run -p omicron-sled-agent --bin sled-agent -- openapi > openapi/sled-agent.jsonThere was a problem hiding this comment.
Definitely seems to build fewer packages, at least. I will be trying this. Normally I run
EXPECTORATE=overwrite cargo t integration_tests::commands::test_nexus_openapi
I only ever work on the external API.
There was a problem hiding this comment.
Added both the test and non-test options
andrewjstone
left a comment
There was a problem hiding this comment.
Thank you so much for doing this @smklein
|
This is great. A bunch of this winds up being basically Nexus architecture. I wonder if it should live in nexus/src/lib.rs (or some other top-level place directly in the source)? |
| ** There exists a https://github.com/oxidecomputer/omicron/blob/main/nexus/src/authz/policy_test[policy test] which compares all Oso objects against an expected policy. New resources are usually added to https://github.com/oxidecomputer/omicron/blob/main/nexus/src/authz/policy_test/resources.rs[resources.rs] to get coverage. | ||
| * openapi | ||
| ** Nexus generates a new openapi spec from the dropshot endpoints. If you modify endpoints, you'll need to update openapi JSON files. | ||
| *** The following commands may be used to update APIs: |
There was a problem hiding this comment.
FYI, I think this overlaps with this section of the README, which has some discussion on how to make changes that affect both a server and client inside Omicron.
I've been committing to Omicron for a while, and even I forget all the steps involved here.
I figured I'd write this down after going through the process on #2099 - maybe this could also serve as a discussion point for "are some of these steps more complicated than they need to be?".
Feedback welcome