Skip to content

Commit

Permalink
perf: offer stream_logs for BoundFunction (#160)
Browse files Browse the repository at this point in the history
* chore: offer proto stream_logs for TaskMetadata

* refactor: avoid unnecessary field in class

* feat: handle stream_logs in TaskMetadata

* test

* fix

* separate in 2 rpc

* revert queue changes

* add into bound func

* adapt code

* adapt tests

* fix default for remote connection
  • Loading branch information
chamini2 authored Jan 14, 2025
1 parent 2f44911 commit 64144e9
Show file tree
Hide file tree
Showing 14 changed files with 142 additions and 277 deletions.
1 change: 1 addition & 0 deletions src/isolate/backends/remote.py
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ def run(
was_it_raised=False,
),
environments=self.definitions,
stream_logs=True, # Default to streaming logs
)

return_value = []
Expand Down
6 changes: 3 additions & 3 deletions src/isolate/connections/grpc/definitions/agent_pb2.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

44 changes: 4 additions & 40 deletions src/isolate/connections/grpc/definitions/agent_pb2_grpc.py
Original file line number Diff line number Diff line change
@@ -1,35 +1,10 @@
# Generated by the gRPC Python protocol compiler plugin. DO NOT EDIT!
"""Client and server classes corresponding to protobuf-defined services."""
import grpc
import warnings

from isolate.connections.grpc.definitions import agent_pb2 as agent__pb2
from isolate.connections.grpc.definitions import common_pb2 as common__pb2

GRPC_GENERATED_VERSION = '1.64.0'
GRPC_VERSION = grpc.__version__
EXPECTED_ERROR_RELEASE = '1.65.0'
SCHEDULED_RELEASE_DATE = 'June 25, 2024'
_version_not_supported = False

try:
from grpc._utilities import first_version_is_lower
_version_not_supported = first_version_is_lower(GRPC_VERSION, GRPC_GENERATED_VERSION)
except ImportError:
_version_not_supported = True

if _version_not_supported:
warnings.warn(
f'The grpc package installed is at version {GRPC_VERSION},'
+ f' but the generated code in agent_pb2_grpc.py depends on'
+ f' grpcio>={GRPC_GENERATED_VERSION}.'
+ f' Please upgrade your grpc module to grpcio>={GRPC_GENERATED_VERSION}'
+ f' or downgrade your generated code using grpcio-tools<={GRPC_VERSION}.'
+ f' This warning will become an error in {EXPECTED_ERROR_RELEASE},'
+ f' scheduled for release on {SCHEDULED_RELEASE_DATE}.',
RuntimeWarning
)


class AgentStub(object):
"""Missing associated documentation comment in .proto file."""
Expand All @@ -44,7 +19,7 @@ def __init__(self, channel):
'/Agent/Run',
request_serializer=agent__pb2.FunctionCall.SerializeToString,
response_deserializer=common__pb2.PartialRunResult.FromString,
_registered_method=True)
)


class AgentServicer(object):
Expand All @@ -69,7 +44,6 @@ def add_AgentServicer_to_server(servicer, server):
generic_handler = grpc.method_handlers_generic_handler(
'Agent', rpc_method_handlers)
server.add_generic_rpc_handlers((generic_handler,))
server.add_registered_method_handlers('Agent', rpc_method_handlers)


# This class is part of an EXPERIMENTAL API.
Expand All @@ -87,18 +61,8 @@ def Run(request,
wait_for_ready=None,
timeout=None,
metadata=None):
return grpc.experimental.unary_stream(
request,
target,
'/Agent/Run',
return grpc.experimental.unary_stream(request, target, '/Agent/Run',
agent__pb2.FunctionCall.SerializeToString,
common__pb2.PartialRunResult.FromString,
options,
channel_credentials,
insecure,
call_credentials,
compression,
wait_for_ready,
timeout,
metadata,
_registered_method=True)
options, channel_credentials,
insecure, call_credentials, compression, wait_for_ready, timeout, metadata)
6 changes: 3 additions & 3 deletions src/isolate/connections/grpc/definitions/common_pb2.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 0 additions & 25 deletions src/isolate/connections/grpc/definitions/common_pb2_grpc.py
Original file line number Diff line number Diff line change
@@ -1,29 +1,4 @@
# Generated by the gRPC Python protocol compiler plugin. DO NOT EDIT!
"""Client and server classes corresponding to protobuf-defined services."""
import grpc
import warnings


GRPC_GENERATED_VERSION = '1.64.0'
GRPC_VERSION = grpc.__version__
EXPECTED_ERROR_RELEASE = '1.65.0'
SCHEDULED_RELEASE_DATE = 'June 25, 2024'
_version_not_supported = False

try:
from grpc._utilities import first_version_is_lower
_version_not_supported = first_version_is_lower(GRPC_VERSION, GRPC_GENERATED_VERSION)
except ImportError:
_version_not_supported = True

if _version_not_supported:
warnings.warn(
f'The grpc package installed is at version {GRPC_VERSION},'
+ f' but the generated code in common_pb2_grpc.py depends on'
+ f' grpcio>={GRPC_GENERATED_VERSION}.'
+ f' Please upgrade your grpc module to grpcio>={GRPC_GENERATED_VERSION}'
+ f' or downgrade your generated code using grpcio-tools<={GRPC_VERSION}.'
+ f' This warning will become an error in {EXPECTED_ERROR_RELEASE},'
+ f' scheduled for release on {SCHEDULED_RELEASE_DATE}.',
RuntimeWarning
)
3 changes: 0 additions & 3 deletions src/isolate/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,3 @@ def from_env(cls) -> "IsolateLogger":
print("Failed to parse ISOLATE_LOG_LABELS")

return cls.with_env_expanded(labels=_labels)


ENV_LOGGER = IsolateLogger.from_env()
1 change: 1 addition & 0 deletions src/isolate/server/definitions/server.proto
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ message BoundFunction {
repeated EnvironmentDefinition environments = 1;
SerializedObject function = 2;
optional SerializedObject setup_func = 3;
bool stream_logs = 4;
}

message EnvironmentDefinition {
Expand Down
64 changes: 32 additions & 32 deletions src/isolate/server/definitions/server_pb2.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion src/isolate/server/definitions/server_pb2.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -25,21 +25,24 @@ class BoundFunction(google.protobuf.message.Message):
ENVIRONMENTS_FIELD_NUMBER: builtins.int
FUNCTION_FIELD_NUMBER: builtins.int
SETUP_FUNC_FIELD_NUMBER: builtins.int
STREAM_LOGS_FIELD_NUMBER: builtins.int
@property
def environments(self) -> google.protobuf.internal.containers.RepeatedCompositeFieldContainer[global___EnvironmentDefinition]: ...
@property
def function(self) -> common_pb2.SerializedObject: ...
@property
def setup_func(self) -> common_pb2.SerializedObject: ...
stream_logs: builtins.bool
def __init__(
self,
*,
environments: collections.abc.Iterable[global___EnvironmentDefinition] | None = ...,
function: common_pb2.SerializedObject | None = ...,
setup_func: common_pb2.SerializedObject | None = ...,
stream_logs: builtins.bool = ...,
) -> None: ...
def HasField(self, field_name: typing_extensions.Literal["_setup_func", b"_setup_func", "function", b"function", "setup_func", b"setup_func"]) -> builtins.bool: ...
def ClearField(self, field_name: typing_extensions.Literal["_setup_func", b"_setup_func", "environments", b"environments", "function", b"function", "setup_func", b"setup_func"]) -> None: ...
def ClearField(self, field_name: typing_extensions.Literal["_setup_func", b"_setup_func", "environments", b"environments", "function", b"function", "setup_func", b"setup_func", "stream_logs", b"stream_logs"]) -> None: ...
def WhichOneof(self, oneof_group: typing_extensions.Literal["_setup_func", b"_setup_func"]) -> typing_extensions.Literal["setup_func"] | None: ...

global___BoundFunction = BoundFunction
Expand Down
Loading

0 comments on commit 64144e9

Please sign in to comment.