8000 add kubevirt metrics and dashboards by klinch0 · Pull Request #573 · cozystack/cozystack · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

add kubevirt metrics and dashboards #573

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged

Conversation

klinch0
Copy link
Contributor
@klinch0 klinch0 commented Jan 15, 2025

Summary by CodeRabbit

  • New Features

    • Introduced ServiceMonitor for KubeVirt metrics.
    • Added new dashboard for KubeVirt control plane monitoring.
  • Monitoring Improvements

    • Implemented PrometheusRule alerts for tracking VM and VMI running status.
    • Added configuration to monitor VM health and performance.
  • Configuration Updates

    • Updated KubeVirt configuration with new monitoring namespace setting.

@klinch0 klinch0 requested a review from kvaps as a code owner January 15, 2025 12:36
Copy link
Contributor
coderabbitai bot commented Jan 15, 2025

Caution

Review failed

The pull request is closed.

Walkthrough

This pull request introduces several enhancements to KubeVirt monitoring capabilities. A new ServiceMonitor resource is added for metrics collection, alongside a PrometheusRule to monitor the statuses of virtual machines (VMs) and virtual machine instances (VMIs). Additionally, a new dashboard entry for the KubeVirt control plane is included. The changes also implement a templating logic that aggregates alert configurations into a single YAML document, improving the overall monitoring infrastructure.

Changes

File Change Summary
packages/system/kubevirt-operator/templates/ServiceMonitor.yaml Added new ServiceMonitor resource for KubeVirt metrics with HTTPS endpoint
packages/system/kubevirt/templates/kubevirt-cr.yaml Added monitorNamespace: tenant-root field in KubeVirt spec
packages/extra/monitoring/dashboards.list Added new dashboard entry: kubevirt/kubevirt-control-plane
packages/system/kubevirt-operator/alerts/PrometheusRule.yaml Added PrometheusRule with alerts for VMs and VMIs not running for 10+ minutes
packages/system/kubevirt-operator/templates/alerts.yaml Updated templating logic to include alert configurations dynamically

Possibly related PRs

  • add kubevirt metrics and dashboards #573: The changes in this PR also introduce a new ServiceMonitor resource with the name kubevirt, which directly relates to the main PR's introduction of the same resource.

Suggested reviewers

  • kvaps

Poem

🐰 In the land of KubeVirt, metrics take flight,
A ServiceMonitor gleams, shining so bright.
Alerts hop forth, keeping watch with delight,
VMs and VMIs, in their monitoring sight.
With dashboards and rules, all systems align,
In this garden of code, everything's fine! 🚀


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 30abd86 and 92ba04a.

📒 Files selected for processing (5)
  • packages/extra/monitoring/dashboards.list (1 hunks)
  • packages/system/kubevirt-operator/alerts/PrometheusRule.yaml (1 hunks)
  • packages/system/kubevirt-operator/templates/ServiceMonitor.yaml (1 hunks)
  • packages/system/kubevirt-operator/templates/alerts.yaml (1 hunks)
  • packages/system/kubevirt/templates/kubevirt-cr.yaml (1 hunks)

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor
@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 5

🧹 Nitpick comments (1)
packages/system/kubevirt-operator/templates/PrometheusRule.yaml (1)

11-18: Optimize alert expressions for better performance.

The current expressions using max_over_time with regex matching could be optimized.

Consider these optimizations:

  1. Use absent() function to detect when metrics are missing
  2. Add more specific label matchers instead of regex
  3. Consider using for: 10m instead of max_over_time

Example optimization:

-      expr: |
-        max_over_time(
-          kubevirt_vm_info{
-            status!="Running",
-            exported_namespace=~".+",
-            name=~".+"
-          }[10m]
-        ) == 1
+      expr: kubevirt_vm_info{status!="Running"} == 1
+      for: 10m

Also applies to: 27-34

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 34d6ab0 and a5c049e.

📒 Files selected for processing (3)
  • packages/system/kubevirt-operator/templates/PrometheusRule.yaml (1 hunks)
  • packages/system/kubevirt-operator/templates/ServiceMonitor.yaml (1 hunks)
  • packages/system/kubevirt/templates/kubevirt-cr.yaml (1 hunks)
🔇 Additional comments (1)
packages/system/kubevirt/templates/kubevirt-cr.yaml (1)

16-16: Verify namespace configuration consistency.

The monitorNamespace is set to tenant-root, but the PrometheusRule is deployed in the monitoring namespace. This inconsistency might affect metric collection.

Let's verify the namespace configuration:

Comment on lines +6 to +8
selector:
matchLabels:
prometheus.kubevirt.io: "true"
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Specify namespaceSelector for better control.

The ServiceMonitor lacks a namespaceSelector, which means it could potentially scrape metrics from any namespace where the label selector matches.

Add a namespaceSelector to restrict metric collection to specific namespaces:

 spec:
   selector:
     matchLabels:
       prometheus.kubevirt.io: "true"
+  namespaceSelector:
+    matchNames:
+    - cozy-kubevirt
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
selector:
matchLabels:
prometheus.kubevirt.io: "true"
selector:
matchLabels:
prometheus.kubevirt.io: "true"
namespaceSelector:
matchNames:
- cozy-kubevirt

Comment on lines +12 to +13
tlsConfig:
insecureSkipVerify: true
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Security concern: TLS verification is disabled.

Using insecureSkipVerify: true in production environments is risky as it bypasses certificate validation, making the connection susceptible to man-in-the-middle attacks.

Consider one of these approaches:

  1. Configure proper certificates and remove insecureSkipVerify
  2. If self-signed certificates are used, specify the CA certificate instead:
   tlsConfig:
-    insecureSkipVerify: true
+    ca:
+      configMap:
+        name: kubevirt-ca-cert
+        key: ca.crt

Committable suggestion skipped: line range outside the PR's diff.

Comment on lines 19 to 22
labels:
severity: critical
annotations:
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Enhance alert metadata for better operability.

The alerts lack important metadata that would help with routing and troubleshooting.

Add standard labels for better alert handling:

       labels:
         severity: critical
+        team: virtualization
+        component: kubevirt
+        alert_group: vm_status

Also add runbook URLs to help operators:

       annotations:
         summary: "VM '{{ $labels.name }}' in namespace '{{ $labels.exported_namespace }}' is not Running for more than 10 minutes"
         description: >
           The VM '{{ $labels.name }}' in namespace '{{ $labels.exported_namespace }}' has been in a non-Running state
           for more than 10 minutes. Please investigate the issue.
+        runbook_url: https://your-runbooks/kubevirt/vm-not-running

Also applies to: 35-37

Comment on lines 40 to 43
The VM '{{ $labels.name }}' in namespace '{{ $labels.exported_namespace }}' has been in a non-Running state
for more than 10 minutes. Please investigate the issue.
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Fix incorrect reference in VMI alert description.

The description for VMINotRunningFor10Minutes incorrectly refers to "VM" instead of "VMI".

       description: >
-          The VM '{{ $labels.name }}' in namespace '{{ $labels.exported_namespace }}' has been in a non-Running state
+          The VMI '{{ $labels.name }}' in namespace '{{ $labels.exported_namespace }}' has been in a non-Running state
           for more than 10 minutes. Please investigate the issue.
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
The VM '{{ $labels.name }}' in namespace '{{ $labels.exported_namespace }}' has been in a non-Running state
for more than 10 minutes. Please investigate the issue.
The VMI '{{ $labels.name }}' in namespace '{{ $labels.exported_namespace }}' has been in a non-Running state
for more than 10 minutes. Please investigate the issue.

kind: PrometheusRule
metadata:
name: vm-not-running-alert
namespace: monitoring
Copy link
Contributor

Choose a reason for hiding this comment

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

💡 Codebase verification

PrometheusRule namespace must be aligned with monitoring stack

The PrometheusRule is currently set to use the monitoring namespace, but the monitoring stack is configured to use cozy-monitoring. Update the namespace to match:

metadata:
  name: vm-not-running-alert
  namespace: cozy-monitoring
🔗 Analysis chain

Verify namespace alignment with monitoring stack.

The PrometheusRule is deployed in the monitoring namespace, but this might not align with your monitoring stack's configuration.

Let's verify the monitoring setup:

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check for Prometheus Operator CRDs and their configuration
kubectl get prometheusrules -A -o json | jq -r '.items[].metadata.namespace' | sort | uniq

# Check if monitoring namespace has required labels
kubectl get ns monitoring -o json 2>/dev/null | jq -r '.metadata.labels'

Length of output: 251


Script:

#!/bin/bash
# Find all PrometheusRule resources and their namespace configurations
rg -l "kind:\s*PrometheusRule" --type yaml
rg "namespace:\s*monitoring" --type yaml -C2

# Look for monitoring stack configuration
fd -e yaml -e yml | xargs rg "prometheusOperator|prometheus-operator" -l

Length of output: 3593


Script:

#!/bin/bash
# Check monitoring namespace configuration in monitoring components
rg -A 3 "namespace:" packages/system/monitoring-agents/
rg -A 3 "namespace:" packages/system/victoria-metrics-operator/

# Check for monitoring stack configuration files
fd -e yaml -e yml -p "monitoring|prometheus" packages/system/monitoring-agents/ | xargs cat

Length of output: 71604

@dosubot dosubot bot added size:M This PR changes 30-99 lines, ignoring generated files. enhancement New feature or request labels Jan 15, 2025
@klinch0 klinch0 force-pushed the feature/add-kubevirt-metrics-and-dashboard branch from a5c049e to 30abd86 Compare January 15, 2025 13:44
Copy link
Contributor
@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a5c049e and 30abd86.

📒 Files selected for processing (5)
  • packages/apps/versions_map (4 hunks)
  • packages/extra/versions_map (2 hunks)
  • packages/system/kubevirt-operator/templates/PrometheusRule.yaml (1 hunks)
  • packages/system/kubevirt-operator/templates/ServiceMonitor.yaml (1 hunks)
  • packages/system/kubevirt/templates/kubevirt-cr.yaml (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • packages/extra/versions_map
🚧 Files skipped from review as they are similar to previous changes (3)
  • packages/system/kubevirt/templates/kubevirt-cr.yaml
  • packages/system/kubevirt-operator/templates/ServiceMonitor.yaml
  • packages/system/kubevirt-operator/templates/PrometheusRule.yaml
🔇 Additional comments (1)
packages/apps/versions_map (1)

69-69: Clarify the need for postgres and redis version updates.

The updates to postgres and redis packages appear unrelated to the PR's objective of adding KubeVirt metrics and dashboards. Please explain why these changes are necessary in this PR.

Also applies to: 82-82

@@ -42,7 +42,7 @@ kubernetes 0.12.0 74649f8
kubernetes 0.12.1 28fca4e
kubernetes 0.13.0 ced8e5b9
kubernetes 0.14.0 bfbde07c
kubernetes 0.14.1 d14b66ce
kubernetes 0.14.1 fde4bcfa
Copy link
Contributor

Choose a reason for hiding this comment

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

💡 Codebase verification

Standardize commit hash lengths to 8 characters

Please update the following commit hashes to use 8 characters for consistency:

  • 175a65f175a65f0 (postgres)
  • cad9cdecad9cde0 (virtual-machine)
🔗 Analysis chain

Verify commit hashes and standardize their length.

Please verify that all commit hashes are valid and consider standardizing their length (7 or 8 characters) for consistency:

Also applies to: 69-69, 82-82, 108-108, 112-112

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify if the commit hashes exist and are valid

# Function to check commit
check_commit() {
    local package=$1
    local version=$2
    local commit=$3
    
    echo "Checking $package $version commit $commit:"
    if git rev-parse --quiet --verify "$commit^{commit}" >/dev/null 2>&1; then
        echo "✓ Valid commit"
        # Show first line of commit message
        git log -1 --pretty=format:"%s" "$commit" 2>/dev/null
    else
        echo "✗ Invalid commit"
    fi
    echo
}

# Check all updated commits
check_commit "kubernetes" "0.14.1" "fde4bcfa"
check_commit "postgres" "0.7.1" "175a65f"
check_commit "redis" "0.4.0" "abc8f082"
check_commit "virtual-machine" "0.5.0" "cad9cde"
check_commit "vm-instance" "0.2.0" "4f767ee3"

Length of output: 1534

@klinch0 klinch0 force-pushed the feature/add-kubevirt-metrics-and-dashboard branch from 30abd86 to dd87935 Compare January 16, 2025 09:55
Copy link
Member
@kvaps kvaps left a comment

Choose a reason for hiding this comment

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

LGTM

@kvaps kvaps merged commit 9f9a774 into cozystack:main Jan 16, 2025
1 check passed
@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Jan 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request lgtm This PR has been approved by a maintainer size:M This PR changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
0