From 2083b1f86e4ce58078042aded3c26a488d00e624 Mon Sep 17 00:00:00 2001 From: thomasht86 Date: Mon, 16 Sep 2024 14:02:19 +0200 Subject: [PATCH 1/2] expose compress-arg --- vespa/application.py | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/vespa/application.py b/vespa/application.py index 8400fdb0..f57848e4 100644 --- a/vespa/application.py +++ b/vespa/application.py @@ -174,7 +174,10 @@ def syncio( :return: Instance of Vespa asynchronous layer. """ return VespaSync( - app=self, pool_connections=connections, pool_maxsize=connections + app=self, + pool_connections=connections, + pool_maxsize=connections, + compress=compress, ) @staticmethod @@ -299,6 +302,7 @@ def feed_data_point( fields: Dict, namespace: str = None, groupname: str = None, + compress: Union[str, bool] = "auto", **kwargs, ) -> VespaResponse: """ @@ -325,13 +329,16 @@ def feed_data_point( :param fields: Dict containing all the fields required by the `schema`. :param namespace: The namespace that we are sending data to. :param groupname: The groupname that we are sending data + :param compress (Union[str, bool], optional): Whether to compress the request body. Defaults to "auto", which will compress if the body is larger than 1024 bytes. :return: VespaResponse of the HTTP POST request. """ if not namespace: namespace = schema # Use low low connection settings to avoid too much overhead for a # single data point - with VespaSync(app=self, pool_connections=1, pool_maxsize=1) as sync_app: + with VespaSync( + app=self, pool_connections=1, pool_maxsize=1, compress=compress + ) as sync_app: return sync_app.feed_data_point( schema=schema, data_id=data_id, @@ -351,6 +358,7 @@ def feed_iterable( max_queue_size: int = 1000, max_workers: int = 8, max_connections: int = 16, + compress: Union[str, bool] = "auto", **kwargs, ): """ @@ -378,6 +386,7 @@ def callback(response, id): :param max_queue_size: The maximum size of the blocking queue and max in-flight operations. :param max_workers: The maximum number of workers in the threadpool executor. :param max_connections: The maximum number of persisted connections to the Vespa endpoint. + :param compress (Union[str, bool], optional): Whether to compress the request body. Defaults to "auto", which will compress if the body is larger than 1024 bytes. :param kwargs: Additional parameters are passed to the respective operation type specific :func:`_data_point`. """ if operation_type not in ["feed", "update", "delete"]: @@ -519,6 +528,7 @@ def _handle_result_callback( app=self, pool_maxsize=max_connections, pool_connections=max_connections, + compress=compress, ) as session: queue = Queue(maxsize=max_queue_size) with ThreadPoolExecutor(max_workers=max_workers) as executor: @@ -829,6 +839,7 @@ def update_data( create: bool = False, namespace: str = None, groupname: str = None, + compress: Union[str, bool] = "auto", **kwargs, ) -> VespaResponse: """ @@ -852,11 +863,14 @@ def update_data( :param auto_assign: Assumes `fields`-parameter is an assignment operation. (https://docs.vespa.ai/en/reference/document-json-format.html#assign). If set to false, the fields parameter should be a dictionary including the update operation. :param namespace: The namespace that we are updating data. If no namespace is provided the schema is used. :param groupname: The groupname that we are updating data. + :param compress (Union[str, bool], optional): Whether to compress the request body. Defaults to "auto", which will compress if the body is larger than 1024 bytes. :param kwargs: Additional arguments to be passed to the HTTP PUT request. https://docs.vespa.ai/en/reference/document-v1-api-reference.html#request-parameters :return: Response of the HTTP PUT request. """ - with VespaSync(self, pool_connections=1, pool_maxsize=1) as sync_app: + with VespaSync( + self, pool_connections=1, pool_maxsize=1, compress=compress + ) as sync_app: return sync_app.update_data( schema=schema, data_id=data_id, From ed25f759bc1d7b624008af2f91990b52580531f7 Mon Sep 17 00:00:00 2001 From: thomasht86 Date: Mon, 16 Sep 2024 14:43:51 +0200 Subject: [PATCH 2/2] remove none from test args --- tests/integration/test_integration_docker.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/integration/test_integration_docker.py b/tests/integration/test_integration_docker.py index ae011659..7bfd6d0f 100644 --- a/tests/integration/test_integration_docker.py +++ b/tests/integration/test_integration_docker.py @@ -1011,7 +1011,7 @@ def setUp(self) -> None: for i in range(10) ] self.queries_first_hit = ["this is title 1", "this is title 2"] - self.compress_args = [True, False, "auto", None] + self.compress_args = [True, False, "auto"] def test_is_using_http2_client(self): asyncio.run(self.async_is_http2_client(app=self.app))