dex-python-sdk 1.37.0__tar.gz → 1.38.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {dex_python_sdk-1.37.0 → dex_python_sdk-1.38.0}/PKG-INFO +1 -1
- {dex_python_sdk-1.37.0 → dex_python_sdk-1.38.0}/dex/__init__.py +4 -0
- {dex_python_sdk-1.37.0 → dex_python_sdk-1.38.0}/dex/_async_value_hydrator.py +36 -12
- {dex_python_sdk-1.37.0 → dex_python_sdk-1.38.0}/dex/_credential_transport.py +12 -4
- dex_python_sdk-1.38.0/dex/_message_size.py +88 -0
- {dex_python_sdk-1.37.0 → dex_python_sdk-1.38.0}/dex/_pull_worker.py +12 -6
- {dex_python_sdk-1.37.0 → dex_python_sdk-1.38.0}/dex/_value_hydrator.py +36 -12
- {dex_python_sdk-1.37.0 → dex_python_sdk-1.38.0}/dex/_worker_dispatcher.py +2 -0
- {dex_python_sdk-1.37.0 → dex_python_sdk-1.38.0}/dex/async_client.py +6 -0
- {dex_python_sdk-1.37.0 → dex_python_sdk-1.38.0}/dex/async_worker.py +2 -0
- {dex_python_sdk-1.37.0 → dex_python_sdk-1.38.0}/dex/client.py +6 -0
- {dex_python_sdk-1.37.0 → dex_python_sdk-1.38.0}/dex/client_options.py +13 -0
- dex_python_sdk-1.38.0/dex/dexpb/dex_pb2.py +443 -0
- {dex_python_sdk-1.37.0 → dex_python_sdk-1.38.0}/dex/dexpb/dex_pb2.pyi +4 -2
- dex_python_sdk-1.38.0/dex/flow_config.py +96 -0
- {dex_python_sdk-1.37.0 → dex_python_sdk-1.38.0}/dex/runtime_errors.py +48 -0
- {dex_python_sdk-1.37.0 → dex_python_sdk-1.38.0}/dex/worker.py +2 -0
- {dex_python_sdk-1.37.0 → dex_python_sdk-1.38.0}/dex/worker_options.py +10 -0
- {dex_python_sdk-1.37.0 → dex_python_sdk-1.38.0}/pyproject.toml +1 -1
- dex_python_sdk-1.37.0/dex/dexpb/dex_pb2.py +0 -443
- dex_python_sdk-1.37.0/dex/flow_config.py +0 -56
- {dex_python_sdk-1.37.0 → dex_python_sdk-1.38.0}/LEGACY_NOTICES.md +0 -0
- {dex_python_sdk-1.37.0 → dex_python_sdk-1.38.0}/LICENSE +0 -0
- {dex_python_sdk-1.37.0 → dex_python_sdk-1.38.0}/README.md +0 -0
- {dex_python_sdk-1.37.0 → dex_python_sdk-1.38.0}/dex/_async_worker_dispatcher.py +0 -0
- {dex_python_sdk-1.37.0 → dex_python_sdk-1.38.0}/dex/_attribute_reads.py +0 -0
- {dex_python_sdk-1.37.0 → dex_python_sdk-1.38.0}/dex/_flow_service_tls.py +0 -0
- {dex_python_sdk-1.37.0 → dex_python_sdk-1.38.0}/dex/_grpc_errors.py +0 -0
- {dex_python_sdk-1.37.0 → dex_python_sdk-1.38.0}/dex/_invocation_context.py +0 -0
- {dex_python_sdk-1.37.0 → dex_python_sdk-1.38.0}/dex/_native.pyi +0 -0
- {dex_python_sdk-1.37.0 → dex_python_sdk-1.38.0}/dex/_server_protocol.py +0 -0
- {dex_python_sdk-1.37.0 → dex_python_sdk-1.38.0}/dex/_utils.py +0 -0
- {dex_python_sdk-1.37.0 → dex_python_sdk-1.38.0}/dex/_value_mapper.py +0 -0
- {dex_python_sdk-1.37.0 → dex_python_sdk-1.38.0}/dex/attribute.py +0 -0
- {dex_python_sdk-1.37.0 → dex_python_sdk-1.38.0}/dex/attribute_match.py +0 -0
- {dex_python_sdk-1.37.0 → dex_python_sdk-1.38.0}/dex/attribute_values.py +0 -0
- {dex_python_sdk-1.37.0 → dex_python_sdk-1.38.0}/dex/blob_cache.py +0 -0
- {dex_python_sdk-1.37.0 → dex_python_sdk-1.38.0}/dex/channel.py +0 -0
- {dex_python_sdk-1.37.0 → dex_python_sdk-1.38.0}/dex/codec.py +0 -0
- {dex_python_sdk-1.37.0 → dex_python_sdk-1.38.0}/dex/condition.py +0 -0
- {dex_python_sdk-1.37.0 → dex_python_sdk-1.38.0}/dex/context.py +0 -0
- {dex_python_sdk-1.37.0 → dex_python_sdk-1.38.0}/dex/credential.py +0 -0
- {dex_python_sdk-1.37.0 → dex_python_sdk-1.38.0}/dex/dexpb/__init__.py +0 -0
- {dex_python_sdk-1.37.0 → dex_python_sdk-1.38.0}/dex/dexpb/dex_pb2_grpc.py +0 -0
- {dex_python_sdk-1.37.0 → dex_python_sdk-1.38.0}/dex/flow.py +0 -0
- {dex_python_sdk-1.37.0 → dex_python_sdk-1.38.0}/dex/flow_info.py +0 -0
- {dex_python_sdk-1.37.0 → dex_python_sdk-1.38.0}/dex/flow_options.py +0 -0
- {dex_python_sdk-1.37.0 → dex_python_sdk-1.38.0}/dex/flow_result.py +0 -0
- {dex_python_sdk-1.37.0 → dex_python_sdk-1.38.0}/dex/flow_service_tls_options.py +0 -0
- {dex_python_sdk-1.37.0 → dex_python_sdk-1.38.0}/dex/pull_registration.py +0 -0
- {dex_python_sdk-1.37.0 → dex_python_sdk-1.38.0}/dex/py.typed +0 -0
- {dex_python_sdk-1.37.0 → dex_python_sdk-1.38.0}/dex/rpc_invoke_options.py +0 -0
- {dex_python_sdk-1.37.0 → dex_python_sdk-1.38.0}/dex/step.py +0 -0
- {dex_python_sdk-1.37.0 → dex_python_sdk-1.38.0}/dex/step_execution.py +0 -0
- {dex_python_sdk-1.37.0 → dex_python_sdk-1.38.0}/dex/stream.py +0 -0
- {dex_python_sdk-1.37.0 → dex_python_sdk-1.38.0}/dex/subflow.py +0 -0
- {dex_python_sdk-1.37.0 → dex_python_sdk-1.38.0}/dex/timer.py +0 -0
- {dex_python_sdk-1.37.0 → dex_python_sdk-1.38.0}/dex/wait.py +0 -0
- {dex_python_sdk-1.37.0 → dex_python_sdk-1.38.0}/dex/wait_options.py +0 -0
- {dex_python_sdk-1.37.0 → dex_python_sdk-1.38.0}/sdk-rust/Cargo.lock +0 -0
- {dex_python_sdk-1.37.0 → dex_python_sdk-1.38.0}/sdk-rust/Cargo.toml +0 -0
- {dex_python_sdk-1.37.0 → dex_python_sdk-1.38.0}/sdk-rust/crates/dex-blob-cache/Cargo.toml +0 -0
- {dex_python_sdk-1.37.0 → dex_python_sdk-1.38.0}/sdk-rust/crates/dex-blob-cache/LICENSE +0 -0
- {dex_python_sdk-1.37.0 → dex_python_sdk-1.38.0}/sdk-rust/crates/dex-blob-cache/README.md +0 -0
- {dex_python_sdk-1.37.0 → dex_python_sdk-1.38.0}/sdk-rust/crates/dex-blob-cache/src/config.rs +0 -0
- {dex_python_sdk-1.37.0 → dex_python_sdk-1.38.0}/sdk-rust/crates/dex-blob-cache/src/entry.rs +0 -0
- {dex_python_sdk-1.37.0 → dex_python_sdk-1.38.0}/sdk-rust/crates/dex-blob-cache/src/error.rs +0 -0
- {dex_python_sdk-1.37.0 → dex_python_sdk-1.38.0}/sdk-rust/crates/dex-blob-cache/src/format.rs +0 -0
- {dex_python_sdk-1.37.0 → dex_python_sdk-1.38.0}/sdk-rust/crates/dex-blob-cache/src/lib.rs +0 -0
- {dex_python_sdk-1.37.0 → dex_python_sdk-1.38.0}/sdk-rust/crates/dex-blob-cache/src/policy.rs +0 -0
- {dex_python_sdk-1.37.0 → dex_python_sdk-1.38.0}/sdk-rust/crates/dex-blob-cache/src/store.rs +0 -0
- {dex_python_sdk-1.37.0 → dex_python_sdk-1.38.0}/sdk-rust/crates/dex-blob-cache/tests/blob_cache_integration.rs +0 -0
- {dex_python_sdk-1.37.0 → dex_python_sdk-1.38.0}/sdk-rust/crates/dex-blob-cache-python/Cargo.toml +0 -0
- {dex_python_sdk-1.37.0 → dex_python_sdk-1.38.0}/sdk-rust/crates/dex-blob-cache-python/LICENSE +0 -0
- {dex_python_sdk-1.37.0 → dex_python_sdk-1.38.0}/sdk-rust/crates/dex-blob-cache-python/README.md +0 -0
- {dex_python_sdk-1.37.0 → dex_python_sdk-1.38.0}/sdk-rust/crates/dex-blob-cache-python/src/lib.rs +0 -0
|
@@ -22,6 +22,7 @@ from dex.attribute import (
|
|
|
22
22
|
)
|
|
23
23
|
from dex.attribute_match import AttributeMatch
|
|
24
24
|
from dex.attribute_values import AttributeValues
|
|
25
|
+
from dex._message_size import DEFAULT_GRPC_MAX_MESSAGE_BYTES
|
|
25
26
|
from dex.blob_cache import BlobCache, BlobCacheConfig, open_blob_cache
|
|
26
27
|
from dex.channel import Channel, ChannelMap, ChannelMapLoad, ChannelMessage
|
|
27
28
|
from dex.client import Client
|
|
@@ -80,6 +81,7 @@ from dex.runtime_errors import (
|
|
|
80
81
|
AttributeMapNotLoadedError,
|
|
81
82
|
ChannelMessageNotFoundError,
|
|
82
83
|
ChannelMessagesNotLoadedError,
|
|
84
|
+
BlobMessageTooLargeError,
|
|
83
85
|
DexServiceError,
|
|
84
86
|
ErrorSubStatus,
|
|
85
87
|
FlowAlreadyStartedError,
|
|
@@ -169,6 +171,8 @@ __all__ = [
|
|
|
169
171
|
"CodecRegistry",
|
|
170
172
|
"ConditionCombination",
|
|
171
173
|
"Context",
|
|
174
|
+
"BlobMessageTooLargeError",
|
|
175
|
+
"DEFAULT_GRPC_MAX_MESSAGE_BYTES",
|
|
172
176
|
"DexServiceError",
|
|
173
177
|
"ErrorSubStatus",
|
|
174
178
|
"Flow",
|
|
@@ -10,10 +10,15 @@ from __future__ import annotations
|
|
|
10
10
|
|
|
11
11
|
import logging
|
|
12
12
|
from dataclasses import dataclass, field
|
|
13
|
+
from typing import cast
|
|
13
14
|
|
|
15
|
+
import grpc
|
|
16
|
+
|
|
17
|
+
from dex._message_size import is_grpc_message_size_error
|
|
14
18
|
from dex.blob_cache import BlobCache
|
|
15
19
|
from dex.dexpb import dex_pb2 as pb
|
|
16
20
|
from dex.dexpb import dex_pb2_grpc
|
|
21
|
+
from dex.runtime_errors import BlobMessageTooLargeError
|
|
17
22
|
|
|
18
23
|
_LOGGER = logging.getLogger(__name__)
|
|
19
24
|
|
|
@@ -212,25 +217,44 @@ class AsyncValueHydrator:
|
|
|
212
217
|
async def _load_misses(self, misses: list[_PendingBlob]) -> None:
|
|
213
218
|
if not misses:
|
|
214
219
|
return
|
|
215
|
-
|
|
216
|
-
pb.LoadBlobsRequest(
|
|
217
|
-
entries=[
|
|
218
|
-
pb.LoadBlobRequestEntry(
|
|
219
|
-
flow_id=miss.flow_id,
|
|
220
|
-
blob_value=miss.request,
|
|
221
|
-
)
|
|
222
|
-
for miss in misses
|
|
223
|
-
]
|
|
224
|
-
)
|
|
225
|
-
)
|
|
220
|
+
values = await self._load_blob_values(misses)
|
|
226
221
|
for miss in misses:
|
|
227
|
-
concrete =
|
|
222
|
+
concrete = values.get(miss.blob_id)
|
|
228
223
|
if concrete is None:
|
|
229
224
|
raise RuntimeError(f"LoadBlobs omitted blob {miss.blob_id}")
|
|
230
225
|
self._validate_hydrated(miss, concrete)
|
|
231
226
|
miss.hydrated = concrete
|
|
232
227
|
self._write_cache(miss, concrete)
|
|
233
228
|
|
|
229
|
+
async def _load_blob_values(self, misses: list[_PendingBlob]) -> dict[str, pb.Value]:
|
|
230
|
+
"""Load blobs, halving a batch whose response exceeds a gRPC size limit."""
|
|
231
|
+
try:
|
|
232
|
+
response = await self._service.LoadBlobs(
|
|
233
|
+
pb.LoadBlobsRequest(
|
|
234
|
+
entries=[
|
|
235
|
+
pb.LoadBlobRequestEntry(
|
|
236
|
+
flow_id=miss.flow_id,
|
|
237
|
+
blob_value=miss.request,
|
|
238
|
+
)
|
|
239
|
+
for miss in misses
|
|
240
|
+
]
|
|
241
|
+
)
|
|
242
|
+
)
|
|
243
|
+
except grpc.RpcError as error:
|
|
244
|
+
if not is_grpc_message_size_error(error):
|
|
245
|
+
raise
|
|
246
|
+
if len(misses) == 1:
|
|
247
|
+
raise BlobMessageTooLargeError(
|
|
248
|
+
misses[0].flow_id,
|
|
249
|
+
misses[0].blob_id,
|
|
250
|
+
cast(grpc.Call, error).details() or str(error),
|
|
251
|
+
) from error
|
|
252
|
+
half = len(misses) // 2
|
|
253
|
+
values = await self._load_blob_values(misses[:half])
|
|
254
|
+
values.update(await self._load_blob_values(misses[half:]))
|
|
255
|
+
return values
|
|
256
|
+
return dict(response.values)
|
|
257
|
+
|
|
234
258
|
def _read_cache(self, blob: _PendingBlob) -> pb.Value | None:
|
|
235
259
|
try:
|
|
236
260
|
payload = self._cache.get(self._cache_key(blob))
|
|
@@ -23,6 +23,7 @@ from typing import Any, NamedTuple, cast
|
|
|
23
23
|
|
|
24
24
|
import grpc
|
|
25
25
|
|
|
26
|
+
from dex._message_size import grpc_message_size_channel_options
|
|
26
27
|
from dex._flow_service_tls import FlowServiceTransport, flow_service_transport
|
|
27
28
|
from dex.credential import Credential
|
|
28
29
|
from dex.flow_service_tls_options import FlowServiceTlsOptions
|
|
@@ -326,14 +327,18 @@ def sync_channel(
|
|
|
326
327
|
flow_service_tls: FlowServiceTlsOptions | None = None,
|
|
327
328
|
*,
|
|
328
329
|
transport: FlowServiceTransport | None = None,
|
|
330
|
+
grpc_max_message_bytes: int = 0,
|
|
329
331
|
) -> grpc.Channel:
|
|
330
332
|
if transport is None:
|
|
331
333
|
transport = flow_service_transport(server_address, flow_service_tls)
|
|
334
|
+
message_size_options = grpc_message_size_channel_options(grpc_max_message_bytes)
|
|
332
335
|
channel = (
|
|
333
|
-
grpc.insecure_channel(server_address)
|
|
336
|
+
grpc.insecure_channel(server_address, options=message_size_options)
|
|
334
337
|
if transport.credentials is None
|
|
335
338
|
else grpc.secure_channel(
|
|
336
|
-
transport.target,
|
|
339
|
+
transport.target,
|
|
340
|
+
transport.credentials,
|
|
341
|
+
options=message_size_options + transport.channel_options,
|
|
337
342
|
)
|
|
338
343
|
)
|
|
339
344
|
if credential is None:
|
|
@@ -347,9 +352,11 @@ def async_channel(
|
|
|
347
352
|
flow_service_tls: FlowServiceTlsOptions | None = None,
|
|
348
353
|
*,
|
|
349
354
|
transport: FlowServiceTransport | None = None,
|
|
355
|
+
grpc_max_message_bytes: int = 0,
|
|
350
356
|
) -> grpc.aio.Channel:
|
|
351
357
|
if transport is None:
|
|
352
358
|
transport = flow_service_transport(server_address, flow_service_tls)
|
|
359
|
+
message_size_options = grpc_message_size_channel_options(grpc_max_message_bytes)
|
|
353
360
|
if transport.credentials is not None:
|
|
354
361
|
interceptors = (
|
|
355
362
|
[
|
|
@@ -364,13 +371,14 @@ def async_channel(
|
|
|
364
371
|
return grpc.aio.secure_channel(
|
|
365
372
|
transport.target,
|
|
366
373
|
transport.credentials,
|
|
367
|
-
options=transport.channel_options,
|
|
374
|
+
options=message_size_options + transport.channel_options,
|
|
368
375
|
interceptors=interceptors,
|
|
369
376
|
)
|
|
370
377
|
if credential_runner is None:
|
|
371
|
-
return grpc.aio.insecure_channel(server_address)
|
|
378
|
+
return grpc.aio.insecure_channel(server_address, options=message_size_options)
|
|
372
379
|
return grpc.aio.insecure_channel(
|
|
373
380
|
server_address,
|
|
381
|
+
options=message_size_options,
|
|
374
382
|
interceptors=[
|
|
375
383
|
cast(
|
|
376
384
|
grpc.aio.ClientInterceptor,
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
# Copyright (c) 2026 Super Durable, Inc.
|
|
2
|
+
#
|
|
3
|
+
# Licensed under the Sustainable Use License 1.0.
|
|
4
|
+
# You may not use this file except in compliance with the License.
|
|
5
|
+
# See the LICENSE file in the repository root.
|
|
6
|
+
#
|
|
7
|
+
# SPDX-License-Identifier: LicenseRef-Sustainable-Use-1.0
|
|
8
|
+
|
|
9
|
+
from __future__ import annotations
|
|
10
|
+
|
|
11
|
+
from typing import cast
|
|
12
|
+
|
|
13
|
+
import grpc
|
|
14
|
+
from grpc_status import rpc_status
|
|
15
|
+
|
|
16
|
+
#: The gRPC receive limit of a Client or Worker whose ``grpc_max_message_bytes`` is zero.
|
|
17
|
+
#:
|
|
18
|
+
#: The limit applies to every message the SDK receives: Client responses such as RPC
|
|
19
|
+
#: results and state reads, responses to the Worker's FlowService calls such as LoadBlobs,
|
|
20
|
+
#: and the Step and RPC invocations that Dex sends to a Worker. The default is 32 MiB,
|
|
21
|
+
#: which matches the Dex server's default ``api.grpcMaxMessageBytes``. With the default,
|
|
22
|
+
#: the SDK keeps gRPC's unlimited send limit, so the Dex server's receive limit bounds what
|
|
23
|
+
#: the SDK sends. A positive ``grpc_max_message_bytes`` limits both directions.
|
|
24
|
+
#:
|
|
25
|
+
#: A message carries one or more application values plus an envelope of metadata. Keep the
|
|
26
|
+
#: limit above the largest application value by an explicit margin. The default leaves
|
|
27
|
+
#: 16 MiB of headroom for values up to 16 MiB. When an application needs larger values,
|
|
28
|
+
#: raise both ``grpc_max_message_bytes`` and the server's ``api.grpcMaxMessageBytes``,
|
|
29
|
+
#: because each hop applies the smaller limit of its ends.
|
|
30
|
+
#:
|
|
31
|
+
#: Example:
|
|
32
|
+
#: >>> options = ClientOptions(grpc_max_message_bytes=2 * DEFAULT_GRPC_MAX_MESSAGE_BYTES)
|
|
33
|
+
#:
|
|
34
|
+
#: .. versionadded:: 1.38.0
|
|
35
|
+
DEFAULT_GRPC_MAX_MESSAGE_BYTES = 32 << 20
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def validate_grpc_max_message_bytes(configured: int) -> None:
|
|
39
|
+
if configured < 0:
|
|
40
|
+
raise ValueError(
|
|
41
|
+
f"grpc_max_message_bytes must not be negative, got {configured}"
|
|
42
|
+
)
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def grpc_message_size_channel_options(configured: int) -> tuple[tuple[str, int], ...]:
|
|
46
|
+
if configured == 0:
|
|
47
|
+
return (("grpc.max_receive_message_length", DEFAULT_GRPC_MAX_MESSAGE_BYTES),)
|
|
48
|
+
return (
|
|
49
|
+
("grpc.max_receive_message_length", configured),
|
|
50
|
+
("grpc.max_send_message_length", configured),
|
|
51
|
+
)
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
_GRPC_SIZE_STATUS_CODES = frozenset(
|
|
55
|
+
(grpc.StatusCode.RESOURCE_EXHAUSTED, grpc.StatusCode.OUT_OF_RANGE)
|
|
56
|
+
)
|
|
57
|
+
|
|
58
|
+
# Lowercase diagnostics of gRPC message size limits; transports reuse the codes otherwise.
|
|
59
|
+
_GRPC_SIZE_DIAGNOSTICS = (
|
|
60
|
+
"message larger than max",
|
|
61
|
+
"message after decompression larger than max",
|
|
62
|
+
"message too large",
|
|
63
|
+
"message with a size larger than",
|
|
64
|
+
"decompresses to a size larger than",
|
|
65
|
+
"message length too large",
|
|
66
|
+
"exceeded while decompressing message",
|
|
67
|
+
"cannot return body with more than 4gb of data",
|
|
68
|
+
)
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
def is_grpc_message_size_error(error: grpc.RpcError) -> bool:
|
|
72
|
+
"""Report a gRPC size rejection, which carries no Dex service error details.
|
|
73
|
+
|
|
74
|
+
The receiver's limit yields RESOURCE_EXHAUSTED, and a tonic server's send limit
|
|
75
|
+
yields OUT_OF_RANGE. The message must also name a size limit, because HTTP/2 flow
|
|
76
|
+
control failures reuse RESOURCE_EXHAUSTED without details.
|
|
77
|
+
"""
|
|
78
|
+
call = cast(grpc.Call, error)
|
|
79
|
+
if call.code() not in _GRPC_SIZE_STATUS_CODES:
|
|
80
|
+
return False
|
|
81
|
+
message = (call.details() or "").lower()
|
|
82
|
+
if not any(diagnostic in message for diagnostic in _GRPC_SIZE_DIAGNOSTICS):
|
|
83
|
+
return False
|
|
84
|
+
try:
|
|
85
|
+
status = rpc_status.from_call(call)
|
|
86
|
+
except ValueError:
|
|
87
|
+
return False
|
|
88
|
+
return status is None or not status.details
|
|
@@ -29,6 +29,7 @@ from dex._credential_transport import (
|
|
|
29
29
|
)
|
|
30
30
|
from dex._flow_service_tls import FlowServiceTransport
|
|
31
31
|
from dex._grpc_errors import _worker_error_status
|
|
32
|
+
from dex._message_size import grpc_message_size_channel_options
|
|
32
33
|
from dex._server_protocol import sdk_version
|
|
33
34
|
from dex.dexpb import dex_pb2 as pb
|
|
34
35
|
from dex.dexpb import dex_pb2_grpc
|
|
@@ -76,17 +77,20 @@ _IDENTITY_COMPRESSION_ONLY_OPTIONS = (
|
|
|
76
77
|
|
|
77
78
|
|
|
78
79
|
def outbound_worker_task_channel(
|
|
79
|
-
server_address: str,
|
|
80
|
+
server_address: str,
|
|
81
|
+
transport: FlowServiceTransport | None = None,
|
|
82
|
+
grpc_max_message_bytes: int = 0,
|
|
80
83
|
) -> grpc.aio.Channel:
|
|
84
|
+
options = _IDENTITY_COMPRESSION_ONLY_OPTIONS + grpc_message_size_channel_options(
|
|
85
|
+
grpc_max_message_bytes
|
|
86
|
+
)
|
|
81
87
|
if transport is not None and transport.credentials is not None:
|
|
82
88
|
return grpc.aio.secure_channel(
|
|
83
89
|
transport.target,
|
|
84
90
|
transport.credentials,
|
|
85
|
-
options=
|
|
91
|
+
options=options + transport.channel_options,
|
|
86
92
|
)
|
|
87
|
-
return grpc.aio.insecure_channel(
|
|
88
|
-
server_address, options=_IDENTITY_COMPRESSION_ONLY_OPTIONS
|
|
89
|
-
)
|
|
93
|
+
return grpc.aio.insecure_channel(server_address, options=options)
|
|
90
94
|
|
|
91
95
|
|
|
92
96
|
def resolve_app_worker_id(registry: Registry, options: PullWorkerOptions) -> str:
|
|
@@ -107,8 +111,10 @@ class PullWorkerRuntime:
|
|
|
107
111
|
app_worker_id: str | None = None,
|
|
108
112
|
credential_runner: AsyncCredentialRunner | None = None,
|
|
109
113
|
transport: FlowServiceTransport | None = None,
|
|
114
|
+
grpc_max_message_bytes: int = 0,
|
|
110
115
|
) -> None:
|
|
111
116
|
self._transport = transport
|
|
117
|
+
self._grpc_max_message_bytes = grpc_max_message_bytes
|
|
112
118
|
self._registry = registry
|
|
113
119
|
self.app_worker_id = app_worker_id or resolve_app_worker_id(registry, options)
|
|
114
120
|
self.flow_types = sorted(registry._registered_flows)
|
|
@@ -183,7 +189,7 @@ class PullWorkerRuntime:
|
|
|
183
189
|
channel: grpc.aio.Channel | None = None
|
|
184
190
|
try:
|
|
185
191
|
channel = outbound_worker_task_channel(
|
|
186
|
-
self._server_address, self._transport
|
|
192
|
+
self._server_address, self._transport, self._grpc_max_message_bytes
|
|
187
193
|
)
|
|
188
194
|
stub = dex_pb2_grpc.WorkerTaskServiceStub(channel) # type: ignore[no-untyped-call]
|
|
189
195
|
self._wake.set()
|
|
@@ -10,10 +10,15 @@ from __future__ import annotations
|
|
|
10
10
|
|
|
11
11
|
import logging
|
|
12
12
|
from dataclasses import dataclass, field
|
|
13
|
+
from typing import cast
|
|
13
14
|
|
|
15
|
+
import grpc
|
|
16
|
+
|
|
17
|
+
from dex._message_size import is_grpc_message_size_error
|
|
14
18
|
from dex.blob_cache import BlobCache
|
|
15
19
|
from dex.dexpb import dex_pb2 as pb
|
|
16
20
|
from dex.dexpb import dex_pb2_grpc
|
|
21
|
+
from dex.runtime_errors import BlobMessageTooLargeError
|
|
17
22
|
|
|
18
23
|
_LOGGER = logging.getLogger(__name__)
|
|
19
24
|
|
|
@@ -206,25 +211,44 @@ class ValueHydrator:
|
|
|
206
211
|
def _load_misses(self, misses: list[_PendingBlob]) -> None:
|
|
207
212
|
if not misses:
|
|
208
213
|
return
|
|
209
|
-
|
|
210
|
-
pb.LoadBlobsRequest(
|
|
211
|
-
entries=[
|
|
212
|
-
pb.LoadBlobRequestEntry(
|
|
213
|
-
flow_id=miss.flow_id,
|
|
214
|
-
blob_value=miss.request,
|
|
215
|
-
)
|
|
216
|
-
for miss in misses
|
|
217
|
-
]
|
|
218
|
-
)
|
|
219
|
-
)
|
|
214
|
+
values = self._load_blob_values(misses)
|
|
220
215
|
for miss in misses:
|
|
221
|
-
concrete =
|
|
216
|
+
concrete = values.get(miss.blob_id)
|
|
222
217
|
if concrete is None:
|
|
223
218
|
raise RuntimeError(f"LoadBlobs omitted blob {miss.blob_id}")
|
|
224
219
|
self._validate_hydrated(miss, concrete)
|
|
225
220
|
miss.hydrated = concrete
|
|
226
221
|
self._write_cache(miss, concrete)
|
|
227
222
|
|
|
223
|
+
def _load_blob_values(self, misses: list[_PendingBlob]) -> dict[str, pb.Value]:
|
|
224
|
+
"""Load blobs, halving a batch whose response exceeds a gRPC size limit."""
|
|
225
|
+
try:
|
|
226
|
+
response = self._service.LoadBlobs(
|
|
227
|
+
pb.LoadBlobsRequest(
|
|
228
|
+
entries=[
|
|
229
|
+
pb.LoadBlobRequestEntry(
|
|
230
|
+
flow_id=miss.flow_id,
|
|
231
|
+
blob_value=miss.request,
|
|
232
|
+
)
|
|
233
|
+
for miss in misses
|
|
234
|
+
]
|
|
235
|
+
)
|
|
236
|
+
)
|
|
237
|
+
except grpc.RpcError as error:
|
|
238
|
+
if not is_grpc_message_size_error(error):
|
|
239
|
+
raise
|
|
240
|
+
if len(misses) == 1:
|
|
241
|
+
raise BlobMessageTooLargeError(
|
|
242
|
+
misses[0].flow_id,
|
|
243
|
+
misses[0].blob_id,
|
|
244
|
+
cast(grpc.Call, error).details() or str(error),
|
|
245
|
+
) from error
|
|
246
|
+
half = len(misses) // 2
|
|
247
|
+
values = self._load_blob_values(misses[:half])
|
|
248
|
+
values.update(self._load_blob_values(misses[half:]))
|
|
249
|
+
return values
|
|
250
|
+
return dict(response.values)
|
|
251
|
+
|
|
228
252
|
def _read_cache(self, blob: _PendingBlob) -> pb.Value | None:
|
|
229
253
|
try:
|
|
230
254
|
payload = self._cache.get(self._cache_key(blob))
|
|
@@ -775,6 +775,8 @@ class WorkerDispatcher:
|
|
|
775
775
|
mapped.attribute_store_names.CopyFrom(
|
|
776
776
|
pb.AttributeStoreNames(names=config.attribute_store_names)
|
|
777
777
|
)
|
|
778
|
+
if config.history_window_events is not None:
|
|
779
|
+
mapped.history_window_events = config.history_window_events
|
|
778
780
|
return mapped
|
|
779
781
|
|
|
780
782
|
def _map_decision(
|
|
@@ -67,6 +67,7 @@ from dex.flow_options import (
|
|
|
67
67
|
)
|
|
68
68
|
from dex.flow_result import FlowResult, flow_result_from_proto
|
|
69
69
|
from dex.runtime_errors import (
|
|
70
|
+
BlobMessageTooLargeError,
|
|
70
71
|
DexServiceError,
|
|
71
72
|
ErrorSubStatus,
|
|
72
73
|
FlowErrorType,
|
|
@@ -150,6 +151,7 @@ class AsyncClient:
|
|
|
150
151
|
self.options.server_address,
|
|
151
152
|
self._credential_runner,
|
|
152
153
|
self.options.flow_service_tls,
|
|
154
|
+
grpc_max_message_bytes=self.options.grpc_max_message_bytes,
|
|
153
155
|
)
|
|
154
156
|
self._service = dex_pb2_grpc.FlowServiceStub( # type: ignore[no-untyped-call]
|
|
155
157
|
self._channel
|
|
@@ -807,6 +809,8 @@ class AsyncClient:
|
|
|
807
809
|
)
|
|
808
810
|
except grpc.RpcError as error:
|
|
809
811
|
raise plan.service_error(error, "LoadBlobs") from error
|
|
812
|
+
except BlobMessageTooLargeError:
|
|
813
|
+
raise
|
|
810
814
|
except (ValueError, RuntimeError) as error:
|
|
811
815
|
raise plan.hydration_error(error) from error
|
|
812
816
|
return plan.decode(self._values, entries, hydrated)
|
|
@@ -1475,6 +1479,8 @@ class AsyncClient:
|
|
|
1475
1479
|
mapped.attribute_store_names.CopyFrom(
|
|
1476
1480
|
pb.AttributeStoreNames(names=config.attribute_store_names)
|
|
1477
1481
|
)
|
|
1482
|
+
if config.history_window_events is not None:
|
|
1483
|
+
mapped.history_window_events = config.history_window_events
|
|
1478
1484
|
return mapped
|
|
1479
1485
|
|
|
1480
1486
|
@staticmethod
|
|
@@ -89,6 +89,7 @@ class AsyncWorker:
|
|
|
89
89
|
self.options.server_address,
|
|
90
90
|
self._credential_runner,
|
|
91
91
|
transport=transport,
|
|
92
|
+
grpc_max_message_bytes=self.options.grpc_max_message_bytes,
|
|
92
93
|
)
|
|
93
94
|
self._flow_service = dex_pb2_grpc.FlowServiceStub( # type: ignore[no-untyped-call]
|
|
94
95
|
self._flow_channel
|
|
@@ -112,6 +113,7 @@ class AsyncWorker:
|
|
|
112
113
|
app_worker_id,
|
|
113
114
|
self._credential_runner,
|
|
114
115
|
transport=transport,
|
|
116
|
+
grpc_max_message_bytes=self.options.grpc_max_message_bytes,
|
|
115
117
|
)
|
|
116
118
|
self._stopped = asyncio.Event()
|
|
117
119
|
|
|
@@ -67,6 +67,7 @@ from dex.flow_options import (
|
|
|
67
67
|
)
|
|
68
68
|
from dex.flow_result import FlowResult, flow_result_from_proto
|
|
69
69
|
from dex.runtime_errors import (
|
|
70
|
+
BlobMessageTooLargeError,
|
|
70
71
|
DexServiceError,
|
|
71
72
|
ErrorSubStatus,
|
|
72
73
|
FlowErrorType,
|
|
@@ -145,6 +146,7 @@ class Client:
|
|
|
145
146
|
self.options.server_address,
|
|
146
147
|
self.options.credential,
|
|
147
148
|
self.options.flow_service_tls,
|
|
149
|
+
grpc_max_message_bytes=self.options.grpc_max_message_bytes,
|
|
148
150
|
)
|
|
149
151
|
self._service = dex_pb2_grpc.FlowServiceStub( # type: ignore[no-untyped-call]
|
|
150
152
|
self._channel
|
|
@@ -822,6 +824,8 @@ class Client:
|
|
|
822
824
|
)
|
|
823
825
|
except grpc.RpcError as error:
|
|
824
826
|
raise plan.service_error(error, "LoadBlobs") from error
|
|
827
|
+
except BlobMessageTooLargeError:
|
|
828
|
+
raise
|
|
825
829
|
except (ValueError, RuntimeError) as error:
|
|
826
830
|
raise plan.hydration_error(error) from error
|
|
827
831
|
return plan.decode(self._values, entries, hydrated)
|
|
@@ -1483,6 +1487,8 @@ class Client:
|
|
|
1483
1487
|
mapped.attribute_store_names.CopyFrom(
|
|
1484
1488
|
pb.AttributeStoreNames(names=config.attribute_store_names)
|
|
1485
1489
|
)
|
|
1490
|
+
if config.history_window_events is not None:
|
|
1491
|
+
mapped.history_window_events = config.history_window_events
|
|
1486
1492
|
return mapped
|
|
1487
1493
|
|
|
1488
1494
|
@staticmethod
|
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
|
|
11
11
|
from dataclasses import dataclass
|
|
12
12
|
|
|
13
|
+
from dex._message_size import validate_grpc_max_message_bytes
|
|
13
14
|
from dex.credential import Credential
|
|
14
15
|
from dex.flow_service_tls_options import FlowServiceTlsOptions
|
|
15
16
|
|
|
@@ -29,8 +30,20 @@ class ClientOptions:
|
|
|
29
30
|
call before contacting Dex. AsyncClient accepts an awaitable token
|
|
30
31
|
and bounds its lookup by the RPC timeout when set. Synchronous token
|
|
31
32
|
lookup must return promptly. Enable TLS to protect bearer tokens in transit.
|
|
33
|
+
grpc_max_message_bytes: Largest gRPC message this Client exchanges with Dex,
|
|
34
|
+
in bytes. Zero, the default, receives up to
|
|
35
|
+
``DEFAULT_GRPC_MAX_MESSAGE_BYTES`` (32 MiB) and leaves sends unlimited,
|
|
36
|
+
so the server's limit bounds them. A positive value limits both
|
|
37
|
+
directions. A negative value raises ``ValueError``. Raise it with the
|
|
38
|
+
server's ``api.grpcMaxMessageBytes`` when one message must carry more.
|
|
39
|
+
|
|
40
|
+
.. versionadded:: 1.38.0
|
|
32
41
|
"""
|
|
33
42
|
|
|
34
43
|
server_address: str = "localhost:8801"
|
|
35
44
|
credential: Credential | None = None
|
|
36
45
|
flow_service_tls: FlowServiceTlsOptions | None = None
|
|
46
|
+
grpc_max_message_bytes: int = 0
|
|
47
|
+
|
|
48
|
+
def __post_init__(self) -> None:
|
|
49
|
+
validate_grpc_max_message_bytes(self.grpc_max_message_bytes)
|