Skip to content

Conversation

@neilalberg
Copy link

Description

Update Cloud Run sample service with readiness probes to support GRPC

Checklist

  • ran this command from run/testing directory: GOLANG_SAMPLES_E2E_TEST=true GOLANG_SAMPLES_PROJECT_ID=lihenan-s8s-networking-test go test -run ^TestServiceHealthGrpc$ -v .
  • Code formatted: gofmt (see Formatting)
  • Vetting pass: go vet (see Formatting)
  • These samples need a new API enabled in testing projects to pass (let us know which ones)
  • These samples need a new/updated env vars in testing projects set to pass (let us know which ones)
  • This sample adds a new sample directory, and I updated the CODEOWNERS file with the codeowners for this sample
  • This sample adds a new Product API, and I updated the Blunderbuss issue/PR auto-assigner with the codeowners for this sample
  • Please merge this PR for me once it is approved

@neilalberg neilalberg requested review from a team as code owners October 28, 2025 23:27
@product-auto-label product-auto-label bot added the samples Issues that are directly related to samples. label Oct 28, 2025
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @neilalberg, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly enhances the Cloud Run readiness probe sample by integrating gRPC health check capabilities. The changes allow the sample service to demonstrate how to expose and respond to gRPC readiness probes, providing a more robust and versatile example for developers deploying applications with gRPC services on Cloud Run. This ensures the sample remains relevant for modern microservice architectures that often leverage gRPC for inter-service communication and health monitoring.

Highlights

  • gRPC Readiness Probe Support: The Cloud Run sample service for readiness probes has been updated to include support for gRPC-based health checks, allowing services to expose their readiness status via a gRPC endpoint.
  • Dependency Update: The go.mod file was updated to explicitly include the google.golang.org/grpc package as a direct dependency.
  • Configuration Model Enhancement: The ReadinessProbeConfig struct in main.go was extended to include a new GrpcAction field, enabling the configuration of gRPC readiness probes alongside existing HTTP probes. Existing HTTP probe fields were made optional using pointers.
  • gRPC Health Server Implementation: A new gRPC server is now started in the sample application, listening on port 8081, and implements the standard gRPC Health Checking Protocol to report the service's readiness status.
  • HTML Template Updates: The layout.html template was modified to conditionally display gRPC readiness probe configuration details if they are present, ensuring the UI reflects the new probe type.
  • New End-to-End Test: A dedicated end-to-end test, TestServiceHealthGrpc, was added to verify the correct functionality and deployment of the service with a gRPC readiness probe configured.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request adds support for gRPC readiness probes to the Cloud Run sample service. The changes include updating the service to start a gRPC health server, modifying the data structures to handle gRPC probe configurations, and adding a new end-to-end test for the gRPC probe functionality.

The implementation is solid, but I have a few suggestions to improve code clarity, maintainability, and fix a minor UI issue. My feedback includes refactoring duplicated test code, removing an unused method, and improving the gRPC server implementation by leveraging UnimplementedHealthServer for forward compatibility.

Comment on lines +90 to +148
func TestServiceHealthGrpc(t *testing.T) {
tc := testutil.EndToEndTest(t)

service := cloudrunci.NewService("service-health", tc.ProjectID)
service.Readiness = &cloudrunci.ReadinessProbe{
TimeoutSeconds: 1,
PeriodSeconds: 1,
SuccessThreshold: 1,
FailureThreshold: 1,
GRPC: &cloudrunci.GRPCProbe{
Port: 8081,
},
}
service.Dir = "../service-health"
service.AsBuildpack = true
service.Platform.CommandFlags()

if err := service.Deploy(); err != nil {
t.Fatalf("service.Deploy %q: %v", service.Name, err)
}
defer func(service *cloudrunci.Service) {
err := service.Clean()
if err != nil {
t.Fatalf("service.Clean %q: %v", service.Name, err)
}
}(service)

resp, err := service.Request("GET", "/are_you_ready")
if err != nil {
t.Fatalf("request: %v", err)
}

out, err := io.ReadAll(resp.Body)
if err != nil {
t.Fatalf("io.ReadAll: %v", err)
}

if got, want := string(out), "HEALTHY"; got != want {
t.Errorf("body: got %q, want %q", got, want)
}

if got := resp.StatusCode; got != http.StatusOK {
t.Errorf("response status: got %d, want %d", got, http.StatusOK)
}

ctx := context.Background()
c, err := storage.NewClient(ctx)
if err != nil {
t.Fatalf("storage.NewClient: %v", err)
}
defer c.Close()
bucketName := os.Getenv("GOLANG_SAMPLES_PROJECT_ID") + "-" + service.Version()
t.Logf("Deleting bucket: %s", bucketName)

err = testutil.DeleteBucketIfExists(ctx, c, bucketName)
if err != nil {
t.Fatalf("testutil.DeleteBucketIfExists: %v", err)
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

There is significant code duplication between TestServiceHealthHttp and this new TestServiceHealthGrpc test. Consider refactoring them into a single table-driven test to improve maintainability and reduce boilerplate.

You could define a slice of test cases, with each case specifying the readiness probe configuration, and then loop through them in a single test function using t.Run for each subtest.

Example structure:

func TestServiceHealth(t *testing.T) {
	tc := testutil.EndToEndTest(t)

	tests := []struct {
		name    string
		probe   *cloudrunci.ReadinessProbe
	}{
		{
			name: "HTTP",
			probe: &cloudrunci.ReadinessProbe{
				// ... HTTP probe config
			},
		},
		{
			name: "gRPC",
			probe: &cloudrunci.ReadinessProbe{
				// ... gRPC probe config
			},
		},
	}

	for _, test := range tests {
		t.Run(test.name, func(t *testing.T) {
			t.Parallel()
			// ... shared test logic using test.probe
		})
	}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

samples Issues that are directly related to samples.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant