Skip to content

Conversation

HonakerM
Copy link
Contributor

What this PR does / why we need it:
This PR adds support for setting a maximum session/channel age in the RemoteModuleBase. This is primarily useful for grpc connections which only poll dns once on creation. This means that if you add a downstream server (like Kubernetes HPA) to the DNS pool existing grpc channels won't "discover" the new replicas until the pod has been restarted.

Special notes for your reviewer:

If applicable:

  • this PR contains documentation
  • this PR contains unit tests
  • this PR has been tested for backwards compatibility

Signed-off-by: Michael Honaker <Michael.Honaker@ibm.com>
Signed-off-by: Michael Honaker <Michael.Honaker@ibm.com>
Copy link
Collaborator

@gabe-l-hart gabe-l-hart left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One typo nit pick and a couple of suggestions

Comment on lines 483 to 489
# If the max session age is less then 0 then reuse the existing con channel
elif self._connection.max_session_age < 0:
pass

# If the current time is greater than the conn channel timeout then construct a
# new channel
elif datetime.now() - self._current_conn_time > self._max_conn_delta:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The elif...pass is a bit confusing. I'd suggest merging these into a single elif

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call, I was trying to be explicit but just made it more confusing

def test_remote_initializer_always_new_channel(
sample_task_model_id, open_port, protocol
):
"""Test to ensure RemoteModule Initializer negative max connection age always creates
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"""Test to ensure RemoteModule Initializer negative max connection age always creates
"""Test to ensure RemoteModule Initializer zero max connection age always creates

remote_model = remote_initializer.init(remote_config)
assert isinstance(remote_model, ModuleBase)

# Run RemoteModule Request twice to ensure the channel is retained. Run the second one with a small sleep to ensure the third request gets a new object
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need a new definition of "small sleep!" I worry this is a little error prone with sleep-based behavior. Could we use a mock to patch over the time.time function to make it appear as "timed out" on the third call?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call on mock! Done

Copy link
Collaborator

@gabe-l-hart gabe-l-hart left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great, ship it!

Signed-off-by: Michael Honaker <Michael.Honaker@ibm.com>
@HonakerM HonakerM force-pushed the max_client_con_age branch from 9675378 to 35650b3 Compare August 28, 2024 12:52
@gabe-l-hart gabe-l-hart merged commit 5124636 into caikit:main Aug 28, 2024
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants