Skip to content
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

Exposing ServerConfig options #959

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open

Exposing ServerConfig options #959

wants to merge 7 commits into from

Conversation

augustuswm
Copy link

@augustuswm augustuswm commented Apr 5, 2024

I wanted to start a discussion on how we might go about exposing some additional server settings to the end user, namely the pagination default values. This PR is the most straightforward take and does not consider backwards compatibility. The main changes are:

  1. Wherever ServerConfig was used ConfigDropshot is now used
  2. Instead of passing a reference to a ConfigDropshot during construction, the value is passed.
  3. There are two new fields on ConfigDropshot. page_max_nitems and page_default_nitems.

This causes two breaking changes:

  1. We no longer accept a reference during construction.
  2. Callers not using the Default implementation will have to add the new fields.

The are a couple options we could also consider here.

  1. ConfigDropshot already derives Clone. We could continue accepting a reference and clone the users config. Not as ideal, but one less breaking change.
  2. As we have move fields on the ConfigDropshot struct, we could consider a builder for it. I'm not sure how helpful this is at the moment given the Default impl.

Either way the primary goal here is to come up with a pattern to expose some of these configurations to end users at the server level (specifically ignoring the ability to control these settings per endpoint).

@augustuswm augustuswm requested a review from ahl April 5, 2024 15:00
@davepacheco
Copy link
Collaborator

Thanks for this! I'm glad to finally resolve that TODO about merging ServerConfig and ConfigDropshot.

I would eliminate the first breaking change by having HttpServerStarter continue to accept &ConfigDropshot and just clone it. In retrospect maybe it would have been better to take an owned value here but I don't think avoiding one clone during server startup is worth the API breakage. (I think this will also significantly reduce the size of the PR.)

Could you also update CHANGELOG.adoc, adding a new "Breaking Changes" section under "Unreleased changes" that points to this issue and explains the extra default values?

dropshot/src/server.rs Outdated Show resolved Hide resolved
dropshot/src/server.rs Outdated Show resolved Hide resolved
dropshot/src/server.rs Outdated Show resolved Hide resolved
@augustuswm
Copy link
Author

Thanks for the review! I updated it back to taking a config by reference and just cloned before passing to the inner server. (Now a much simple PR)

Breaking change note has been added. Let me know if the tone of it makes sense.

@@ -49,6 +50,10 @@ pub struct ConfigDropshot {
pub bind_address: SocketAddr,
/// maximum allowed size of a request body, defaults to 1024
pub request_body_max_bytes: usize,
/// maximum size of any page of results
Copy link
Collaborator

Choose a reason for hiding this comment

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

do we want to add #[non_exhaustive] to the struct? Would that force consumers to use ..Default::default() when constructing this? i.e. such that adding more fields would not be a breaking change?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I wondered the same thing. Consumers can already do that if they want. It's kind of nice that the way it is now you can have your code break if we add some new config option so that you get a chance to look yourself at whether our default works for you. I think I've used this in the past.

Copy link
Collaborator

@davepacheco davepacheco left a comment

Choose a reason for hiding this comment

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

Thanks -- this is looking good.

I just noticed that ServerConfig was sort of exposed via rqctx.server.config. Would you mind doing a test build of Omicron with this dropshot to make sure we're not using something there that's hard to fix up?

@@ -15,6 +15,10 @@

https://github.com/oxidecomputer/dropshot/compare/v0.10.0\...HEAD[Full list of commits]

=== Breaking Changes

* https://github.com/oxidecomputer/dropshot/pull/959[#959] expands the settings available via `ConfigDropshot`. This adds two new fields `page_max_nitems` and `page_default_nitems` that will need to be added wherever a `ConfigDropshot` struct is manually constructed.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
* https://github.com/oxidecomputer/dropshot/pull/959[#959] expands the settings available via `ConfigDropshot`. This adds two new fields `page_max_nitems` and `page_default_nitems` that will need to be added wherever a `ConfigDropshot` struct is manually constructed.
* https://github.com/oxidecomputer/dropshot/pull/959[#959] expands the settings available via `ConfigDropshot`. This adds two new fields `page_max_nitems` and `page_default_nitems` that will need to be added wherever a `ConfigDropshot` struct is manually constructed. The defaults are likely appropriate for most use cases.

@@ -480,7 +480,7 @@ impl<Context: ServerContext> TestContext<Context> {
pub fn new(
api: ApiDescription<Context>,
private: Context,
config_dropshot: &ConfigDropshot,
config_dropshot: ConfigDropshot,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do we have to change this? This seems like another breaking change. (I'm not sure how this still compiles?)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants