Repository navigation
feat(composer): use cloud monitoring metrics for historical GKE cluster discovery in composer - #879
Merged
Conversation
…er discovery in composer Replace live ListClusters API calls in ComposerEnvironmentClusterFinder with Cloud Monitoring metric queries to discover both current and deleted/past GKE clusters for Cloud Composer environments. - Update ComposerEnvironmentClusterFinder interface method to GetGKEClusterNames supporting time range and location parameters. - Query kubernetes.io/container/uptime metrics on k8s_container to extract cluster names matching <location>-<environment>-<hash>-gke naming pattern. - Update AutocompleteComposerClusterNamesTask to include start/end time dependencies, return empty location hint, and return all matching past/present GKE cluster identities. - Remove unused ContainerClusterManagerClient and associated cache fields from ClientFactory.
Contributor
There was a problem hiding this comment.
Code Review
This pull request refactors the Cloud Composer GKE cluster finding logic to query cluster names from monitoring metrics instead of listing GKE clusters directly, allowing it to return multiple matching clusters. It also updates the autocomplete task to incorporate start and end times. The review feedback highlights a bug in filterAndMatchComposerGKEClusterNames when the location parameter is empty, suggests adding a corresponding test case, and recommends replacing time.Now() with a fixed time in tests to prevent non-determinism.
…er discovery in composer Replace live ListClusters API calls in ComposerEnvironmentClusterFinder with Cloud Monitoring metric queries to discover both current and deleted/past GKE clusters for Cloud Composer environments. - Update ComposerEnvironmentClusterFinder interface method to GetGKEClusterNames supporting time range and location parameters. - Query kubernetes.io/container/uptime metrics on k8s_container to extract cluster names matching <location>-<candidate>-<hash>-gke pattern. - Extract extractEnvironmentPrefixCandidate helper function using strings.LastIndex to extract candidate environment name prefixes from GKE cluster names. - Return ErrEnvironmentClusterNotFound when no cluster candidates are found in GetGKEClusterNames. - Update AutocompleteComposerClusterNamesTask to include start/end time dependencies, return empty location hint, handle ErrEnvironmentClusterNotFound, and return all matching past/present GKE cluster identities. - Remove unused ContainerClusterManagerClient and associated cache fields from ClientFactory.
kyasbal
marked this pull request as ready for review
August 12, 2026 02:19
kyasbal
requested review from
K53,
RyuSA,
jyane,
kkuchima and
renamoo
as code owners
August 12, 2026 02:19
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.
Problem Statement
Previously,
ComposerEnvironmentClusterFinderinvoked the live GKE API (ContainerClusterManagerClient.ListClusters) and searched for clusters whosegoog-composer-environmentresource label matched the environment name. Because this live listing API only returns currently active GKE clusters, KHI could not discover or autocomplete deleted or historical GKE clusters associated with a Cloud Composer environment.Solution & Key Changes
pkg/task/inspection/googlecloudclustercomposer/contract/environmentclusterfinder.go):ComposerEnvironmentClusterFinderinterface signature to:ListClustersAPI calls with Cloud Monitoring resource label queries (metric.type="kubernetes.io/container/uptime" AND resource.type="k8s_container").filterAndMatchComposerGKEClusterNames) that identifies historical GKE clusters by checking against the Cloud Composer naming convention:<location>-<environment>-<hash (8 chars)>-gke.-gkesuffix and 8-character hash and verifying that the remaining prefix matches<location>-<environment>, KHI discovers all matching past and present clusters.pkg/task/inspection/googlecloudclustercomposer/impl/autocompletecomposerclusternames_task.go):InputStartTimeTaskIDandInputEndTimeTaskIDso that the cache digest automatically updates when the inspection time window changes."Cluster names are suggested after the location is provided.") whenlocationis empty.AutocompleteResult.Values.pkg/api/googlecloud/clientfactory.go):ContainerClusterManagerClient(GKE ClusterManager API client) method, cache maps, configuration fields, and thecloud.google.com/go/container/apiv1import fromClientFactory, as it is no longer referenced anywhere in the repository.pkg/task/inspection/googlecloudclustercomposer/contract/environmentclusterfinder_test.goverifying cluster name extraction, hash validation, sorting, and deduplication.pkg/task/inspection/googlecloudclustercomposer/impl/autocompletecomposerclusternames_task_test.goto test the new interface signature, empty location hint, and multiple cluster autocompletion.Verification
make build-gocompleted cleanly with zero errors.go test ./pkg/task/inspection/googlecloudclustercomposer/...and fullmake test-gopassed cleanly.make pre-commitpassed with 0 linting or formatting errors across the project.