Skip to content

Commit

Permalink
Revert "Gzip request body if server support it (#1476)"
Browse files Browse the repository at this point in the history
This reverts commit 799e9d8.
  • Loading branch information
PatrykGala committed Oct 10, 2023
1 parent 519678f commit 6eeaf34
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 32 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

### Changes
- Upgraded performance of sending series data to Neptune ([#1483](https://github.com/neptune-ai/neptune-client/pull/1483))
- Compress (gzip) request to server, when server support it ([#1476](https://github.com/neptune-ai/neptune-client/pull/1476))


## neptune 1.8.1

Expand Down
3 changes: 0 additions & 3 deletions src/neptune/internal/backends/api_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,6 @@ class ClientConfig:
_missing_features: FrozenSet[str]
version_info: VersionInfo
multipart_config: MultipartConfig
gzip_upload: bool

def has_feature(self, feature_name: str) -> bool:
return feature_name not in self._missing_features
Expand Down Expand Up @@ -163,7 +162,6 @@ def from_api_response(config) -> "ClientConfig":
multipart_upload_config = MultipartConfig(
min_chunk_size, max_chunk_size, max_chunk_count, max_single_part_size
)
gzip_upload = getattr(config, "gzipUpload", False)

artifacts_config_obj = getattr(config, "artifacts", None)
has_artifacts = getattr(artifacts_config_obj, "enabled", False)
Expand All @@ -181,7 +179,6 @@ def from_api_response(config) -> "ClientConfig":
_missing_features=frozenset(missing_features),
version_info=VersionInfo.build(min_recommended, min_compatible, max_compatible),
multipart_config=multipart_upload_config,
gzip_upload=gzip_upload,
)


Expand Down
29 changes: 1 addition & 28 deletions src/neptune/internal/backends/hosted_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@

import os
import platform
import zlib
from typing import (
Dict,
Tuple,
Expand All @@ -32,11 +31,6 @@
import requests
from bravado.http_client import HttpClient
from bravado.requests_client import RequestsClient
from requests import (
PreparedRequest,
Response,
)
from requests.adapters import HTTPAdapter

from neptune.common.backends.utils import with_api_exceptions_handler
from neptune.common.oauth import NeptuneAuthenticator
Expand All @@ -54,7 +48,6 @@
verify_host_resolution,
)
from neptune.internal.credentials import Credentials
from neptune.internal.utils.logger import logger
from neptune.version import version as neptune_client_version

BACKEND_SWAGGER_PATH = "/api/backend/swagger.json"
Expand All @@ -73,22 +66,6 @@
}


class GzipAdapter(HTTPAdapter):
def send(self, request: PreparedRequest, stream: bool = False, **kw) -> Response:
if request.body is not None and not stream and request.headers.get("Content-Type", None) == "application/json":
try:
request_body = request.body if isinstance(request.body, bytes) else bytes(request.body, "utf-8")
gzip_compress = zlib.compressobj(zlib.Z_DEFAULT_COMPRESSION, zlib.DEFLATED, zlib.MAX_WBITS | 16)
compressed = gzip_compress.compress(request_body) + gzip_compress.flush()
request.prepare_body(compressed, None)
request.headers["Content-Encoding"] = "gzip"
except zlib.error:
logger.warning("Error on compressing request")
pass

return super(GzipAdapter, self).send(request, stream, **kw)


def _close_connections_on_fork(session: requests.Session):
try:
os.register_at_fork(before=session.close, after_in_child=session.close, after_in_parent=session.close)
Expand Down Expand Up @@ -197,11 +174,7 @@ def create_backend_client(client_config: ClientConfig, http_client: HttpClient)


@cache
def create_leaderboard_client(client_config: ClientConfig, http_client: RequestsClient) -> SwaggerClientWrapper:
if client_config.gzip_upload:
http_client.session.mount("http://", GzipAdapter())
http_client.session.mount("https://", GzipAdapter())

def create_leaderboard_client(client_config: ClientConfig, http_client: HttpClient) -> SwaggerClientWrapper:
return SwaggerClientWrapper(
create_swagger_client(
build_operation_url(client_config.api_url, LEADERBOARD_SWAGGER_PATH),
Expand Down

0 comments on commit 6eeaf34

Please sign in to comment.