feat: add Pub/Sub readiness health check#262
Open
shimib wants to merge 1 commit into
Open
Conversation
/readyz only runs a backend check when the active Flow implements pipeline.HealthChecker. Only the Redis flows did, so for gcp-pubsub / gcp-pubsub-gated the type assertion in cmd/main.go failed, the checker stayed nil, and /readyz reflected only the in-process ready flag — a pod with an unreachable Pub/Sub backend still reported ready (llm-d-incubation#246). Implement HealthCheck on PubSubMQFlow. It probes each configured request subscription via SubscriptionAdminClient.GetSubscription, reusing Subscriber().String() for resource-name normalization. A PermissionDenied response is treated as healthy because it still proves the broker is reachable: the consume-only role (roles/pubsub.subscriber) lacks pubsub.subscriptions.get, so a correctly-configured consumer can confirm connectivity without introspecting the subscription. Genuine failures (Unavailable, NotFound, etc.) mark the pod not-ready. The cmd/main.go wiring picks up the HealthChecker automatically. A client field is stored on the flow so the new path is injectable in tests. Add pstest-based unit tests covering healthy, missing-subscription, and broker-unreachable (the llm-d-incubation#246 regression guard) cases. Fixes llm-d-incubation#246 Signed-off-by: Shimi Bandiel <shimib@google.com>
jtechapps
reviewed
Jun 22, 2026
| // its result as the fully-qualified name for the admin lookup. | ||
| name := r.client.Subscriber(cd.subscriberID).String() | ||
| _, err := r.client.SubscriptionAdminClient.GetSubscription(ctx, | ||
| &pubsubpb.GetSubscriptionRequest{Subscription: name}) |
Contributor
There was a problem hiding this comment.
Why not use .Exists()?
I don't think Exists() requires additional IAM permissions.
You can use sub.Exists() in the requestWorker() loop to cache the current state of the subscription to a shared data structure and then read that data structure in HealthCheck().
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Fixes #246.
/readyzonly runs a backend health check when the activeFlowimplements the optionalpipeline.HealthCheckerinterface (cmd/main.go). Only the Redis flows did (rdb.Ping), so forgcp-pubsub/gcp-pubsub-gatedthe type assertion failed,checkerstayednil, and/readyzreflected only the in-processreadyflag — a pod with an unreachable Pub/Sub backend still reportedready.This PR makes
PubSubMQFlowimplementpipeline.HealthCheckerso/readyzverifies real broker/subscription connectivity. Thecmd/main.gowiring picks it up automatically.How it works
HealthCheckprobes each configured request subscription viaSubscriptionAdminClient.GetSubscription, reusingSubscriber().String()for resource-name normalization (handles both short IDs and full resource paths).IAM consideration
GetSubscriptionrequirespubsub.subscriptions.get, which is not included inroles/pubsub.subscriber(the consume-only role). To avoid falsely marking correctly-configured consumer pods as not-ready, aPermissionDeniedresponse is treated as healthy — it still proves the broker round-tripped (reachable). Genuine connectivity/config failures (Unavailable,DeadlineExceeded,NotFound, connection errors) mark the pod not-ready, which still fixes the original bug.Tests
Introduces the
pstestin-memory fake (first use in the repo) covering:nilNotFound)Notes for reviewers
GetTopiccheck onresultTopicIDif preferred.Start()still uses the package-globalpubSubClient; only the newHealthCheckuses the structclientfield (kept minimal). Can migrateStartfor consistency if desired.go.mod:google.golang.org/grpcpromoted to a direct dependency (now imported in tests); pstest transitive deps added viago mod tidy.Verification
go build ./...make testgolangci-lint run ./pkg/pubsub/...(0 issues)