Skip to content

build: bump grpcio dependencies #1904

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

Closed
wants to merge 15 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 22 additions & 20 deletions .github/workflows/ci_cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -481,11 +481,6 @@ jobs:
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Pull and launch geometry service
run: |
docker pull ${{ env.ANSRV_GEO_IMAGE_MINREQS }}
docker run --detach --name ${{ env.GEO_CONT_NAME }} -e LICENSE_SERVER=${{ env.ANSRV_GEO_LICENSE_SERVER }} -p ${{ env.ANSRV_GEO_PORT }}:50051 ${{ env.ANSRV_GEO_IMAGE_MINREQS }}

- name: Checkout repository
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2

Expand All @@ -500,6 +495,12 @@ jobs:
pip install -e .[all,tests-minimal]
pip install pytest

- name: Start Geometry service and verify start
run: |
docker pull ${{ env.ANSRV_GEO_IMAGE_MINREQS }}
docker run --detach --name ${{ env.GEO_CONT_NAME }} -e LICENSE_SERVER=${{ env.ANSRV_GEO_LICENSE_SERVER }} -p ${{ env.ANSRV_GEO_PORT }}:50051 ${{ env.ANSRV_GEO_IMAGE_MINREQS }}
python -c "from ansys.geometry.core.connection.validate import validate; validate()"

- name: Run pytest
run: |
pytest -v
Expand Down Expand Up @@ -529,11 +530,6 @@ jobs:
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Pull and launch geometry service
run: |
docker pull ${{ env.ANSRV_GEO_IMAGE_MINREQS }}
docker run --detach --name ${{ env.GEO_CONT_NAME }} -e LICENSE_SERVER=${{ env.ANSRV_GEO_LICENSE_SERVER }} -p ${{ env.ANSRV_GEO_PORT }}:50051 ${{ env.ANSRV_GEO_IMAGE_MINREQS }}

- name: Checkout repository
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2

Expand All @@ -551,6 +547,12 @@ jobs:
# Installing docker (needed for the tests)
pip install docker

- name: Start Geometry service and verify start
run: |
docker pull ${{ env.ANSRV_GEO_IMAGE_MINREQS }}
docker run --detach --name ${{ env.GEO_CONT_NAME }} -e LICENSE_SERVER=${{ env.ANSRV_GEO_LICENSE_SERVER }} -p ${{ env.ANSRV_GEO_PORT }}:50051 ${{ env.ANSRV_GEO_IMAGE_MINREQS }}
python -c "from ansys.geometry.core.connection.validate import validate; validate()"

- name: Run pytest
run: |
pytest -v -c pytest-nographics.ini
Expand All @@ -562,7 +564,6 @@ jobs:
docker logs ${{ env.GEO_CONT_NAME }}
docker rm ${{ env.GEO_CONT_NAME }}


package:
name: Package library
needs: [testing-windows, testing-linux, testing-min-reqs, testing-no-graphics, docs]
Expand Down Expand Up @@ -691,17 +692,12 @@ jobs:
run:
echo "ANSRV_GEO_LICENSE_SERVER=${{ secrets.INTERNAL_LICENSE_SERVER }}" | Out-File -FilePath $env:GITHUB_ENV -Append

- name: Launch Geometry service
run: |
docker run --detach --name ${{ env.GEO_CONT_NAME }} -e LICENSE_SERVER=${{ env.ANSRV_GEO_LICENSE_SERVER }} -p ${{ env.ANSRV_GEO_PORT }}:50051 ghcr.io/ansys/geometry:windows-tmp

- name: Validate connection using PyAnsys Geometry
run: |
python -m venv .venv
.\.venv\Scripts\Activate.ps1
python -m pip install --upgrade pip
pip install -e .[tests]
python -c "from ansys.geometry.core.connection.validate import validate; validate()"

- name: Restore images cache
uses: actions/cache@5a3ec84eff668545956fd18022155c47e93e2684 # v4.2.3
Expand All @@ -710,6 +706,12 @@ jobs:
key: pyvista-image-cache-${{ runner.os }}-v-${{ env.RESET_IMAGE_CACHE }}-${{ hashFiles('pyproject.toml') }}
restore-keys: pyvista-image-cache-${{ runner.os }}-v-${{ env.RESET_IMAGE_CACHE }}

- name: Start Geometry service and verify start
run: |
.\.venv\Scripts\Activate.ps1
docker run --detach --name ${{ env.GEO_CONT_NAME }} -e LICENSE_SERVER=${{ env.ANSRV_GEO_LICENSE_SERVER }} -p ${{ env.ANSRV_GEO_PORT }}:50051 ghcr.io/ansys/geometry:windows-tmp
python -c "from ansys.geometry.core.connection.validate import validate; validate()"

- name: Testing
run: |
.\.venv\Scripts\Activate.ps1
Expand Down Expand Up @@ -778,14 +780,14 @@ jobs:
run: |
docker build -f linux/coreservice/Dockerfile -t ghcr.io/ansys/geometry:linux-tmp .

- name: Launch Geometry service
run: |
docker run --detach --name ${{ env.GEO_CONT_NAME }} -e LICENSE_SERVER=${{ env.ANSRV_GEO_LICENSE_SERVER }} -p ${{ env.ANSRV_GEO_PORT }}:50051 ghcr.io/ansys/geometry:linux-tmp

- name: Validate connection using PyAnsys Geometry
run: |
python -m pip install --upgrade pip
pip install -e .[tests]

- name: Start Geometry service and verify start
run: |
docker run --detach --name ${{ env.GEO_CONT_NAME }} -e LICENSE_SERVER=${{ env.ANSRV_GEO_LICENSE_SERVER }} -p ${{ env.ANSRV_GEO_PORT }}:50051 ghcr.io/ansys/geometry:linux-tmp
python -c "from ansys.geometry.core.connection.validate import validate; validate()"

- name: Restore images cache
Expand Down
1 change: 1 addition & 0 deletions doc/changelog.d/1904.dependencies.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
bump grpcio dependencies
17 changes: 7 additions & 10 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,15 @@ classifiers = [
]

dependencies = [
"ansys-api-geometry==0.4.56",
"ansys-api-geometry==0.4.57",
"ansys-tools-path>=0.3,<1",
"beartype>=0.11.0,<0.21",
"geomdl>=5,<6",
"grpcio>=1.35.0,<1.68",
"grpcio-health-checking>=1.45.0,<1.68",
"grpcio>=1.35.0,<2",
"matplotlib>=3,<4",
"numpy>=1.20.3,<3",
"Pint>=0.18,<1",
"protobuf>=3.20.2,<6",
"protobuf>=3.20.2,<7",
"requests>=2,<3",
"scipy>=1.7.3,<2",
"semver>=3,<4",
Expand Down Expand Up @@ -62,12 +61,11 @@ tests = [
"beartype==0.20.2",
"docker==7.1.0",
"geomdl==5.3.1",
"grpcio==1.67.1",
"grpcio-health-checking==1.67.1",
"grpcio==1.71.0",
"matplotlib==3.10.1",
"numpy==2.2.4",
"Pint==0.24.4",
"protobuf==5.29.3",
"protobuf==6.30.2",
"pygltflib==1.16.3",
"pytest==8.3.5",
"pytest-cov==6.1.1",
Expand All @@ -93,8 +91,7 @@ doc = [
"beartype==0.20.2",
"docker==7.1.0",
"geomdl==5.3.1",
"grpcio==1.67.1",
"grpcio-health-checking==1.67.1",
"grpcio==1.71.0",
"ipyvtklink==0.2.3",
"jupyter_sphinx==0.5.3",
"jupytext==1.16.7",
Expand All @@ -108,7 +105,7 @@ doc = [
"panel==1.6.1",
"pdf2image==1.17.0",
"Pint==0.24.4",
"protobuf==5.29.3",
"protobuf==6.30.2",
"pygltflib==1.16.3",
"pyvista[jupyter]==0.44.2",
"quarto-cli==1.6.42",
Expand Down
11 changes: 9 additions & 2 deletions src/ansys/geometry/core/_grpc/_services/_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,12 @@ class _GRPCServices:
version is used.
"""

def __init__(self, channel: grpc.Channel, version: GeometryApiProtos | str | None = None):
def __init__(
self,
channel: grpc.Channel,
version: GeometryApiProtos | str | None = None,
timeout: float = 5.0,
):
"""
Initialize the GRPCServices class.

Expand All @@ -61,9 +66,11 @@ def __init__(self, channel: grpc.Channel, version: GeometryApiProtos | str | Non
version : GeometryApiProtos | str | None
The version of the gRPC API protocol to use. If None, the latest
version is used.
timeout : float
The timeout in seconds for the health check. Default is 5 seconds.
"""
# Set the proto version to be used
self.version = set_proto_version(channel, version)
self.version = set_proto_version(channel, version, timeout)
self.channel = channel

# Lazy load all the services
Expand Down
5 changes: 5 additions & 0 deletions src/ansys/geometry/core/_grpc/_services/base/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,8 @@ def get_backend(self, **kwargs) -> dict:
def get_logs(self, **kwargs) -> dict:
"""Get server logs."""
pass # pragma: no cover

@abstractmethod
def wait_until_healthy(self, **kwargs) -> dict:
"""Wait until the server is healthy."""
pass
55 changes: 46 additions & 9 deletions src/ansys/geometry/core/_grpc/_services/v0/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@
# SOFTWARE.
"""Module containing the admin service implementation for v0."""

import warnings

import grpc
import semver

Expand Down Expand Up @@ -53,13 +51,7 @@ def __init__(self, channel: grpc.Channel): # noqa: D102

@protect_grpc
def get_backend(self, **kwargs) -> dict: # noqa: D102
# TODO: Remove this context and filter once the protobuf UserWarning is downgraded to INFO
# https://github.com/grpc/grpc/issues/37609
with warnings.catch_warnings():
warnings.filterwarnings(
"ignore", "Protobuf gencode version", UserWarning, "google.protobuf.runtime_version"
)
from google.protobuf.empty_pb2 import Empty
from google.protobuf.empty_pb2 import Empty

# Create the request - assumes all inputs are valid and of the proper type
request = Empty()
Expand Down Expand Up @@ -104,3 +96,48 @@ def get_logs(self, **kwargs) -> dict: # noqa: D102
logs[chunk.log_name] += chunk.log_chunk.decode()

return {"logs": logs}

@protect_grpc
def wait_until_healthy(self, **kwargs) -> dict: # noqa: D102
from concurrent.futures import ThreadPoolExecutor
import time

from ansys.api.dbu.v0.admin_pb2 import HealthResponse

def _get_health_status() -> HealthResponse:
"""Get the health status of the server."""
from google.protobuf.empty_pb2 import Empty

return self.stub.Health(Empty())

t_max = time.time() + kwargs["timeout"]
t_out = 0.1
while time.time() < t_max:
try:
result = None
# Use ThreadPoolExecutor to run the health check in a separate thread
with ThreadPoolExecutor() as executor:
future = executor.submit(_get_health_status)
try:
result = future.result(timeout=t_out) # seconds
except (TimeoutError, grpc.RpcError) as e:
# Timeout error, try again
raise TimeoutError(f"Timeout/connection error... {e}")
if result:
return {"healthy": True if result.message == "I am healthy!" else False}

except TimeoutError:
# Duplicate timeout and try again
t_now = time.time()
t_out *= 2
# If we have time to try again, continue.. but if we don't,
# just try for the remaining time
if t_now + t_out > t_max:
t_out = t_max - t_now
continue

# If we reach here, the server is not healthy
target_str = kwargs["target"]
raise TimeoutError(
f"Channel health check to target '{target_str}' timed out after {kwargs['timeout']} seconds." # noqa: E501
)
4 changes: 4 additions & 0 deletions src/ansys/geometry/core/_grpc/_services/v1/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,7 @@ def get_backend(self, **kwargs) -> dict: # noqa: D102
@protect_grpc
def get_logs(self, **kwargs) -> dict: # noqa: D102
raise NotImplementedError

@protect_grpc
def wait_until_healthy(self, **kwargs): # noqa: D102
raise NotImplementedError
37 changes: 22 additions & 15 deletions src/ansys/geometry/core/_grpc/_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,28 +23,31 @@

from enum import Enum, unique

from google.protobuf.empty_pb2 import Empty
import grpc

# ATTEMPT v0 IMPORT
try:
import ansys.api.dbu.v0.admin_pb2_grpc as dbu_v0_admin_pb2_grpc
import ansys.api.dbu.v0.admin_pb2_grpc # noqa: F401

from ._services.v0.admin import GRPCAdminServiceV0 as V0AdminService
except ImportError:
dbu_v0_admin_pb2_grpc = None
V0AdminService = None

# ATTEMPT v1 IMPORT
try:
import ansys.api.dbu.v1.admin_pb2_grpc as dbu_v1_admin_pb2_grpc
import ansys.api.dbu.v1.admin_pb2_grpc # noqa: F401

from ._services.v1.admin import GRPCAdminServiceV1 as V1AdminService
except ImportError:
dbu_v1_admin_pb2_grpc = None
V1AdminService = None


@unique
class GeometryApiProtos(Enum):
"""Enumeration of the supported versions of the gRPC API protocol."""

V0 = 0, dbu_v0_admin_pb2_grpc
V1 = 1, dbu_v1_admin_pb2_grpc
V0 = 0, V0AdminService
V1 = 1, V1AdminService

@staticmethod
def get_latest_version() -> "GeometryApiProtos":
Expand All @@ -68,7 +71,7 @@ def from_string(version_string: str) -> "GeometryApiProtos":
return version
raise ValueError(f"Invalid version string: {version_string}")

def verify_supported(self, channel: grpc.Channel) -> bool:
def verify_supported(self, channel: grpc.Channel, timeout: float) -> bool:
"""Check if the version is supported.

Notes
Expand All @@ -85,20 +88,22 @@ def verify_supported(self, channel: grpc.Channel) -> bool:
bool
True if the server supports the version, otherwise False.
"""
pb2_grpc = self.value[1]
if pb2_grpc is None:
from ._services.base.admin import GRPCAdminService

AdminService: type[GRPCAdminService] | None = self.value[1] # noqa: N806
if AdminService is None:
return False

try:
admin_stub = pb2_grpc.AdminStub(channel)
admin_stub.Health(Empty())
admin_service = AdminService(channel)
admin_service.wait_until_healthy(timeout=timeout, target=channel._target)
return True
except grpc.RpcError:
return False


def set_proto_version(
channel: grpc.Channel, version: GeometryApiProtos | str | None = None
channel: grpc.Channel, version: GeometryApiProtos | str | None = None, timeout: float = 5.0
) -> "GeometryApiProtos":
"""Set the version of the gRPC API protocol used by the server.

Expand All @@ -109,6 +114,8 @@ def set_proto_version(
version : GeometryApiProtos | str | None
The version of the gRPC API protocol to use. If None, the latest
version is used.
timeout : float
The timeout in seconds for the health check. Default is 5 seconds.

Returns
-------
Expand All @@ -120,14 +127,14 @@ def set_proto_version(
version = GeometryApiProtos.from_string(version)

# Check the server supports the requested version (if specified)
if version and not version.verify_supported(channel):
if version and not version.verify_supported(channel, timeout):
raise ValueError(f"Server does not support the requested version: {version.name}")

# If no version specified... Attempt to use all of them, starting
# with the latest version
if version is None:
version = GeometryApiProtos.get_latest_version()
while not version.verify_supported(channel):
while not version.verify_supported(channel, timeout):
version = GeometryApiProtos.from_int_value(version.value[0] - 1)

# Return the version
Expand Down
Loading
Loading