-
Notifications
You must be signed in to change notification settings - Fork 53
Take TypedUuid
s out of the external API
#8910
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
Conversation
CC @sunshowers I thought that it was possible for the typed uuids to make it across the server-client boundary, and maybe that that's already happening? That seems pretty valuable. But maybe that's currently happening through |
We do handle typed UUIDs across internal boundaries (currently via replace statements, and in the future through automatic replacement), but in general exposing typed UUIDs in the external API is probably lower value. |
I was also hoping in a future PR to change to typed UUIDs in the path parameters, request bodies, etc, so that they come in typed and don't have to be converted from a generic UUID. Hopefully the answer is that clients can deal with this change? |
Right, that's why I called out the unfortunate spots where we seem to be using the same struct both internally and externally. |
For me, the ideal situation would be that this is done at the API request handling layer but it doesn't actually show up in the OpenAPI schema. The clients wouldn't know about it at all. And this reflects the purpose of typed UUIDs: the fact that a client calls it an instance ID doesn't make it one — what makes it one is that it was passed as the ID parameter to an instance endpoint. That suggests another approach: use |
To be clear, I think exposing these in the public API is not lower value, I think it has negative value. It is confusing but adds nothing otherwise. |
We could provide an alternative schema for TypedUuid for use in the external API via a separate function. |
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.
Also: what about the replace statements in clients/oxide-client/src/lib.rs
? Should those get removed too?
dev-tools/omdb/src/bin/omdb/nexus.rs
Outdated
@@ -2,7 +2,7 @@ | |||
// License, v. 2.0. If a copy of the MPL was not distributed with this | |||
// file, You can obtain one at https://mozilla.org/MPL/2.0/. | |||
|
|||
//! omdb commands that query or update specific Nexus instances |
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.
?
@@ -19,7 +19,7 @@ use omicron_common::api::external::{ | |||
Digest, Error, FailureDomain, IdentityMetadata, InstanceState, Name, | |||
ObjectIdentity, SimpleIdentity, SimpleIdentityOrName, | |||
}; | |||
use omicron_uuid_kinds::{AlertReceiverUuid, AlertUuid}; | |||
// Use plain `Uuid` in external views to avoid leaking typed UUIDs in OpenAPI |
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.
can this be enforced somehow, like not including the uuid kinds dep in the Cargo.toml for this crate?
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.
Good idea, I'll try. Though it's not necessary if we go the other route and just have typed UUIDs act like normal ones in the OpenAPI schema.
The replaces in omicron/clients/nexus-client/src/lib.rs Lines 32 to 83 in 900085e
|
Completely changed the approach in 823d0d5 to use manual |
I noticed in #8803 (comment) that there are some typed UUIDs leaking into the external API. As I said in the comment, I don't think this information is likely to be useful for clients because we don't actually use it in any of the request body types, only the responses.
I don't think this change hurts correctness in our code because the conversion to generic UUID usually happens right at the end of request handling, when models are converted to views for response serialization.
However, there are a couple of spots where the struct is used a little earlier in the process (see how the affinity datastore functions return view structs) or is shared with internal API code, so there may be a tiny risk to correctness.This is no longer true with 823d0d5.