-
Notifications
You must be signed in to change notification settings - Fork 3
feat(observability): add VirtualDisk capacity, info, and in-use metrics #1592
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
base: main
Are you sure you want to change the base?
Conversation
Signed-off-by: Daniil Loktev <[email protected]>
Reviewer's GuideThis 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.ReportsequenceDiagram
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
Class diagram for updated dataMetric struct with new fields for metricsclassDiagram
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
Class diagram for new metric registration constants and mapclassDiagram
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
Class diagram for scraper methods handling new metricsclassDiagram
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
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this 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>
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
images/virtualization-artifact/pkg/monitoring/metrics/vd/metrics.go
Outdated
Show resolved
Hide resolved
func (s *scraper) updateMetricDiskStatusInUse(m *dataMetric) { | ||
value := float64(0) | ||
if m.InUse { | ||
value = 1 | ||
} | ||
s.defaultUpdate(MetricDiskStatusInUse, value, m, m.AttachedVirtualMachine) | ||
} |
There was a problem hiding this comment.
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.
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]>
Signed-off-by: Daniil Loktev <[email protected]>
Workflow has started. The target step completed with status: success. |
There was a problem hiding this 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.
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
Signed-off-by: Daniil Loktev <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Description
Added three new Prometheus metrics for VirtualDisk resources to improve observability:
d8_virtualization_virtualdisk_capacity_bytes
- Reports disk capacity in bytesname
,namespace
,uid
.status.capacity
fieldd8_virtualization_virtualdisk_info
- Provides disk metadata (info metric pattern)name
,namespace
,uid
,storageclass
,persistentvolumeclaim
1
d8_virtualization_virtualdisk_status_inuse
- Indicates whether disk is actively usedname
,namespace
,uid
,virtualmachine
1
when in use,0
otherwiseInUse
condition and attached VirtualMachines listWhy do we need it, and what problem does it solve?
What is the expected result?
Checklist
Changelog entries