-
Notifications
You must be signed in to change notification settings - Fork 15
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
Refactor RequestData #127
Refactor RequestData #127
Conversation
This refactoring introduces an `Endpoint` parameter to various request methods across the codebase, ensuring a more consistent and descriptive way to handle request data. It modifies the necessary invocations and internal handling, enhancing clarity and maintainability.
Refactored methods and constructors to use `EndpointPath` instead of individual parameters for HTTP methods and paths. Improved encapsulation of path construction and method handling in various transport request invocations.
Enhanced `Request` and `RequestAsync` methods across various classes to accept a new `PostData` parameter. This improves the handling of POST data in requests. Also, included nullable reference type annotations and updated related tests.
Refactored PostData methods to include disableDirectStreaming parameter for better control over streaming behavior. Removed unused variables and streamlined RequestData construction to ensure settings are correctly assigned. Improved consistency in handling streams and memory buffers across synchronous and asynchronous write operations.
Update `PipelineException` constructors to use nullable inner exceptions and refine exception handling logic in `DefaultRequestPipeline`. Remove unnecessary `MadeItToResponse` flags and related properties in `RequestData` and invokers for streamlined code.
Modified methods to include a boolean isAsync parameter for more precise handling of asynchronous requests. Removed IsAsync property from RequestData.
Simplified `RequestData` instantiation by removing the `OpenTelemetryData` parameter across the codebase. Adjusted related properties and methods to maintain functionality and align with the new constructor signature.
Without having looked at it yet:
Maybe we can find a way to avoid the allocations. I need the This would cause the allocation to happen for every single request. |
There are two pieces a global The goal although not yet implemented is that if Do you need to specify a different |
Sounds great 👍
That's not the case, no. But I still need a way to override the This client instance is internally used to perform the requests. We want to use a custom My idea was to add Your refactoring is a good improvement anyways for all other cases where we do not have to override on a per-request basis. Maybe we can be smart in some way to optimize the per-request-override case as well. |
Would it make sense to consider the client passed to Semantic Kernel dedicated to that use, i.e. create an instance with the configured UA etc. that is only used by Semantic Kernel. If the app also needs to use a client for other ES-related code, they could have a second instance of the client configured for that use case. Although there is some extra overhead, this might be the rare use case where having more than one client in an app is reasonable? |
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.
LGTM from a first glance 🙂
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.
LGTM too. Thanks for starting off this improved direction!
This PR is meant as the first step to undo making
RequestData
the God Object it is today.PostData
is moved outsideRequestData
HttpMethod
andPath
andRequestParameters
now live outsideRequestData
, more info on this later.OpenTelemetryData
now lives outsideRequestData
.HeaderList
constructors.This now also introduces 2 new records.
EndpointPath
a readonly record struct that instructs what API we're calling.Endpoint
takes andEndpointPath
andNode
to take ownership ofUri
creations.This is hopefully a first step where we can cache these in calling libraries.
TransportConfiguration
now implemententsIRequestConfigation
The goal here is for
RequestData
to turn intoBoundConfiguration
and instance we can cache perTransportConfiguration
. Unless a local per request configuration is provided in which case we'll need to new a new instance which is rare.