Skip to content
Merged
Show file tree
Hide file tree
Changes from 68 commits
Commits
Show all changes
82 commits
Select commit Hold shift + click to select a range
ad3d5ca
cloudrun server test
sourabhsinghs Nov 25, 2024
45f84dc
Merge branch 'main' into feature/cloudrun/server-test
sourabhsinghs Jan 28, 2025
6859957
cloudrun server test
sourabhsinghs Nov 25, 2024
39c5cbe
check patch
eshitachandwani Feb 11, 2025
87317ec
correct logging import and remove clourun server flag
eshitachandwani Feb 11, 2025
a9f88b0
client test not working
eshitachandwani Feb 17, 2025
0142857
changes
eshitachandwani Feb 21, 2025
579f782
running tests
eshitachandwani Feb 26, 2025
64cd9f1
run black and isort
eshitachandwani Feb 26, 2025
1a1c974
pylint error
eshitachandwani Feb 26, 2025
6d5e0de
pylint error
eshitachandwani Feb 26, 2025
bc64577
remove unwanted files
eshitachandwani Feb 27, 2025
b9be8ca
address comments
eshitachandwani Feb 28, 2025
521bf5e
pylint
eshitachandwani Feb 28, 2025
8455a1e
address comments
eshitachandwani Mar 6, 2025
d04238e
pylint
eshitachandwani Mar 6, 2025
10e9589
black
eshitachandwani Mar 6, 2025
91ddacc
working cloudrun_server test
eshitachandwani Mar 10, 2025
bc72f63
formatting
eshitachandwani Mar 10, 2025
a70ea9b
pylint
eshitachandwani Mar 10, 2025
2685397
pylint
eshitachandwani Mar 10, 2025
75184b9
address comments
eshitachandwani Mar 11, 2025
0b235ee
black
eshitachandwani Mar 11, 2025
486c554
add cloudrunlogs
eshitachandwani Mar 12, 2025
47447cf
flag file
eshitachandwani Mar 19, 2025
ab09f9c
test suit
eshitachandwani Mar 19, 2025
9af09ec
pull from main
eshitachandwani Mar 26, 2025
2c270c2
create_resource
eshitachandwani Mar 27, 2025
65f29bf
address comments
eshitachandwani Mar 27, 2025
54e9052
black
eshitachandwani Mar 27, 2025
b2de1cd
test
eshitachandwani Mar 28, 2025
3bd8806
add flag
eshitachandwani Apr 1, 2025
4cd2532
secure mode remove
eshitachandwani Apr 1, 2025
9062441
secure channel
eshitachandwani Apr 1, 2025
69184c1
region change for kokoro
eshitachandwani Apr 1, 2025
56fb5c0
no vpc for kokoro
eshitachandwani Apr 2, 2025
6e33d57
comments
eshitachandwani Apr 2, 2025
0ee079b
format
eshitachandwani Apr 2, 2025
9f26af5
pylint
eshitachandwani Apr 2, 2025
ce1e662
pylint
eshitachandwani Apr 2, 2025
83802a4
pylint
eshitachandwani Apr 2, 2025
1f9c4f3
merge and running tests
eshitachandwani Apr 24, 2025
2962dca
merge and running tests
eshitachandwani Apr 24, 2025
148e100
black
eshitachandwani Apr 24, 2025
7f66c2f
black
eshitachandwani Apr 24, 2025
5e203e9
minors
eshitachandwani Apr 24, 2025
025630f
minor
eshitachandwani Apr 24, 2025
3bf7296
Merge branch 'main' into eshita_cr_cr
eshitachandwani Apr 24, 2025
f5de981
minor
eshitachandwani Apr 24, 2025
43a00d8
minor
eshitachandwani Apr 24, 2025
9bc7575
Merge branch 'eshita_cr_cr' of https://github.com/eshitachandwani/psm…
eshitachandwani Apr 24, 2025
71a6052
Merge branch 'main' into eshita_cr_cr
eshitachandwani Apr 24, 2025
7df6058
comments
eshitachandwani Apr 24, 2025
0d754b1
Merge branch 'eshita_cr_cr' of https://github.com/eshitachandwani/psm…
eshitachandwani Apr 24, 2025
68cd017
comments
eshitachandwani Apr 25, 2025
07abd39
comment
eshitachandwani Apr 25, 2025
140a74e
address comments
eshitachandwani Apr 25, 2025
d0f08db
secure_mode
eshitachandwani Apr 25, 2025
d3c7461
format
eshitachandwani Apr 25, 2025
459d9e3
Merge branch 'main' into eshita_cr_cr
eshitachandwani Apr 25, 2025
30307b6
cleanup
eshitachandwani Apr 25, 2025
84526b4
Merge branch 'eshita_cr_cr' of https://github.com/eshitachandwani/psm…
eshitachandwani Apr 25, 2025
e45e55d
fix test
eshitachandwani Apr 29, 2025
366c8ef
change name
eshitachandwani Apr 29, 2025
bcfa2f8
client run
eshitachandwani Apr 29, 2025
532b519
black
eshitachandwani Apr 29, 2025
3ecea0b
black
eshitachandwani Apr 29, 2025
196bab9
test run
eshitachandwani Apr 29, 2025
35b302f
client script
eshitachandwani Apr 29, 2025
42e0620
final changes
eshitachandwani Apr 30, 2025
54d588f
changes
eshitachandwani May 5, 2025
61cb473
Merge branch 'main' into eshita_cr_cr
eshitachandwani May 6, 2025
c4576cb
change policy
eshitachandwani May 6, 2025
3f14141
Merge branch 'eshita_cr_cr' of https://github.com/eshitachandwani/psm…
eshitachandwani May 6, 2025
8939071
policy
eshitachandwani May 6, 2025
a32ba27
policy
eshitachandwani May 6, 2025
aa7e4b1
Refactor secure channel creation, add call creds logging
sergiitk May 6, 2025
677ec69
temporary change: extend the retry timeout for live kokoro debugging
sergiitk May 7, 2025
c731f68
Call creds should work now
sergiitk May 7, 2025
5e1b6ad
oops forgot to refresh the creds
sergiitk May 7, 2025
13a1624
missed target audience format
sergiitk May 7, 2025
553182a
add region to delete resource
eshitachandwani May 7, 2025
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
1 change: 1 addition & 0 deletions .kokoro/psm_interop_kokoro_lib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ psm::cloud_run::setup() {
psm::cloud_run::get_tests() {
TESTS=(
"cloud_run_csm_inbound_test"
"cloud_run_csm_outbound_test"
Comment thread
sergiitk marked this conversation as resolved.
)
Comment thread
kannanjgithub marked this conversation as resolved.
}

Expand Down
17 changes: 17 additions & 0 deletions bin/lib/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
from framework.infrastructure.gcp import cloud_run
from framework.test_app import client_app
from framework.test_app import server_app
from framework.test_app.runners.cloud_run import cloud_run_xds_client_runner
from framework.test_app.runners.cloud_run import cloud_run_xds_server_runner
from framework.test_app.runners.k8s import gamma_server_runner
from framework.test_app.runners.k8s import k8s_xds_client_runner
Expand All @@ -48,6 +49,7 @@
KubernetesServerRunner = k8s_xds_server_runner.KubernetesServerRunner
GammaServerRunner = gamma_server_runner.GammaServerRunner
CloudRunServerRunner = cloud_run_xds_server_runner.CloudRunServerRunner
CloudRunClientRunner = cloud_run_xds_client_runner.CloudRunClientRunner
_XdsTestServer = server_app.XdsTestServer
_XdsTestClient = client_app.XdsTestClient

Expand Down Expand Up @@ -177,6 +179,21 @@ def make_cloud_run_server_runner() -> CloudRunServerRunner:
server_runner = CloudRunServerRunner
return server_runner(**runner_kwargs)

def make_cloud_run_client_runner(mesh_name: str, server_target: str) -> CloudRunClientRunner:
# CloudRunClientRunner arguments.
runner_kwargs = dict(
project=xds_flags.PROJECT.value,
service_name=xds_flags.SERVER_NAME.value,
image_name=xds_k8s_flags.SERVER_IMAGE.value,
Comment thread
XuanWang-Amos marked this conversation as resolved.
Outdated
Comment thread
eshitachandwani marked this conversation as resolved.
Outdated
network=xds_flags.NETWORK.value,
region=xds_flags.CLOUD_RUN_REGION.value,
gcp_api_manager=gcp.api.GcpApiManager(),
mesh_name=mesh_name,
server_target=server_target,
)
client_runner = CloudRunClientRunner
return client_runner(**runner_kwargs)

def _ensure_atexit(signum, frame):
"""Needed to handle signals or atexit handler won't be called."""
del frame
Expand Down
72 changes: 72 additions & 0 deletions bin/run_test_client_cloud_run.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# Copyright 2025 gRPC authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""
Run test xds client.

Typical usage examples:

# Help.
./run.sh ./bin/run_test_client_cloud_run.py --help

"""
import logging

from absl import app
from absl import flags

from bin.lib import common
from framework import xds_flags
from framework import xds_k8s_flags
from framework.infrastructure.mesh_resource_manager import (
cloud_run_mesh_manager,
)

logger = logging.getLogger(__name__)

flags.adopt_module_key_flags(xds_flags)
flags.adopt_module_key_flags(xds_k8s_flags)
flags.adopt_module_key_flags(common)


def main(argv):
if len(argv) > 1:
raise app.UsageError("Too many command-line arguments.")

xds_flags.set_socket_default_timeout_from_flag()

run_kwargs = dict()
td = cloud_run_mesh_manager.CloudRunMeshManager(
**common.td_attrs(), region=xds_flags.CLOUD_RUN_REGION.value
)

# Default server target pattern.
server_target = f"xds:///{xds_flags.SERVER_XDS_HOST.value}"
if xds_flags.SERVER_XDS_PORT.value != 80:
server_target = f"{server_target}:{xds_flags.SERVER_XDS_PORT.value}"

run_kwargs["server_target"] = server_target

mesh = td.create_mesh()
run_kwargs[
"config_mesh"
] = f"projects/{td.project}/locations/global/meshes/{mesh.name}"
logger.info("Config Mesh: %s", mesh.name)
client_runner = common.make_cloud_run_client_runner(
run_kwargs["config_mesh"], server_target
)
client_runner.run(**run_kwargs)


if __name__ == "__main__":
app.run(main)
2 changes: 1 addition & 1 deletion config/common-cloudrun.cfg
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# Common config file for Cloudrun PSM tests.
--cloud_run_region=us-central1
--cloud_run_region=us-east7
23 changes: 23 additions & 0 deletions framework/infrastructure/gcp/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -581,6 +581,29 @@ def _delete_resource(
logger.warning("Failed to delete %s, %r", full_name, error)
return False

def _set_iam_policy(
Comment thread
eshitachandwani marked this conversation as resolved.
Outdated
self,
collection: discovery.Resource,
body: dict,
full_name: str,
**kwargs,
):
logger.info(
"Setting IAM policy for %s resource:\n%s",
Comment thread
sergiitk marked this conversation as resolved.
Outdated
self.api_name,
self.resource_pretty_format(body),
)
try:
collection.setIamPolicy(
resource=full_name, body=body, **kwargs
).execute()
return True
except _HttpError as error:
logger.warning(
"Failed to set IAM policy for %s, %r", full_name, error
)
raise

# TODO(sergiitk): Use ResponseError and TransportError
def _execute( # pylint: disable=arguments-differ
self,
Expand Down
9 changes: 9 additions & 0 deletions framework/infrastructure/gcp/cloud_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,12 @@ def delete_service(self, service_name: str):
service_name, self.SERVICES, self.region
),
)

def setIamPolicy(self, service_name: str, policy_body: dict):
Comment thread
eshitachandwani marked this conversation as resolved.
Outdated
self._set_iam_policy(
collection=self._services_collection,
full_name=self.resource_full_name(
service_name, self.SERVICES, self.region
),
body=policy_body,
)
9 changes: 7 additions & 2 deletions framework/rpc/grpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,15 @@ def __init__(self, rpc_host):
# Cache gRPC channels per port
self.channels = dict()

def _make_channel(self, port) -> grpc.Channel:
def _make_channel(self, port, secure_mode=False) -> grpc.Channel:
Comment thread
sergiitk marked this conversation as resolved.
Outdated
if port not in self.channels:
target = f"{self.rpc_host}:{port}"
self.channels[port] = grpc.insecure_channel(target)
if secure_mode:
self.channels[port] = grpc.secure_channel(
target, grpc.ssl_channel_credentials()
)
else:
self.channels[port] = grpc.insecure_channel(target)
return self.channels[port]

def close(self):
Expand Down
43 changes: 38 additions & 5 deletions framework/test_app/client_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
DEFAULT_TD_XDS_URI = "trafficdirector.googleapis.com:443"


# pylint: disable=too-many-public-methods
class XdsTestClient(framework.rpc.grpc.GrpcApp):
"""
Represents RPC services implemented in Client component of the xds test app.
Expand Down Expand Up @@ -85,6 +86,18 @@ def load_balancer_stats(self) -> _LoadBalancerStatsServiceClient:
log_target=f"{self.hostname}:{self.rpc_port}",
)

# For fetching stats from gRPC client containers requiring secure
# communication, like Cloud run where, a proxy is involved. The proxy uses
# HTTP/1.1 for plaintext connections. However, since gRPC requires HTTP/2,
# we must use encrypted communication (HTTPS) to ensure compatibility.
@property
@functools.lru_cache(None)
def secure_load_balancer_stats(self) -> _LoadBalancerStatsServiceClient:
return _LoadBalancerStatsServiceClient(
self._make_channel(self.rpc_port, secure_mode=True),
log_target=f"{self.hostname}:{self.rpc_port}",
)

@property
@functools.lru_cache(None)
def update_config(self):
Expand All @@ -109,6 +122,18 @@ def csds(self) -> _CsdsClient:
log_target=f"{self.hostname}:{self.maintenance_port}",
)

# For fetching stats from gRPC client containers requiring secure
# communication, like Cloud run where, a proxy is involved. The proxy uses
# HTTP/1.1 for plaintext connections. However, since gRPC requires HTTP/2,
# we must use encrypted communication (HTTPS) to ensure compatibility.
@property
@functools.lru_cache(None)
def secure_csds(self) -> _CsdsClient:
Comment thread
eshitachandwani marked this conversation as resolved.
return _CsdsClient(
self._make_channel(self.maintenance_port, secure_mode=True),
log_target=f"{self.hostname}:{self.maintenance_port}",
)

def get_csds_parsed(self, **kwargs) -> Optional[grpc_csds.DumpedXdsConfig]:
return self.csds.fetch_client_status_parsed(**kwargs)

Expand All @@ -118,15 +143,23 @@ def get_load_balancer_stats(
num_rpcs: int,
metadata_keys: Optional[tuple[str, ...]] = None,
timeout_sec: Optional[int] = None,
secure_mode: bool = False,
) -> grpc_testing.LoadBalancerStatsResponse:
"""
Shortcut to LoadBalancerStatsServiceClient.get_client_stats()
"""
return self.load_balancer_stats.get_client_stats(
num_rpcs=num_rpcs,
timeout_sec=timeout_sec,
metadata_keys=metadata_keys,
)
if secure_mode:
return self.secure_load_balancer_stats.get_client_stats(
num_rpcs=num_rpcs,
timeout_sec=timeout_sec,
metadata_keys=metadata_keys,
)
else:
return self.load_balancer_stats.get_client_stats(
num_rpcs=num_rpcs,
timeout_sec=timeout_sec,
metadata_keys=metadata_keys,
)

def get_load_balancer_accumulated_stats(
self,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ def _initalize_cloud_run_api_manager(self):
api_manager=self.gcp_api_manager,
)

def run(self, **kwargs):
def run(self, **kwargs) -> None:
if self.time_start_requested and not self.time_stopped:
if self.time_start_completed:
raise RuntimeError(
Expand Down
Loading