-
Notifications
You must be signed in to change notification settings - Fork 78
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[5/n] [dropshot] add support for per-endpoint size limits (#1171)
For some endpoints like uploading update and support bundles, we would like to have a larger request limit. Add support for that. This is the other half of RFD 353, after #617. (A previous attempt was #618, which I've abandoned.) The PR consists of: * The implementation. * A small tweak to the API generation code for better span attribution. * Tests.
- Loading branch information
1 parent
05af62e
commit d5874eb
Showing
19 changed files
with
559 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// Copyright 2024 Oxide Computer Company | ||
|
||
#![allow(unused_imports)] | ||
|
||
use dropshot::channel; | ||
use dropshot::RequestContext; | ||
use dropshot::WebsocketUpgrade; | ||
|
||
// Test: request_body_max_bytes specified for channel (this parameter is only | ||
// accepted for endpoints, not channels) | ||
|
||
#[channel { | ||
protocol = WEBSOCKETS, | ||
path = "/test", | ||
request_body_max_bytes = 1024, | ||
}] | ||
async fn bad_channel( | ||
_rqctx: RequestContext<()>, | ||
_upgraded: WebsocketUpgrade, | ||
) -> dropshot::WebsocketChannelResult { | ||
Ok(()) | ||
} | ||
|
||
fn main() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
error: extraneous member `request_body_max_bytes` | ||
--> tests/fail/bad_channel28.rs:15:5 | ||
| | ||
15 | request_body_max_bytes = 1024, | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// Copyright 2024 Oxide Computer Company | ||
|
||
#![allow(unused_imports)] | ||
|
||
use dropshot::endpoint; | ||
use dropshot::HttpError; | ||
use dropshot::HttpResponseUpdatedNoContent; | ||
use dropshot::RequestContext; | ||
|
||
// Test: incorrect type for request_body_max_bytes. | ||
|
||
#[endpoint { | ||
method = GET, | ||
path = "/test", | ||
request_body_max_bytes = "not_a_number" | ||
}] | ||
async fn bad_endpoint( | ||
_rqctx: RequestContext<()>, | ||
) -> Result<HttpResponseUpdatedNoContent, HttpError> { | ||
Ok(HttpResponseUpdatedNoContent()) | ||
} | ||
|
||
fn main() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
error[E0308]: mismatched types | ||
--> tests/fail/bad_endpoint28.rs:15:30 | ||
| | ||
15 | request_body_max_bytes = "not_a_number" | ||
| ^^^^^^^^^^^^^^ expected `usize`, found `&str` | ||
16 | }] | ||
17 | async fn bad_endpoint( | ||
| ------------ arguments to this method are incorrect | ||
| | ||
note: method defined here | ||
--> src/api_description.rs | ||
| | ||
| pub fn request_body_max_bytes(mut self, max_bytes: usize) -> Self { | ||
| ^^^^^^^^^^^^^^^^^^^^^^ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
// Copyright 2024 Oxide Computer Company | ||
|
||
#![allow(unused_imports)] | ||
|
||
use dropshot::channel; | ||
use dropshot::RequestContext; | ||
use dropshot::WebsocketUpgrade; | ||
|
||
#[dropshot::api_description] | ||
trait MyServer { | ||
type Context; | ||
|
||
// Test: request_body_max_bytes specified for channel (this parameter is only | ||
// accepted for endpoints, not channels) | ||
#[channel { | ||
protocol = WEBSOCKETS, | ||
path = "/test", | ||
request_body_max_bytes = 1024, | ||
}] | ||
async fn bad_channel( | ||
_rqctx: RequestContext<Self::Context>, | ||
_upgraded: WebsocketUpgrade, | ||
) -> dropshot::WebsocketChannelResult; | ||
} | ||
|
||
enum MyImpl {} | ||
|
||
// This should not produce errors about items being missing. | ||
impl MyServer for MyImpl { | ||
type Context = (); | ||
|
||
async fn bad_channel( | ||
_rqctx: RequestContext<Self::Context>, | ||
_upgraded: WebsocketUpgrade, | ||
) -> dropshot::WebsocketChannelResult { | ||
Ok(()) | ||
} | ||
} | ||
|
||
fn main() { | ||
// These items should be generated and accessible. | ||
my_server_mod::api_description::<MyImpl>(); | ||
my_server_mod::stub_api_description(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
error: endpoint `bad_channel` has invalid attributes: extraneous member `request_body_max_bytes` | ||
--> tests/fail/bad_trait_channel28.rs:18:9 | ||
| | ||
18 | request_body_max_bytes = 1024, | ||
| ^^^^^^^^^^^^^^^^^^^^^^ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// Copyright 2024 Oxide Computer Company | ||
|
||
#![allow(unused_imports)] | ||
|
||
use dropshot::endpoint; | ||
use dropshot::HttpError; | ||
use dropshot::HttpResponseUpdatedNoContent; | ||
use dropshot::RequestContext; | ||
|
||
// Test: incorrect type for request_body_max_bytes. | ||
|
||
#[dropshot::api_description] | ||
trait MyApi { | ||
type Context; | ||
|
||
#[endpoint { | ||
method = GET, | ||
path = "/test", | ||
request_body_max_bytes = "not_a_number", | ||
}] | ||
async fn bad_endpoint( | ||
_rqctx: RequestContext<Self::Context>, | ||
) -> Result<HttpResponseUpdatedNoContent, HttpError>; | ||
} | ||
|
||
enum MyImpl {} | ||
|
||
// This should not produce errors about items being missing. | ||
|
||
impl MyApi for MyImpl { | ||
type Context = (); | ||
async fn bad_endpoint( | ||
_rqctx: RequestContext<Self::Context>, | ||
) -> Result<HttpResponseUpdatedNoContent, HttpError> { | ||
Ok(HttpResponseUpdatedNoContent()) | ||
} | ||
} | ||
|
||
fn main() { | ||
// These items should be generated and accessible. | ||
my_api_mod::api_description::<MyImpl>(); | ||
my_api_mod::stub_api_description(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
error[E0308]: mismatched types | ||
--> tests/fail/bad_trait_endpoint28.rs:19:34 | ||
| | ||
16 | #[endpoint { | ||
| - arguments to this method are incorrect | ||
... | ||
19 | request_body_max_bytes = "not_a_number", | ||
| ^^^^^^^^^^^^^^ expected `usize`, found `&str` | ||
| | ||
note: method defined here | ||
--> src/api_description.rs | ||
| | ||
| pub fn request_body_max_bytes(mut self, max_bytes: usize) -> Self { | ||
| ^^^^^^^^^^^^^^^^^^^^^^ |
Oops, something went wrong.