-
Notifications
You must be signed in to change notification settings - Fork 285
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Version mismatch checks #3989
Merged
Merged
Changes from 4 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
f11b448
Send server version in response headers and warn if clients diverge
anticorrelator 6598c53
Fix logic for only showing minor version mismatch warnings once
anticorrelator f70fc7b
Move clients into utilities to avoid circular imports
anticorrelator 98fe9b9
Don't call `close` in httpx client wrappers
anticorrelator 6472362
Ensure version warnings work for suffixes and missing server versions
anticorrelator 61affca
Do not await sync function
anticorrelator File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
import warnings | ||
from typing import Any | ||
|
||
import httpx | ||
|
||
PHOENIX_SERVER_VERSION_HEADER = "x-phoenix-server-version" | ||
|
||
|
||
class VersionedClient(httpx.Client): | ||
""" | ||
A httpx.Client wrapper that warns if there is a server/client version mismatch. | ||
""" | ||
|
||
def __init__(self, *args: Any, **kwargs: Any): | ||
from phoenix import __version__ as phoenix_version | ||
|
||
super().__init__(*args, **kwargs) | ||
self._client_phoenix_version = phoenix_version | ||
self._major, self._minor, self._patch = map(int, self._client_phoenix_version.split(".")) | ||
anticorrelator marked this conversation as resolved.
Show resolved
Hide resolved
|
||
self._warned_on_minor_version_mismatch = False | ||
|
||
def _check_version(self, response: httpx.Response) -> None: | ||
server_version = response.headers.get(PHOENIX_SERVER_VERSION_HEADER) | ||
if server_version is None: | ||
return | ||
anticorrelator marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
server_major, server_minor, server_patch = map(int, server_version.split(".")) | ||
anticorrelator marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if abs(server_major - self._major) >= 1: | ||
warnings.warn( | ||
f"⚠️⚠️ The Phoenix server ({server_version}) and client " | ||
f"({self._client_phoenix_version}) versions are severely mismatched. Upgrade " | ||
" either the client or server to ensure API compatibility ⚠️⚠️" | ||
) | ||
elif abs(server_minor - self._minor) >= 1 and not self._warned_on_minor_version_mismatch: | ||
self._warned_on_minor_version_mismatch = True | ||
RogerHYang marked this conversation as resolved.
Show resolved
Hide resolved
|
||
warnings.warn( | ||
f"The Phoenix server ({server_version}) and client ({self._client_phoenix_version})" | ||
" versions are mismatched and may have compatibility issues." | ||
) | ||
|
||
def request(self, *args: Any, **kwargs: Any) -> httpx.Response: | ||
response = super().request(*args, **kwargs) | ||
self._check_version(response) | ||
return response | ||
|
||
|
||
class VersionedAsyncClient(httpx.AsyncClient): | ||
""" | ||
A httpx.Client wrapper that warns if there is a server/client version mismatch. | ||
""" | ||
|
||
def __init__(self, *args: Any, **kwargs: Any): | ||
from phoenix import __version__ as phoenix_version | ||
|
||
super().__init__(*args, **kwargs) | ||
self._client_phoenix_version = phoenix_version | ||
self._major, self._minor, self._patch = map(int, self._client_phoenix_version.split(".")) | ||
self._warned_on_minor_version_mismatch = False | ||
|
||
async def _check_version(self, response: httpx.Response) -> None: | ||
anticorrelator marked this conversation as resolved.
Show resolved
Hide resolved
|
||
server_version = response.headers.get(PHOENIX_SERVER_VERSION_HEADER) | ||
if server_version is None: | ||
return | ||
|
||
server_major, server_minor, server_patch = map(int, server_version.split(".")) | ||
if abs(server_major - self._major) >= 1: | ||
warnings.warn( | ||
f"⚠️⚠️ The Phoenix server ({server_version}) and client " | ||
f"({self._client_phoenix_version}) versions are severely mismatched. Upgrade " | ||
" either the client or server to ensure API compatibility ⚠️⚠️" | ||
) | ||
elif abs(server_minor - self._minor) >= 1 and not self._warned_on_minor_version_mismatch: | ||
self._warned_on_minor_version_mismatch = True | ||
warnings.warn( | ||
f"The Phoenix server ({server_version}) and client ({self._client_phoenix_version})" | ||
" versions are mismatched and may have compatibility issues." | ||
) | ||
|
||
async def request(self, *args: Any, **kwargs: Any) -> httpx.Response: | ||
response = await super().request(*args, **kwargs) | ||
await self._check_version(response) | ||
return response |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we avoid this import to keep server and client easily separable?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's easy to separate either way, it's a constant, this is just a way to coordinate on the name. I'd argue that on the hierarchy of couplings we need untangle when making new packages a single name import has never made separating work into a package more or less difficult