-
Notifications
You must be signed in to change notification settings - Fork 58
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
Psr interfaces #233
base: main
Are you sure you want to change the base?
Psr interfaces #233
Conversation
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.
I love this change, thank you! Let's iterate till we get this to green. I think it's a lot simpler than #228, what do you think @shyim?
- Sign DCO,
git commit -s --amend
for existing commits, force push. - Add to CHANGELOG.
- Let's add an UPGRADING.md like https://github.com/opensearch-project/opensearch-py/blob/main/UPGRADING.md with details on migrating to this version.
- Should we keep a
OpenSearch\ClientBuilder
even with different parameters for easier migration?
82721bd
to
2f4661d
Compare
I noticed you tried to fix DCO?
Something is not adding up between your settings and the commit signature. |
16b664e
to
f14e9a2
Compare
I think I fixed that now? Let me know if it's still not rigt. I've updated the ClientBuilder and refactored the endpoints callable into it's own factory class. I think this makes it easier to understand, and also allows clients to swap out an implementation or use a dependency injection container if they want. I updated the client and namespace templates also. I regenerated afterwards and it looks like there are a lot of new API methods added. Should I use something other than https://github.com/opensearch-project/opensearch-api-specification/releases/download/main-latest/opensearch-openapi.yaml ? |
I think setHandler are not working anymore right? So aws sig v4 needs to be adjusted? |
Yes, I think we'd need to rewrite the guzzle middleware/handler without the ring dependency to make it easier for people who use AWS OpenSearch service to use signed requests. |
Yep looks good.
👍
Let's work on merging #223 separately from this not to mix in the PSR changes. It needs some attention to tests. If nobody picks it up here I can do it soon. |
be04c45
to
df01728
Compare
Thinking about this more, returning HTTP Response might not be the best DX. We should introduce a The Promise would also return this too. Thoughts? |
@kimpepper In other clients we return a strongly typed object that derives from a base class that also gives access to the underlying raw HTTP response from the network library "as is" along with some helper methods like status code or raw body. Note that OpenSearch returns more than JSON, too. |
I fixed what was broken in #223 and merged, rebase. |
I think the strongly typed object would require a lot of work on the generator side and might be out of scope for this issue? Not sure whether it's worth a simple wrapper around the PSR Response and HTTP Promise that gets returned? |
From my understanding the response content types can be one of:
but I couldn't find the docs to back that up. |
100%
I would if we think it makes it easier to extend it later in a common way across multiple transports (it feels like it would). |
We cover the range in https://github.com/opensearch-project/opensearch-api-specification, see https://github.com/opensearch-project/opensearch-api-specification/blob/07e329e8d01fd0576de6a0a3c35412fd5a9163db/tools/src/tester/MimeTypes.ts#L10. OpenSearch returns plain text, JSON, nd-json, CBOR, SMILE, and YAML, most from cat APIs. Did you see XML somewhere? That may be a miss in API specs :) |
Signed-off-by: Kim Pepper <[email protected]>
df01728
to
ec11701
Compare
I created a separate PR #236 to deal with the bulk change to |
Split out #237 for the endpoint factory changes here. |
Thanks @kimpepper! Let's work through those. |
*/ | ||
private function createEndpoint(string $class): EndpointInterface | ||
{ | ||
$fullPath = '\\OpenSearch\\Endpoints\\' . $class; |
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.
This looks wrong to me if $class
is already the class-string
* @var MlNamespace | ||
*/ | ||
protected $ml; | ||
protected MonitoringNamespace $monitoring; |
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.
Turning protected properties into typed properties is technically a BC break for child classes if they redefine the properties.
Btw, if this is going to be released as a major version of the package, maybe private visibility should be used instead (removing the properties themselves from the API covered by semver as child classes won't have access to them anymore). After all, the child classes can read them using the public getter.
* | ||
* @throws \Psr\Http\Client\ClientExceptionInterface|\Exception | ||
*/ | ||
protected function performRequest(EndpointInterface $endpoint): Promise|ResponseInterface |
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.
This return type check actually changes the return type of all public methods on namespaces, which have not been updated
@@ -1714,16 +1613,15 @@ public function createPointInTime(array $params = []) | |||
* $params['body'] = (array) The document (Required) | |||
* | |||
* @param array $params Associative array of parameters | |||
* @return array | |||
* @return \Http\Promise\Promise|\Psr\Http\Message\ResponseInterface |
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.
returning a ResponseInterface instead of parsing its body makes it impossible to document the structure of the response (defeating half of the goals of #217).
It also forces the caller to know how each endpoint is encoding its response (is it a JSON response or a plain text response ?), while the SDK could know that (this should be part of the API description)
|
||
return $this->transport->resultOrFuture($promise, $options); | ||
if ($this->isAsync()) { |
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.
instead of an instance-level flag (which separates the configuration from the usage, forcing all caller code to actually support both return types as they don't know how the client was configured), maybe this should be a argument of that method, allowing to use a conditional return type to be more precise (or even separate methods)
); | ||
|
||
return $this->transport->resultOrFuture($promise, $endpoint->getOptions()); | ||
if ($this->isAsync()) { |
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.
this isAsync
flag changing the return type makes it impossible to properly define the return type of methods of the SDK, as they will change return type depending on the configuration of the client, which would be a pain for DX.
Also, as discussed in #219 (comment), it looks like the existing version of opensearch-php does not actually support using the async mode for those methods (unless I missed a way to enable it), so maybe this switch should be removed entirely here, to allow keeping a well-typed SDK.
Fixes #199
Description
This PR removes the dependency on a specific HTTP client implementation and introduces PSR-7, PSR-17 and PSR-18 interfaces.
Issues Resolved
It greatly simplifies the volume and complexity of the library codebase and removes the need to manage:
Users of this library can choose from a number of synchronous and asynchronous HTTP clients including:
It greatly simplifies the volume and complexity of the library codebase. Specifically, it:
ezimuel/ringphp
which is not longer getting updatesBreaking changes
\Psr\Http\Message\StreamInterface
to decode the response in a memory efficient wayTasks:
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.