Skip to content

use Cloud Monitoring for cluster autocomplete#413

Merged
kyasbal merged 2 commits into
GoogleCloudPlatform:mainfrom
kyasbal:feat/historical-cluster-autocomplete
Dec 15, 2025
Merged

use Cloud Monitoring for cluster autocomplete#413
kyasbal merged 2 commits into
GoogleCloudPlatform:mainfrom
kyasbal:feat/historical-cluster-autocomplete

Conversation

@kyasbal

@kyasbal kyasbal commented Dec 10, 2025

Copy link
Copy Markdown
Member

This PR refactors the cluster name autocomplete functionality to use Cloud Monitoring's TimeSeries API instead of the specific cluster management APIs (e.g., GKE API). This change enables KHI to suggest historical cluster names that existed within the inspection time window, even if those clusters have since been deleted.
Previously, autocomplete only supported currently running clusters via the GKE API.

NOTE: This change is not covering the autocomplete logic change for the Cloud Composer cluster name autocompletion because it uses the resource label obtained from GKE API and it's not possible to take the value from metrics API.

Key Changes

  • Generic Autocomplete Implementation: Centralized the autocomplete logic in pkg/task/inspection/googlecloudk8scommon, removing duplicated implementations for GKE, GDC, and MultiCloud.
  • Data Source: Uses monitoring.timeSeries.list to query metrics and discover cluster names.
    • GKE: Uses kubernetes.io/container/uptime
    • Others (GDC, MultiCloud): Uses kubernetes.io/anthos/container/uptime
    • Note: These metrics were chosen for their 24-month retention period, allowing for long-term historical discovery.
  • New Utility: Added QueryDistinctLabelValuesFromMetrics in pkg/api/googlecloud/monitoring_util.go to handle generic distinct value querying from partial metrics.
  • Permissions: Added monitoring.timeSeries.list to the recommended permissions in README.md.

Related Issues

Closes #412

Verification

  • Verified that deleted clusters appear in the autocomplete suggestions when the time range covers their lifespan.
  • Verified that GKE, GDC, and MultiCloud cluster types correctly invoke the common task with their respective prefixes.

Changes the data source for GKE cluster name autocomplete from the GKE API to the Cloud Monitoring TimeSeries API.
By querying the `logging.googleapis.com/log_entry_count` metric, the autocomplete can now suggest clusters that existed during the inspection time window, even if they have since been deleted.
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @kyasbal, 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 refactors the GKE cluster name autocomplete functionality to utilize the Cloud Monitoring TimeSeries API. This strategic shift enables the system to provide more comprehensive suggestions, including clusters that may have been deleted but were active during a user-defined inspection period. The change involves integrating a new monitoring client, updating the cluster fetching logic to query metric data, and enhancing user feedback for scenarios where no clusters are identified within the specified time window.

Highlights

  • Data Source Change: The GKE cluster autocomplete functionality now sources its data from the Cloud Monitoring TimeSeries API instead of directly from the GKE API.
  • Historical Cluster Suggestions: Autocomplete can now suggest GKE clusters that existed within a specified inspection time window, even if they have since been deleted, by querying the logging.googleapis.com/log_entry_count metric.
  • Monitoring Client Integration: A new MonitoringMetricClient has been added to the ClientFactory to facilitate interaction with the Cloud Monitoring API.
  • Time Window Parameters: The GetClusterNames function now accepts startTime and endTime parameters, allowing for time-bound cluster lookups and historical data retrieval.
  • Improved User Feedback: Added a Hint field to the AutocompleteClusterNameList and logic to display informative messages when no clusters are found or metrics are unavailable for the specified time range.
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.

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

Copy link
Copy Markdown
Contributor

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 refactors the GKE cluster name autocomplete feature to use the Cloud Monitoring API instead of the GKE API. This is a great improvement as it allows autocompletion for clusters that existed within the selected time frame, even if they have been deleted. The implementation is well-structured, following existing patterns for adding new Google Cloud clients and tasks.

I've identified a potential issue with the alignment_period in the Monitoring API call which could lead to incorrect results for small time windows. I've also included a minor suggestion to improve the formatting of a user-facing hint message. Overall, this is a valuable change.

Comment thread pkg/task/inspection/googlecloudclustergke/contract/gkeclusterlistfetcher.go Outdated
@kyasbal kyasbal changed the title use Cloud Monitoring for GKE cluster autocomplete use Cloud Monitoring for cluster autocomplete Dec 15, 2025
@kyasbal kyasbal added enhancement New feature or request backend:parser labels Dec 15, 2025
@kyasbal kyasbal marked this pull request as ready for review December 15, 2025 01:58
Refactors cluster name autocomplete to utilize Cloud Monitoring, enabling historical cluster discovery. This change centralizes the autocomplete logic and removes provider-specific implementations.
- feat: implement generic `AutocompleteClusterNamesTask` in `googlecloudk8scommon` using Cloud Monitoring metrics.
- feat: add `QueryDistinctLabelValuesFromMetrics` utility for generic metric label querying.
- refactor: remove specific autocomplete tasks for GKE, GDC, and MultiCloud in favor of the common implementation.
- fix: correct task dependencies in `InputClusterNameTask` to use reference IDs.
- doc: update README.md and README.ja.md with new optional permissions for autocomplete.
@kyasbal kyasbal force-pushed the feat/historical-cluster-autocomplete branch from d78fd2d to 6b53dc6 Compare December 15, 2025 02:00

@renamoo renamoo left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I quickly went through the change and it looks good to me, but if this PR needs review by someone with backend expertise, feel free to wait for their review

@kyasbal kyasbal merged commit 9a96dc7 into GoogleCloudPlatform:main Dec 15, 2025
8 of 9 checks passed
Comment on lines +76 to +78
if err != nil {
errorString = err.Error()
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

How about adding a 403 error handling, like "You may miss a permission monitoring.timeSeries.list Cluster name suggestions does not work correctly."

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

Labels

backend:parser enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Use Cloud Monitoring for historical GKE cluster name autocomplete

3 participants