Skip to content

[docs][nexus] Document the process for adding new endpoints - #2101

Merged
smklein merged 4 commits into
mainfrom
new-endpoint-docs
Dec 30, 2022
Merged

smklein merged 4 commits into
mainfrom
new-endpoint-docs

Conversation

@smklein

@smklein smklein commented Dec 29, 2022 •

Copy link
Copy Markdown
Collaborator

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

@smklein smklein changed the title Add a doc on adding new endpoints [docs][nexus] Document the process for adding new endpoints Dec 29, 2022
@smklein smklein added documentation Improvements or additions to documentation. nexus Related to nexus labels Dec 29, 2022
@smklein
smklein marked this pull request as ready for review December 29, 2022 22:00
** 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])

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Notes for myself:

  • It's kinda weird that the lookup_resource and authz_resource are separate; I think they both need to be used together to be functional
  • Populating the list of resources in oso_generic.rs feels like it could be automated
  • Generating the lookup methods on LookupPath feels like it could be automated
  • I believe these structures actually depend on a db::model object 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.

Comment thread docs/adding-an-endpoint.adoc Outdated
Comment on lines +49 to +54
* 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`

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

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...

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.json

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Added both the test and non-test options

@andrewjstone andrewjstone left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thank you so much for doing this @smklein

@smklein
smklein enabled auto-merge (squash) December 30, 2022 15:07
@smklein
smklein merged commit 82f75c9 into main Dec 30, 2022
@smklein
smklein deleted the new-endpoint-docs branch December 30, 2022 16:16
@davepacheco

Copy link
Copy Markdown
Collaborator

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:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation. nexus Related to nexus

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants