Skip to content

[Discussion] How to declare ClientOptions #300

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

Closed
heaths opened this issue Jun 15, 2021 · 3 comments
Closed

[Discussion] How to declare ClientOptions #300

heaths opened this issue Jun 15, 2021 · 3 comments
Labels
design-discussion An area of design currently under discussion and open to team and community feedback.

Comments

@heaths
Copy link
Member

heaths commented Jun 15, 2021

Starting with PR #288 we need to define how ClientOptions should be defined throughout our SDKs. Based on our general designs and .NET designs - more specifically for service versions - client options should be optional with good defaults.

In PR #288 I'm suggesting we implement the Default trait along with setters that allow for a pattern like:

let options = StorageClientOptions::default()
  .with_version("2021-06-15")
  .with_retry(RetryOptions::default().with_mode(RetryMode::Fixed()));

Alternatively, a service version could be passed into a new associated function like we do for .NET and Java, at least.

The underpinning concept is that nothing in ClientOptions should be required, or that should be in the associated Client class's new method (or similar).

The Azure SDK guidelines isn't typically specific on how client options are implemented, but it state that we should follow a convention of:

  • Client is the client to send requests
  • ClientOptions are options for the client above
@heaths heaths added the design-discussion An area of design currently under discussion and open to team and community feedback. label Jun 15, 2021
@heaths
Copy link
Member Author

heaths commented Jun 15, 2021

Also, @rylev brought this up before, but it sounds like we should favor composition over derivation, such that a *ClientOptions class should contain an azure_core::ClientOptions named options. In our other Azure SDKs, we derive or implement, but perhaps that's not idiomatic here.

So logical structure would look like this using Storage as an example again:

#[derive(Clone, Debug, Default)]
struct StorageClientOptions {
  version: StorageClientServiceVersion,
  options: azure_core::ClientOptions,
}

I also recommend we derive Clone and Debug as well. If we don't want to borrow references everywhere, Clone will be useful. Based on our existing SDKs, nothing apart from the HttpClient (which we already define as Arc<dyn HttpClient anyway) is expensive anyway.

@rylev
Copy link
Contributor

rylev commented Jun 16, 2021

The code you posted above looks good. My only nit would be perhaps a better name for the options field, but I'm not sure what one would be.

#[derive(Clone, Debug, Default)]
struct StorageClientOptions {
  version: StorageClientServiceVersion,
  options: azure_core::ClientOptions,
}

Question: what would be the default StorageClientServiceVersion?

@heaths
Copy link
Member Author

heaths commented Jun 16, 2021

We always default to the latest (hardcoded) at the time of compilation. Release semvers never refer to service preview versions - only "beta" (we stopped using "preview" because that causes support lifecycle confusion with the service) semvers can do that, but I'm not sure how those work with cargo. I'll have that in the guidelines to match our other SDKs as well.

@cataggar cataggar closed this as not planned Won't fix, can't repro, duplicate, stale Oct 1, 2023
@github-actions github-actions bot locked and limited conversation to collaborators Feb 4, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
design-discussion An area of design currently under discussion and open to team and community feedback.
Projects
None yet
Development

No branches or pull requests

3 participants