Skip to content

[Telemetry] Add machine_category metric for hardware classification (CPU/GPU/TPU) - #6010

Open
kadupoornima wants to merge 5 commits into
GoogleCloudPlatform:developfrom
kadupoornima:feature/machine_category_metric
Open

[Telemetry] Add machine_category metric for hardware classification (CPU/GPU/TPU)#6010
kadupoornima wants to merge 5 commits into
GoogleCloudPlatform:developfrom
kadupoornima:feature/machine_category_metric

Conversation

@kadupoornima

@kadupoornima kadupoornima commented Jul 27, 2026

Copy link
Copy Markdown
Contributor

Overview

This PR introduces a new telemetry metric machine_category to categorize instantiated compute machines dynamically by identifying their underlying hardware components (e.g., CPU, GPU, TPU). The metric outputs the detected categories similarly to existing telemetry structures maintaining consistency with execution flows. For example, the output traces configurations like a3-highgpu-8g:GPU,tpu7x-standard-4t:TPU,c2-standard-4:CPU.
Here is a section you can append directly to your PR description summarizing the categorization logic clearly for reviewers:

Categorization Logic

The telemetry extraction (detectMachineCategory) identifies the hardware bucket of an instance via a strict, prioritized sequence to handle ambiguous instance shaping (such as -standard- suffixes shared across CPU and GPU families):

  1. TPU Inference: Evaluates exactly against the toolkit's native IsTPU() identifier, correctly capturing ct*, tpu, and v* pod slice shorthands directly.
  2. GPU Lookup: Resolves natively against config.GetMachineMappings().MachineFamilyToLabelMap. Ambiguous GPU nodes like g2-standard or rtx-6000 (via shorthand substitution) natively map to "nvidia" payload labels and are flagged correctly as GPU.
  3. GPU String Keyword: Acts as a safety net explicitly catching standard types directly featuring "gpu" implicitly (like a2-highgpu-1g).
  4. CPU Lookup: With accelerators ruled out, we evaluate against all known standard CPU families using config.GetMachineMappings().CpuMachineFamilies (e.g. n1-, c2-).
  5. CPU Fallback: Finally, it checks against uniform GCP structural classifiers (-standard-, -highmem-, -highcpu-, custom-). This operates purely as a fallback to guarantee that completely undocumented new CPU families securely classify as CPU rather than Other until mappings update.

Changes

  • New Telemetry Metric: Introduced the MACHINE_CATEGORY metric to dynamically categorize compute machines as CPU, GPU, or TPU within telemetry data.
  • Classification Logic: Implemented a prioritized detection mechanism in collector_util.go that leverages existing toolkit mappings and naming conventions to identify hardware types.
  • Robust Testing: Added comprehensive unit tests in collector_test.go to validate classification accuracy across various machine types, including shorthand mappings and edge cases.

Change-Id: I7eb7dff27edbb553b8df0c3b8d99c0b623577a0f
.
Change-Id: I40a93eca881f3cd1c1cd1540fa1b5827216b4546
@kadupoornima
kadupoornima requested a review from a team as a code owner July 27, 2026 09:14
@kadupoornima kadupoornima added the release-improvements Added to release notes under the "Improvements" heading. label Jul 27, 2026
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, 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 enhances the telemetry capabilities of the toolkit by adding a machine category classification feature. By identifying the underlying hardware type of instantiated compute nodes, this change provides better visibility into the infrastructure footprint of deployments. The implementation integrates seamlessly with existing telemetry flows and ensures consistency through robust parsing logic and thorough test coverage.

Highlights

  • New Telemetry Metric: Introduced the MACHINE_CATEGORY metric to categorize compute machines (CPU, GPU, TPU) dynamically within the telemetry data.
  • Classification Logic: Implemented detectMachineCategory in collector_util.go to parse machine types by leveraging existing configuration mappings and standard naming conventions.
  • Validation: Added comprehensive unit tests in collector_test.go covering various scenarios including shorthand mappings, deduplication, and edge cases for unknown machine types.
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 the 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 counterproductive. 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.

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 introduces a new telemetry metric, CLUSTER_TOOLKIT_MACHINE_CATEGORY, which maps blueprint machine types to their inferred hardware categories (CPU, GPU, TPU, or Other). This is implemented via the getMachineCategory and detectMachineCategory functions, along with corresponding unit tests. The reviewer suggested an improvement to detectMachineCategory to ensure memory-optimized machine types (e.g., containing -megamem- or -ultramem-) are correctly classified as CPU instead of falling back to Other.

Comment thread pkg/telemetry/collector_util.go Outdated
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
@kadupoornima
kadupoornima enabled auto-merge (squash) July 27, 2026 09:31
.
Change-Id: Ieab1fa5f38cdfcb2e7f0de9934bf69f51463ded5
@kadupoornima

Copy link
Copy Markdown
Contributor Author

/gemini summary

@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

This pull request enhances the telemetry infrastructure by adding a machine category classification feature. By dynamically identifying the underlying hardware of compute instances, the toolkit now provides better visibility into the infrastructure footprint of deployments. The implementation ensures consistency with existing telemetry flows and includes robust fallback logic to handle various machine families.

Highlights

  • New Telemetry Metric: Introduced the MACHINE_CATEGORY metric to dynamically categorize compute machines as CPU, GPU, or TPU within telemetry data.
  • Classification Logic: Implemented a prioritized detection mechanism in collector_util.go that leverages existing toolkit mappings and naming conventions to identify hardware types.
  • Robust Testing: Added comprehensive unit tests in collector_test.go to validate classification accuracy across various machine types, including shorthand mappings and edge cases.
Activity
  • Gemini Code Assist provided an initial summary of the changes.
  • Gemini Code Assist suggested adding '-megamem-' and '-ultramem-' to the CPU fallback logic to ensure correct classification of memory-optimized instances.
  • The author requested a summary of the pull request.

func isCPUFallback(mType string) bool {
cpuKeywords := []string{
"-standard-", "-highmem-", "-highcpu-",
"-megamem-", "-ultramem-", "custom-",

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.

I checked that there are a few more strings we can add in this list: "-micro", "-small", "-medium", "-metal". These correspond to some of the existing GCE supported CPUs.

}

// getMachineCategory maps each machine type to its inferred hardware category (CPU/GPU/TPU/Other)
func getMachineCategory(bp config.Blueprint) string {

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.

Is there a way we can reuse the getMachineType function here? The current getMachineCategory function will probably get simpler if we use getMachineType.

},
want: "",
},
{

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.

Can we add a test to verify the isCPUFallback?

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

Labels

release-improvements Added to release notes under the "Improvements" heading.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants