refactor: vmware host capacity kpi#775
Conversation
Co-authored-by: Copilot <copilot@github.com>
|
Warning Rate limit exceeded
To keep reviews running without waiting, you can enable usage-based add-on for your organization. This allows additional reviews beyond the hourly cap. Account admins can enable it under billing. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (3)
📝 WalkthroughWalkthroughThis PR relocates the VMware Host Capacity KPI implementation from the compute package to the infrastructure package, updates the YAML template description to emphasize CPU/RAM/disk metrics, removes the hypervisor_family label, and revises the KPI registry mapping accordingly. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Review rate limit: 0/1 reviews remaining, refill in 7 minutes and 20 seconds.Comment |
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
internal/knowledge/kpis/plugins/infrastructure/shared.go (1)
39-50:⚠️ Potential issue | 🟠 MajorPreserve backward-compatible host label schema (or scope this change to one KPI).
Dropping
hypervisor_familyfrom the shared VMware host labels changes the exported metric label set for all infrastructure KPIs usingvmwareHostLabels/getHostLabels. That is a breaking metrics contract and can silently break existing PromQL, alerts, and dashboards.Suggested compatibility-safe approach
return []string{ h.AvailabilityZone, h.ComputeHost, h.CPUArchitecture, h.WorkloadType, strconv.FormatBool(h.Enabled), strconv.FormatBool(h.Decommissioned), strconv.FormatBool(h.ExternalCustomer), disabledReason, + h.HypervisorFamily, strconv.FormatBool(pinnedProjects), pinnedProjectIds, } var vmwareHostLabels = []string{ "availability_zone", "compute_host", "cpu_architecture", "workload_type", "enabled", "decommissioned", "external_customer", "disabled_reason", + "hypervisor_family", "pinned_projects", "pinned_project_ids", }Also applies to: 53-64
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@internal/knowledge/kpis/plugins/infrastructure/shared.go` around lines 39 - 50, The change removed the hypervisor_family label from vmwareHostLabels/getHostLabels which breaks the exported metric label set; restore the hypervisor_family entry (or add a compatibility branch) so the label list returned by vmwareHostLabels and the callers of getHostLabels remains stable: ensure the hypervisor_family string (or an empty placeholder value when not available) is included in the slice returned by vmwareHostLabels/getHostLabels and, if this removal was intended only for a specific KPI, confine the change to that KPI function instead of the shared vmwareHostLabels/getHostLabels helpers.
🧹 Nitpick comments (1)
internal/knowledge/kpis/plugins/compute/resource_capacity_kvm_test.go (1)
42-50: Replace brittle Desc.String() parsing with fail-fast error handling.Prometheus maintainers explicitly advise against parsing
Desc.String()output—it's human-readable debug output only, not a stable API. The helper should return a boolean to signal parse failures instead of silently returning an empty string, allowing the test to fail fast and expose format changes immediately.♻️ Proposed hardening
var fqNameRe = regexp.MustCompile(`fqName: "([^"]+)"`) -func getMetricName(desc string) string { +func getMetricName(desc string) (string, bool) { match := fqNameRe.FindStringSubmatch(desc) if len(match) > 1 { - return match[1] + return match[1], true } - return "" + return "", false }And at the call site (line 1329):
metricName, ok := getMetricName(metric.Desc().String()) if !ok { t.Fatalf("failed to parse metric family name from descriptor: %s", metric.Desc().String()) }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@internal/knowledge/kpis/plugins/compute/resource_capacity_kvm_test.go` around lines 42 - 50, The helper getMetricName currently parses Desc.String() and returns an empty string on failure; change its signature to return (string, bool) and use fqNameRe.FindStringSubmatch to return (match[1], true) on success and ("", false) on failure so callers can fail fast; update the caller that uses metric.Desc().String() (the call site that currently does metricName := getMetricName(metric.Desc().String())) to receive metricName, ok := getMetricName(metric.Desc().String()) and call t.Fatalf("failed to parse metric family name from descriptor: %s", metric.Desc().String()) when ok is false.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Outside diff comments:
In `@internal/knowledge/kpis/plugins/infrastructure/shared.go`:
- Around line 39-50: The change removed the hypervisor_family label from
vmwareHostLabels/getHostLabels which breaks the exported metric label set;
restore the hypervisor_family entry (or add a compatibility branch) so the label
list returned by vmwareHostLabels and the callers of getHostLabels remains
stable: ensure the hypervisor_family string (or an empty placeholder value when
not available) is included in the slice returned by
vmwareHostLabels/getHostLabels and, if this removal was intended only for a
specific KPI, confine the change to that KPI function instead of the shared
vmwareHostLabels/getHostLabels helpers.
---
Nitpick comments:
In `@internal/knowledge/kpis/plugins/compute/resource_capacity_kvm_test.go`:
- Around line 42-50: The helper getMetricName currently parses Desc.String() and
returns an empty string on failure; change its signature to return (string,
bool) and use fqNameRe.FindStringSubmatch to return (match[1], true) on success
and ("", false) on failure so callers can fail fast; update the caller that uses
metric.Desc().String() (the call site that currently does metricName :=
getMetricName(metric.Desc().String())) to receive metricName, ok :=
getMetricName(metric.Desc().String()) and call t.Fatalf("failed to parse metric
family name from descriptor: %s", metric.Desc().String()) when ok is false.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: dc890f45-1301-4040-a47d-01b8670bfe6c
📒 Files selected for processing (8)
helm/bundles/cortex-nova/templates/kpis.yamlinternal/knowledge/kpis/plugins/compute/resource_capacity_kvm_test.gointernal/knowledge/kpis/plugins/compute/resource_capacity_vmware.gointernal/knowledge/kpis/plugins/compute/resource_capacity_vmware_test.gointernal/knowledge/kpis/plugins/infrastructure/shared.gointernal/knowledge/kpis/plugins/infrastructure/vmware_host_capacity.gointernal/knowledge/kpis/plugins/infrastructure/vmware_host_capacity_test.gointernal/knowledge/kpis/supported_kpis.go
💤 Files with no reviewable changes (2)
- internal/knowledge/kpis/plugins/compute/resource_capacity_vmware.go
- internal/knowledge/kpis/plugins/compute/resource_capacity_vmware_test.go
Co-authored-by: Copilot <copilot@github.com>
Test Coverage ReportTest Coverage 📊: 69.2% |
No description provided.