diff --git a/st2api/st2api/controllers/v1/actionexecutions.py b/st2api/st2api/controllers/v1/actionexecutions.py index 714f1977f1..4ff9f023fe 100644 --- a/st2api/st2api/controllers/v1/actionexecutions.py +++ b/st2api/st2api/controllers/v1/actionexecutions.py @@ -27,6 +27,7 @@ from oslo_config import cfg from six.moves import http_client from mongoengine.queryset.visitor import Q +import zstandard from st2api.controllers.base import BaseRestControllerMixin from st2api.controllers.resource import ResourceController @@ -438,12 +439,16 @@ def get( # For new JSON storage format we just use raw value since it's already JSON serialized # string response_body = result["result"] - + try: + response_body = zstandard.ZstdDecompressor().decompress(response_body) + # skip if already a byte string and not compressed + except zstandard.ZstdError: + pass if pretty_format: # Pretty format is not a default behavior since it adds quite some overhead (e.g. # 10-30ms for non pretty format for 4 MB json vs ~120 ms for pretty formatted) response_body = orjson.dumps( - orjson.loads(result["result"]), option=orjson.OPT_INDENT_2 + orjson.loads(response_body), option=orjson.OPT_INDENT_2 ) response = Response() diff --git a/st2common/st2common/fields.py b/st2common/st2common/fields.py index 8ee1a0f603..8ad17d7925 100644 --- a/st2common/st2common/fields.py +++ b/st2common/st2common/fields.py @@ -414,7 +414,7 @@ def parse_field_value(self, value: Optional[Union[bytes, dict]]) -> dict: data = orjson.loads(data) return data - def _serialize_field_value(self, value: dict) -> bytes: + def _serialize_field_value(self, value: dict, zstd=True) -> bytes: """ Serialize and encode the provided field value. """ @@ -434,8 +434,9 @@ def default(obj): return list(obj) raise TypeError - value = orjson.dumps(value, default=default) - data = zstandard.ZstdCompressor().compress(value) + data = orjson.dumps(value, default=default) + if zstd: + data = zstandard.ZstdCompressor().compress(data) return data diff --git a/st2common/st2common/services/executions.py b/st2common/st2common/services/executions.py index 4c190b69fb..a5d3179010 100644 --- a/st2common/st2common/services/executions.py +++ b/st2common/st2common/services/executions.py @@ -224,7 +224,7 @@ def update_execution(liveaction_db, publish=True, set_result_size=False): with Timer(key="action.executions.calculate_result_size"): result_size = len( ActionExecutionDB.result._serialize_field_value( - liveaction_db.result + value=liveaction_db.result, zstd=False ) ) kw["set__result_size"] = result_size