Skip to content

Conversation

loktev-d
Copy link
Contributor

@loktev-d loktev-d commented Oct 15, 2025

Description

Added three new Prometheus metrics for VirtualDisk resources to improve observability:

  1. d8_virtualization_virtualdisk_capacity_bytes - Reports disk capacity in bytes

    • Labels: name, namespace, uid
    • Value: Parsed from .status.capacity field
  2. d8_virtualization_virtualdisk_info - Provides disk metadata (info metric pattern)

    • Labels: name, namespace, uid, storageclass, persistentvolumeclaim
    • Value: Always 1
    • Exposes storage class and PVC name for correlation
  3. d8_virtualization_virtualdisk_status_inuse - Indicates whether disk is actively used

    • Labels: name, namespace, uid, virtualmachine
    • Value: 1 when in use, 0 otherwise
    • Determined from InUse condition and attached VirtualMachines list

Why do we need it, and what problem does it solve?

What is the expected result?

Checklist

  • The code is covered by unit tests.
  • e2e tests passed.
  • Documentation updated according to the changes.
  • Changes were tested in the Kubernetes cluster manually.

Changelog entries

section: observability
type: feature
summary: Added three new Prometheus metrics for VirtualDisk monitoring (capacity_bytes, info, and status_inuse).

Signed-off-by: Daniil Loktev <[email protected]>
Copy link
Contributor

sourcery-ai bot commented Oct 15, 2025

Reviewer's Guide

This PR enhances the VirtualDisk monitoring by introducing three new Prometheus metrics—capacity_bytes, info, and status_inuse—through extending the data model, registering the new metrics, and updating the scraper logic to emit them.

Sequence diagram for emitting new VirtualDisk metrics in scraper.Report

sequenceDiagram
participant S as scraper
participant DM as dataMetric
participant P as Prometheus
S->>DM: Report(m)
S->>S: updateMetricDiskCapacityBytes(m)
S->>P: emit capacity_bytes metric
S->>S: updateMetricDiskInfo(m)
S->>P: emit info metric
S->>S: updateMetricDiskStatusInUse(m)
S->>P: emit status_inuse metric
Loading

Class diagram for updated dataMetric struct with new fields for metrics

classDiagram
class dataMetric {
  +string Name
  +string Namespace
  +string UID
  +DiskPhase Phase
  +map<string, string> Labels
  +map<string, string> Annotations
  +int64 CapacityBytes
  +string StorageClass
  +string PersistentVolumeClaim
  +bool InUse
  +string[] AttachedVirtualMachines
}

class VirtualDisk
class DiskPhase

VirtualDisk <.. dataMetric : used in
DiskPhase <.. dataMetric : used in
Loading

Class diagram for new metric registration constants and map

classDiagram
class metrics {
}
class MetricInfo {
  +string Name
  +string Help
  +ValueType Type
  +string[] Labels
}

class diskMetrics {
  +MetricInfo MetricDiskStatusPhase
  +MetricInfo MetricDiskLabels
  +MetricInfo MetricDiskAnnotations
  +MetricInfo MetricDiskCapacityBytes
  +MetricInfo MetricDiskInfo
  +MetricInfo MetricDiskStatusInUse
}

metrics <.. MetricInfo : creates
metrics <.. diskMetrics : contains
Loading

Class diagram for scraper methods handling new metrics

classDiagram
class scraper {
  +Report(m *dataMetric)
  +updateMetricDiskStatusPhase(m *dataMetric)
  +updateMetricDiskLabels(m *dataMetric)
  +updateMetricDiskAnnotations(m *dataMetric)
  +updateMetricDiskCapacityBytes(m *dataMetric)
  +updateMetricDiskInfo(m *dataMetric)
  +updateMetricDiskStatusInUse(m *dataMetric)
  +defaultUpdate(descName string, value float64, m *dataMetric, labels ...string)
}

scraper --> dataMetric : uses
Loading

File-Level Changes

Change Details Files
Extend dataMetric model and initialization
  • Added fields: CapacityBytes, StorageClass, PersistentVolumeClaim, InUse, AttachedVirtualMachines
  • Extracted capacity parsing into parseCapacityBytes function
  • Determined in-use state and attached VMs via getInUseStatus function
  • Populated new fields in newDataMetric constructor
images/virtualization-artifact/pkg/monitoring/metrics/vd/data_metric.go
Register new metrics in metrics map
  • Defined constants for capacity_bytes, info, and status_inuse metrics
  • Added MetricInfo entries for the three new metrics with appropriate labels and descriptions
images/virtualization-artifact/pkg/monitoring/metrics/vd/metrics.go
Implement scraper updates for new metrics
  • Invoked update methods for capacityBytes, info, and statusInUse in Report
  • Implemented updateMetricDiskCapacityBytes, updateMetricDiskInfo, and updateMetricDiskStatusInUse methods
images/virtualization-artifact/pkg/monitoring/metrics/vd/scraper.go

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey there - I've reviewed your changes and they look great!

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location> `images/virtualization-artifact/pkg/monitoring/metrics/vd/metrics.go:29-31` </location>
<code_context>
+	MetricDiskStatusPhase   = "virtualdisk_status_phase"
+	MetricDiskLabels        = "virtualdisk_labels"
+	MetricDiskAnnotations   = "virtualdisk_annotations"
+	MetricDiskCapacityBytes = "virtualdisk_capacity_bytes"
+	MetricDiskInfo          = "virtualdisk_info"
+	MetricDiskStatusInUse   = "virtualdisk_status_inuse"
 )

</code_context>

<issue_to_address>
**suggestion:** Metric naming is inconsistent: consider using underscores for all metric names.

'virtualdisk_info' and 'virtualdisk_status_inuse' do not follow the underscore naming convention used by the other metrics. Please update these for consistency.
</issue_to_address>

### Comment 2
<location> `images/virtualization-artifact/pkg/monitoring/metrics/vd/scraper.go:90-96` </location>
<code_context>
+	s.defaultUpdate(MetricDiskInfo, 1, m, m.StorageClass, m.PersistentVolumeClaim)
+}
+
+func (s *scraper) updateMetricDiskStatusInUse(m *dataMetric) {
+	value := float64(0)
+	if m.InUse {
+		value = 1
+	}
+	s.defaultUpdate(MetricDiskStatusInUse, value, m, m.AttachedVirtualMachine)
+}
+
</code_context>

<issue_to_address>
**suggestion:** AttachedVirtualMachine label may be empty when InUse is false.

This could cause confusion in metrics interpretation. Consider omitting the label or using a sentinel value when the disk is not in use.

```suggestion
func (s *scraper) updateMetricDiskStatusInUse(m *dataMetric) {
	value := float64(0)
	attachedVM := "none"
	if m.InUse {
		value = 1
		attachedVM = m.AttachedVirtualMachine
	}
	s.defaultUpdate(MetricDiskStatusInUse, value, m, attachedVM)
}
```
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment on lines 90 to 96
func (s *scraper) updateMetricDiskStatusInUse(m *dataMetric) {
value := float64(0)
if m.InUse {
value = 1
}
s.defaultUpdate(MetricDiskStatusInUse, value, m, m.AttachedVirtualMachine)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion: AttachedVirtualMachine label may be empty when InUse is false.

This could cause confusion in metrics interpretation. Consider omitting the label or using a sentinel value when the disk is not in use.

Suggested change
func (s *scraper) updateMetricDiskStatusInUse(m *dataMetric) {
value := float64(0)
if m.InUse {
value = 1
}
s.defaultUpdate(MetricDiskStatusInUse, value, m, m.AttachedVirtualMachine)
}
func (s *scraper) updateMetricDiskStatusInUse(m *dataMetric) {
value := float64(0)
attachedVM := "none"
if m.InUse {
value = 1
attachedVM = m.AttachedVirtualMachine
}
s.defaultUpdate(MetricDiskStatusInUse, value, m, attachedVM)
}

Signed-off-by: Daniil Loktev <[email protected]>
@loktev-d loktev-d marked this pull request as draft October 15, 2025 20:17
Signed-off-by: Daniil Loktev <[email protected]>
@loktev-d loktev-d added the e2e/run Run e2e test on cluster of PR author label Oct 16, 2025
@deckhouse-BOaTswain
Copy link
Contributor

deckhouse-BOaTswain commented Oct 16, 2025

Workflow has started.
Follow the progress here: Workflow Run

The target step completed with status: success.

@deckhouse-BOaTswain deckhouse-BOaTswain removed the e2e/run Run e2e test on cluster of PR author label Oct 16, 2025
@loktev-d loktev-d added this to the v1.1.1 milestone Oct 16, 2025
@loktev-d loktev-d marked this pull request as ready for review October 16, 2025 11:47
Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey there - I've reviewed your changes - here's some feedback:

  • updateMetricDiskStatusInUse emits a 0 metric with an empty 'virtualmachine' label when the disk is not in use; consider omitting the VM label entirely or using a placeholder value instead of an empty string to avoid unlabeled metrics.
  • parseCapacityBytes silently returns 0 on errors or non-integer quantities; consider logging parse errors or using AsApproximateFloat64 to handle fractional capacities more accurately.
  • updateMetricDiskStatusInUse loops over each attached VM and emits a separate metric, which may introduce high cardinality—verify that emitting per-VM metrics aligns with your observability and performance requirements.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- updateMetricDiskStatusInUse emits a 0 metric with an empty 'virtualmachine' label when the disk is not in use; consider omitting the VM label entirely or using a placeholder value instead of an empty string to avoid unlabeled metrics.
- parseCapacityBytes silently returns 0 on errors or non-integer quantities; consider logging parse errors or using AsApproximateFloat64 to handle fractional capacities more accurately.
- updateMetricDiskStatusInUse loops over each attached VM and emits a separate metric, which may introduce high cardinality—verify that emitting per-VM metrics aligns with your observability and performance requirements.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@loktev-d loktev-d marked this pull request as draft October 16, 2025 11:50
@nevermarine nevermarine modified the milestones: v1.1.1, v1.2.0 Oct 16, 2025
Signed-off-by: Daniil Loktev <[email protected]>
@loktev-d loktev-d marked this pull request as ready for review October 16, 2025 19:36
Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey there - I've reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants