From c7af23d4a48d0cbf29cc5b253b29e0c734180bf4 Mon Sep 17 00:00:00 2001 From: Josh Mock Date: Thu, 10 Aug 2023 14:32:18 -0500 Subject: [PATCH 1/2] Use `esv` service key for client meta header Used to track serverless as a distinct client from stack. --- elasticsearch_serverless/_sync/client/utils.py | 2 +- elasticsearch_serverless/_version.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/elasticsearch_serverless/_sync/client/utils.py b/elasticsearch_serverless/_sync/client/utils.py index 1444adf..129be74 100644 --- a/elasticsearch_serverless/_sync/client/utils.py +++ b/elasticsearch_serverless/_sync/client/utils.py @@ -64,7 +64,7 @@ SKIP_IN_PATH: Collection[Any] = (None, "", b"", [], ()) # To be passed to 'client_meta_service' on the Transport -CLIENT_META_SERVICE = ("es", client_meta_version(__versionstr__)) +CLIENT_META_SERVICE = ("esv", client_meta_version(__versionstr__)) # Default User-Agent used by the client USER_AGENT = create_user_agent("elasticsearch-py", __versionstr__) diff --git a/elasticsearch_serverless/_version.py b/elasticsearch_serverless/_version.py index 36d1fe9..616474e 100644 --- a/elasticsearch_serverless/_version.py +++ b/elasticsearch_serverless/_version.py @@ -15,4 +15,4 @@ # specific language governing permissions and limitations # under the License. -__versionstr__ = "8.10.0" +__versionstr__ = "0.1.0" From e291fcdefcfc4ee0767a630becd79720b29d751e Mon Sep 17 00:00:00 2001 From: Josh Mock Date: Thu, 10 Aug 2023 14:56:13 -0500 Subject: [PATCH 2/2] Unit test fixes --- .../test_async/test_transport.py | 11 +++--- .../test_client/test_options.py | 34 +++++++++---------- .../test_client/test_serializers.py | 12 +++---- .../test_serializer.py | 8 ++--- .../test_transport.py | 11 +++--- 5 files changed, 39 insertions(+), 37 deletions(-) diff --git a/test_elasticsearch_serverless/test_async/test_transport.py b/test_elasticsearch_serverless/test_async/test_transport.py index 5520a4b..c9d8112 100644 --- a/test_elasticsearch_serverless/test_async/test_transport.py +++ b/test_elasticsearch_serverless/test_async/test_transport.py @@ -215,7 +215,8 @@ async def test_client_meta_header(self): assert 1 == len(calls) headers = calls[0][1]["headers"] assert re.search( - r"^es=[0-9.]+p?,py=[0-9.]+p?,t=[0-9.]+p?$", headers["x-elastic-client-meta"] + r"^esv=[0-9.]+p?,py=[0-9.]+p?,t=[0-9.]+p?$", + headers["x-elastic-client-meta"], ) class DummyNodeWithMeta(DummyNode): @@ -230,7 +231,7 @@ class DummyNodeWithMeta(DummyNode): assert 1 == len(calls) headers = calls[0][1]["headers"] assert re.search( - r"^es=[0-9.]+p?,py=[0-9.]+p?,t=[0-9.]+p?,dm=1.2.3$", + r"^esv=[0-9.]+p?,py=[0-9.]+p?,t=[0-9.]+p?,dm=1.2.3$", headers["x-elastic-client-meta"], ) assert headers["Custom"] == "header" @@ -244,7 +245,7 @@ async def test_client_meta_header_not_sent(self): calls = client.transport.node_pool.get().calls assert 1 == len(calls) assert calls[0][1]["headers"] == { - "accept": "application/vnd.elasticsearch+json; compatible-with=8", + "accept": "application/vnd.elasticsearch+json; compatible-with=0", } async def test_body_surrogates_replaced_encoded_into_bytes(self): @@ -421,7 +422,7 @@ async def test_sniff_uses_sniff_timeout(self): { "body": None, "headers": { - "accept": "application/vnd.elasticsearch+json; compatible-with=8", + "accept": "application/vnd.elasticsearch+json; compatible-with=0", }, "request_timeout": DEFAULT, }, @@ -686,7 +687,7 @@ async def test_unsupported_product_error(headers): { "body": None, "headers": { - "accept": "application/vnd.elasticsearch+json; compatible-with=8", + "accept": "application/vnd.elasticsearch+json; compatible-with=0", }, "request_timeout": DEFAULT, }, diff --git a/test_elasticsearch_serverless/test_client/test_options.py b/test_elasticsearch_serverless/test_client/test_options.py index b93110c..ba18b4a 100644 --- a/test_elasticsearch_serverless/test_client/test_options.py +++ b/test_elasticsearch_serverless/test_client/test_options.py @@ -139,7 +139,7 @@ def test_options_passed_to_perform_request(self): assert call.pop("client_meta") is DEFAULT assert call == { "headers": { - "accept": "application/vnd.elasticsearch+json; compatible-with=8", + "accept": "application/vnd.elasticsearch+json; compatible-with=0", }, "body": None, } @@ -157,7 +157,7 @@ def test_options_passed_to_perform_request(self): assert call.pop("client_meta") is DEFAULT assert call == { "headers": { - "accept": "application/vnd.elasticsearch+json; compatible-with=8", + "accept": "application/vnd.elasticsearch+json; compatible-with=0", }, "body": None, "request_timeout": 1, @@ -182,7 +182,7 @@ def test_options_passed_to_perform_request(self): assert call.pop("client_meta") is DEFAULT assert call == { "headers": { - "accept": "application/vnd.elasticsearch+json; compatible-with=8", + "accept": "application/vnd.elasticsearch+json; compatible-with=0", }, "body": None, "request_timeout": 1, @@ -209,7 +209,7 @@ async def test_options_passed_to_async_perform_request(self): assert call.pop("client_meta") is DEFAULT assert call == { "headers": { - "accept": "application/vnd.elasticsearch+json; compatible-with=8", + "accept": "application/vnd.elasticsearch+json; compatible-with=0", }, "body": None, } @@ -227,7 +227,7 @@ async def test_options_passed_to_async_perform_request(self): assert call.pop("client_meta") is DEFAULT assert call == { "headers": { - "accept": "application/vnd.elasticsearch+json; compatible-with=8", + "accept": "application/vnd.elasticsearch+json; compatible-with=0", }, "body": None, "request_timeout": 1, @@ -252,7 +252,7 @@ async def test_options_passed_to_async_perform_request(self): assert call.pop("client_meta") is DEFAULT assert call == { "headers": { - "accept": "application/vnd.elasticsearch+json; compatible-with=8", + "accept": "application/vnd.elasticsearch+json; compatible-with=0", }, "body": None, "request_timeout": 1, @@ -294,7 +294,7 @@ def test_http_headers_overrides(self): assert call["headers"] == { "key": "val", - "accept": "application/vnd.elasticsearch+json; compatible-with=8", + "accept": "application/vnd.elasticsearch+json; compatible-with=0", } client.options(headers={"key1": "val"}).indices.get(index="2") @@ -303,7 +303,7 @@ def test_http_headers_overrides(self): assert call["headers"] == { "key": "val", "key1": "val", - "accept": "application/vnd.elasticsearch+json; compatible-with=8", + "accept": "application/vnd.elasticsearch+json; compatible-with=0", } client.options(headers={"key": "val2"}).indices.get(index="3") @@ -311,7 +311,7 @@ def test_http_headers_overrides(self): assert call["headers"] == { "key": "val2", - "accept": "application/vnd.elasticsearch+json; compatible-with=8", + "accept": "application/vnd.elasticsearch+json; compatible-with=0", } client = Elasticsearch( @@ -338,14 +338,14 @@ def test_user_agent_override(self): call = calls[("GET", "/1")][0] assert call["headers"] == { "user-agent": "custom1", - "accept": "application/vnd.elasticsearch+json; compatible-with=8", + "accept": "application/vnd.elasticsearch+json; compatible-with=0", } client.indices.get(index="2", headers={"user-agent": "custom2"}) call = calls[("GET", "/2")][0] assert call["headers"] == { "user-agent": "custom2", - "accept": "application/vnd.elasticsearch+json; compatible-with=8", + "accept": "application/vnd.elasticsearch+json; compatible-with=0", } client = Elasticsearch( @@ -359,14 +359,14 @@ def test_user_agent_override(self): call = calls[("GET", "/1")][0] assert call["headers"] == { "user-agent": "custom3", - "accept": "application/vnd.elasticsearch+json; compatible-with=8", + "accept": "application/vnd.elasticsearch+json; compatible-with=0", } client.indices.get(index="2", headers={"user-agent": "custom4"}) call = calls[("GET", "/2")][0] assert call["headers"] == { "user-agent": "custom4", - "accept": "application/vnd.elasticsearch+json; compatible-with=8", + "accept": "application/vnd.elasticsearch+json; compatible-with=0", } def test_options_timeout_parameters(self): @@ -387,7 +387,7 @@ def test_options_timeout_parameters(self): assert call.pop("client_meta") is DEFAULT assert call == { "headers": { - "accept": "application/vnd.elasticsearch+json; compatible-with=8", + "accept": "application/vnd.elasticsearch+json; compatible-with=0", }, "body": None, "request_timeout": 1, @@ -416,7 +416,7 @@ def test_options_timeout_parameters(self): assert call.pop("client_meta") is DEFAULT assert call == { "headers": { - "accept": "application/vnd.elasticsearch+json; compatible-with=8", + "accept": "application/vnd.elasticsearch+json; compatible-with=0", }, "body": None, "request_timeout": 2, @@ -440,7 +440,7 @@ def test_options_timeout_parameters(self): assert call.pop("client_meta") is DEFAULT assert call == { "headers": { - "accept": "application/vnd.elasticsearch+json; compatible-with=8", + "accept": "application/vnd.elasticsearch+json; compatible-with=0", }, "body": None, } @@ -461,7 +461,7 @@ def test_options_timeout_parameters(self): assert call.pop("client_meta") is DEFAULT assert call == { "headers": { - "accept": "application/vnd.elasticsearch+json; compatible-with=8", + "accept": "application/vnd.elasticsearch+json; compatible-with=0", }, "body": None, "request_timeout": 1, diff --git a/test_elasticsearch_serverless/test_client/test_serializers.py b/test_elasticsearch_serverless/test_client/test_serializers.py index 6115e43..8a63a1b 100644 --- a/test_elasticsearch_serverless/test_client/test_serializers.py +++ b/test_elasticsearch_serverless/test_client/test_serializers.py @@ -29,30 +29,30 @@ def test_compat_mode_on_by_default(self): self.client.get(index="test0", id="1") assert len(calls) == 1 assert calls[("GET", "/test0/_doc/1")][0]["headers"] == { - "Accept": "application/vnd.elasticsearch+json; compatible-with=8" + "Accept": "application/vnd.elasticsearch+json; compatible-with=0" } # Search with body self.client.search(index="test1", query={"match_all": {}}) assert len(calls) == 2 assert calls[("POST", "/test1/_search")][0]["headers"] == { - "Accept": "application/vnd.elasticsearch+json; compatible-with=8", - "Content-Type": "application/vnd.elasticsearch+json; compatible-with=8", + "Accept": "application/vnd.elasticsearch+json; compatible-with=0", + "Content-Type": "application/vnd.elasticsearch+json; compatible-with=0", } # Search without body self.client.search(index="test2") assert len(calls) == 3 assert calls[("POST", "/test2/_search")][0]["headers"] == { - "Accept": "application/vnd.elasticsearch+json; compatible-with=8", + "Accept": "application/vnd.elasticsearch+json; compatible-with=0", } # Bulk uses x-ndjson self.client.bulk(operations=[]) assert len(calls) == 4 assert calls[("PUT", "/_bulk")][0]["headers"] == { - "Accept": "application/vnd.elasticsearch+json; compatible-with=8", - "Content-Type": "application/vnd.elasticsearch+x-ndjson; compatible-with=8", + "Accept": "application/vnd.elasticsearch+json; compatible-with=0", + "Content-Type": "application/vnd.elasticsearch+x-ndjson; compatible-with=0", } @pytest.mark.parametrize("mime_subtype", ["json", "x-ndjson"]) diff --git a/test_elasticsearch_serverless/test_serializer.py b/test_elasticsearch_serverless/test_serializer.py index 4f24573..7d1bc8e 100644 --- a/test_elasticsearch_serverless/test_serializer.py +++ b/test_elasticsearch_serverless/test_serializer.py @@ -197,8 +197,8 @@ def test_deserialize_compatibility_header(self): for content_type in ( "application/vnd.elasticsearch+json;compatible-with=7", "application/vnd.elasticsearch+json; compatible-with=7", - "application/vnd.elasticsearch+json;compatible-with=8", - "application/vnd.elasticsearch+json; compatible-with=8", + "application/vnd.elasticsearch+json;compatible-with=0", + "application/vnd.elasticsearch+json; compatible-with=0", ): assert {"some": "data"} == self.serializers.loads( '{"some":"data"}', content_type @@ -210,8 +210,8 @@ def test_deserialize_compatibility_header(self): for content_type in ( "application/vnd.elasticsearch+x-ndjson;compatible-with=7", "application/vnd.elasticsearch+x-ndjson; compatible-with=7", - "application/vnd.elasticsearch+x-ndjson;compatible-with=8", - "application/vnd.elasticsearch+x-ndjson; compatible-with=8", + "application/vnd.elasticsearch+x-ndjson;compatible-with=0", + "application/vnd.elasticsearch+x-ndjson; compatible-with=0", ): assert b'{"some":"data"}\n{"some":"data"}\n' == self.serializers.dumps( ['{"some":"data"}', {"some": "data"}], content_type diff --git a/test_elasticsearch_serverless/test_transport.py b/test_elasticsearch_serverless/test_transport.py index a47bf3f..75cb49c 100644 --- a/test_elasticsearch_serverless/test_transport.py +++ b/test_elasticsearch_serverless/test_transport.py @@ -245,7 +245,8 @@ def test_client_meta_header(self): assert 1 == len(calls) headers = calls[0][1]["headers"] assert re.search( - r"^es=[0-9.]+p?,py=[0-9.]+p?,t=[0-9.]+p?$", headers["x-elastic-client-meta"] + r"^esv=[0-9.]+p?,py=[0-9.]+p?,t=[0-9.]+p?$", + headers["x-elastic-client-meta"], ) class DummyNodeWithMeta(DummyNode): @@ -258,7 +259,7 @@ class DummyNodeWithMeta(DummyNode): assert 1 == len(calls) headers = calls[0][1]["headers"] assert re.search( - r"^es=[0-9.]+p?,py=[0-9.]+p?,t=[0-9.]+p?,dm=1.2.3$", + r"^esv=[0-9.]+p?,py=[0-9.]+p?,t=[0-9.]+p?,dm=1.2.3$", headers["x-elastic-client-meta"], ) assert headers["Custom"] == "header" @@ -272,7 +273,7 @@ def test_client_meta_header_not_sent(self): calls = client.transport.node_pool.get().calls assert 1 == len(calls) assert calls[0][1]["headers"] == { - "accept": "application/vnd.elasticsearch+json; compatible-with=8", + "accept": "application/vnd.elasticsearch+json; compatible-with=0", } def test_meta_header_type_error(self): @@ -446,7 +447,7 @@ def test_sniff_uses_sniff_timeout(self): { "body": None, "headers": { - "accept": "application/vnd.elasticsearch+json; compatible-with=8", + "accept": "application/vnd.elasticsearch+json; compatible-with=0", }, "request_timeout": DEFAULT, }, @@ -613,7 +614,7 @@ def test_unsupported_product_error(headers): { "body": None, "headers": { - "accept": "application/vnd.elasticsearch+json; compatible-with=8", + "accept": "application/vnd.elasticsearch+json; compatible-with=0", }, "request_timeout": DEFAULT, },