Skip to content

Conversation

@mkowalski
Copy link
Member

This PR introduces a small set of metrics based on the NodeNetworkState, i.e. kubernetes_nmstate_network_interfaces and
kubernetes_nmstate_routes. Those track number of network interfaces and number of routes for every node in the cluster where nmstate handler pods are running.

This creates a skeleton for k-nmstate to create metrics based on the effective state of the network on the system and not only based on the content of NNCP.

In the future it may be used to create statistics about network topologies of clusters.

Is this a BUG FIX or a FEATURE ?:

Uncomment only one, leave it on its own line:

/kind bug
/kind enhancement

What this PR does / why we need it:

Special notes for your reviewer:

Release note:

New metrics `kubernetes_nmstate_network_interfaces` and `kubernetes_nmstate_routes` are introduced to track number of network interfaces and number of routes configured per node.

This PR introduces a small set of metrics based on the NodeNetworkState,
i.e. `kubernetes_nmstate_network_interfaces` and
`kubernetes_nmstate_routes`. Those track number of network interfaces
and number of routes for every node in the cluster where nmstate handler
pods are running.

This creates a skeleton for k-nmstate to create metrics based on the
effective state of the network on the system and not only based on the
content of NNCP.

In the future it may be used to create statistics about network
topologies of clusters.

Signed-off-by: Mat Kowalski <mko@redhat.com>
@kubevirt-bot kubevirt-bot added release-note Denotes a PR that will be considered when it comes time to generate release notes. kind/enhancement dco-signoff: yes Indicates the PR's author has DCO signed all their commits. labels Dec 19, 2025
@kubevirt-bot
Copy link
Collaborator

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign mkowalski for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@gemini-code-assist
Copy link

Summary of Changes

Hello @mkowalski, 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 significantly enhances the observability of network configurations within the cluster by introducing new Prometheus metrics derived directly from the NodeNetworkState. These metrics provide a granular view of network interfaces by type and routes by IP stack and configuration type (static/dynamic) on each node. This foundational work lays the groundwork for future capabilities, such as analyzing network topologies and gaining deeper insights into the operational state of the network.

Highlights

  • New Metrics Introduction: Two new Prometheus metrics, "kubernetes_nmstate_network_interfaces" and "kubernetes_nmstate_routes", have been introduced to provide detailed insights into the network configuration of nodes.
  • NodeNetworkState-based Monitoring: A dedicated controller (NodeNetworkStateReconciler) now actively monitors NodeNetworkState objects to collect and update these new metrics, ensuring they reflect the current network reality.
  • Interface and Route Counting Logic: New utility functions ("CountInterfacesByType", "CountRoutes") have been added to parse NodeNetworkState and accurately count network interfaces by type and routes by IP stack (IPv4/IPv6) and type (static/dynamic).
  • Comprehensive Testing: Extensive unit tests for the new counting logic and end-to-end tests for the metrics themselves have been added to ensure accuracy and reliability.
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.

Copy link

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

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 new Prometheus metrics to track network interface counts by type and network route counts by node, IP stack, and type (static/dynamic). A new NodeNetworkStateReconciler controller was added to manage these metrics, watching NodeNetworkState objects and updating kubernetes_nmstate_network_interfaces and kubernetes_nmstate_routes gauges based on the node's current network state. The controller uses in-memory maps to track previous interface types and route keys, enabling the cleanup of stale metrics when network configurations change or are deleted. Helper functions for counting interfaces and routes were added to pkg/state/filter.go, necessitating updates to pkg/state/type.go for proper data unmarshaling. Extensive unit and E2E tests were included to validate the new metrics. A review comment highlighted that the in-memory state for tracking old metrics could lead to temporary inaccuracies after controller restarts, a common consideration for Prometheus controllers.

@mkowalski
Copy link
Member Author

image image

@mkowalski
Copy link
Member Author

/test pull-kubernetes-nmstate-e2e-handler-k8s

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

Labels

dco-signoff: yes Indicates the PR's author has DCO signed all their commits. kind/enhancement release-note Denotes a PR that will be considered when it comes time to generate release notes. size/XL

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants