Skip to content
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

cloudrun server test #150

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

sourabhsinghs
Copy link

No description provided.

@sourabhsinghs sourabhsinghs requested a review from a team as a code owner January 28, 2025 16:24
Copy link
Member

@sergiitk sergiitk left a comment

Choose a reason for hiding this comment

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

A quick review, please address. Then I'll follow up with a more thorough review.

from typing import Optional

import framework
from framework.infrastructure import c6n
Copy link
Member

Choose a reason for hiding this comment

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

Is c6n this a common abbreviation? If no, we should call it cloud_run.

@@ -0,0 +1,66 @@
# Copyright 2020 gRPC authors.
Copy link
Member

Choose a reason for hiding this comment

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

please bump copyrights of the new files to 2025

Comment on lines +213 to +214
# "balancingMode": "CONNECTION",
# "maxRatePerEndpoint": max_rate_per_endpoint,
Copy link
Member

Choose a reason for hiding this comment

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

please parametrize this, so it doesn't affect current tests

@@ -158,7 +158,7 @@ def create_backend_service_traffic_director(
body = {
"name": name,
"loadBalancingScheme": "INTERNAL_SELF_MANAGED", # Traffic Director
"healthChecks": [health_check.url],
# "healthChecks": [health_check.url],
Copy link
Member

Choose a reason for hiding this comment

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

please parametrize this, so it doesn't affect current tests

print(neg)
return neg

except Exception as e:
Copy link
Member

@sergiitk sergiitk Jan 28, 2025

Choose a reason for hiding this comment

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

Too broad for a create_* function.

.execute()
)
neg = self.get_serverless_network_endpoint_group(name, region)
print(neg)
Copy link
Member

Choose a reason for hiding this comment

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

use logger

- name: grpc-td-conf
emptyDir:
medium: Memory
...
Copy link
Member

Choose a reason for hiding this comment

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

add nl at EOF

@@ -36,7 +36,7 @@ spec:
## driver waiting for the container to start.
failureThreshold: 1000
args:
- "--server=${server_target}"
- "--server=psm-grpc-server:8080"
Copy link
Member

Choose a reason for hiding this comment

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

this will break existing tests

GCR_TESTING: Final[
str
] = "us-docker.pkg.dev/grpc-testing/trafficdirector/td-grpc-bootstrap"
GCR_TESTING: Final[str] = (
Copy link
Member

Choose a reason for hiding this comment

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

You're probably using more a more recent version of black. Please reinstall packages with pip install -r requirements-dev.txt, and revert unrelated code changes

Copy link
Member

@sergiitk sergiitk left a comment

Choose a reason for hiding this comment

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

Added more comments.

@@ -1282,3 +1285,125 @@ def _get_certificate_provider(cls):
"pluginInstance": cls.CERTIFICATE_PROVIDER_INSTANCE,
},
}


class TrafficDirectorCloudRunManager(TrafficDirectorAppNetManager):
Copy link
Member

Choose a reason for hiding this comment

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

Please move to a separate file, similar to traffic_director_gamma.py

spec:
containers:
- name: psm-grpc-client
image: docker.io/grpc/xds-example-cpp-client:v1.69.x
Copy link
Member

Choose a reason for hiding this comment

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

Seem like you removed most variables from the template (image, bootstrap image, deployment name, etc). Is this template supposed to be temporary? I'd highly prefer if we parametrized regular client.deployment.yaml instead,

Comment on lines +26 to +27
class BaselineTest(xds_k8s_testcase.CloudRunXdsKubernetesTestCase):
def test_traffic_director_grpc_setup(self):
Copy link
Member

Choose a reason for hiding this comment

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

Please choose appropriate names for the test class and test case

@@ -199,6 +199,12 @@
help="Enable support for Dual Stack resources to the framework.",
)

REGION = flags.DEFINE_string(
"region",
default="us-central1",
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
default="us-central1",
default=None,

@@ -33,6 +33,18 @@
help="Traffic Director gRPC Bootstrap Docker image",
)

CLOUDRUN_SERVER_IMAGE = flags.DEFINE_string(
Copy link
Member

Choose a reason for hiding this comment

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

Why do we need separate images? I thought we'll be using our regular test server / test client.


def create_grpc_route(self, src_host: str, src_port: int):
hostname = src_host
route_name = f"{self.resource_prefix}-grpc-route-{self.resource_suffix}"
Copy link
Member

Choose a reason for hiding this comment

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

is this different from TrafficDirectorAppNetManager.create_grpc_route? If so, please add a note explaining how


https://cloud.google.com/kubernetes-engine/docs/how-to/workload-identity
"""
return (
Copy link
Member

Choose a reason for hiding this comment

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

this looks the same as KubernetesBaseRunner._get_workload_identity_member_name

Choose a reason for hiding this comment

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

We don't run the cloud run service as a workload in the CSM tests (and I don't see this method called from anywhere). Only for SPIFFE tests the calling cloud run service will join the workload identity pool.

Copy link
Member

Choose a reason for hiding this comment

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

Makes sense. Looks like there are other methods in this class that are copy-pasted from KubernetesBaseRunner, but never called

Copy link
Member

Choose a reason for hiding this comment

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

please move to gcp/

logger = logging.getLogger(__name__)


class CloudRunApiManager:
Copy link
Member

Choose a reason for hiding this comment

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

consider extending GcpStandardCloudApiResource


try:
operation = self._client.create_service(request=request)
self._service = operation.result(timeout=300)
Copy link
Member

Choose a reason for hiding this comment

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

Note that operation is not guaranteed to succeed on the first try. Instead, use GcpProjectApiResource.wait_for_operation

# See the License for the specific language governing permissions and
# limitations under the License.
"""
Run xDS Test Client on Kubernetes.

Choose a reason for hiding this comment

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

Fix the comment.

self.run_history = collections.deque()

# Persistent across many runs.
self.run_history = collections.deque()

Choose a reason for hiding this comment

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

Repeated twice.

self.service_name, self.image_name
)

def _start_completed(self):

Choose a reason for hiding this comment

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

This method is not called from anywhere.

Copy link
Member

Choose a reason for hiding this comment

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

Good catch. @sourabhsinghs - this should be called from CloudRunServerRunner, once you finished the deployment.

Copy link
Member

Choose a reason for hiding this comment

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

Note that you also want to call _stop from at the end of cleanup

)

self._reset_state()
self.time_start_requested = dt.datetime.now(tz=dt.timezone.utc)
Copy link
Member

Choose a reason for hiding this comment

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

Why did you add tz=dt.timezone.utc everywhere when copying from KubernetesBaseRunner? We intentionally assume local timezone elsewhere. We even log it at the beginning

logger.info("Logs timezone: %s", time.localtime().tm_zone)

"""Deploys and manages the xDS Test Server on Cloud Run."""
logger.info(self.service_name)
logger.info(self.image_name)
deployed_service_url = self.cloudrun_api_manager.deploy_service(
Copy link

@kannanjgithub kannanjgithub Jan 30, 2025

Choose a reason for hiding this comment

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

Did you intend to use the baseclass' run method which also has the cloudrun_api_manager.deploy_service call?

ports=[
run_v2.ContainerPort(
name="http1",
container_port=50051,

Choose a reason for hiding this comment

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

I think this should be getting the value from self.server_xds_port?

return self._start_test_client(test_server.xds_uri, **kwargs)

def backend_service_add_serverless_neg_backends(self):
logger.info("Creating serverless NEG")

Choose a reason for hiding this comment

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

The cloud run service name needs to be added to the NEG

gcloud compute network-endpoint-groups create destination-neg --region=us-central1 --network-endpoint-type=serverless --cloud-run-service=$DEST_SERVICE

] = GcpResourceManager().affinity_backend_service()
path_matcher["defaultService"] = (
GcpResourceManager().affinity_backend_service()
)
return host_rule, path_matcher

Choose a reason for hiding this comment

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

nit: Only whitespace diffs in this file, revert.

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.

3 participants