Skip to content

Commit

Permalink
Fix kubevirt_vmi_phase_count not being created
Browse files Browse the repository at this point in the history
Signed-off-by: João Vilaça <jvilaca@redhat.com>
  • Loading branch information
machadovilaca committed Jun 28, 2023
1 parent b9799d1 commit 09374fb
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 11 deletions.
2 changes: 1 addition & 1 deletion pkg/monitoring/vmistats/collector.go
Expand Up @@ -250,7 +250,7 @@ func (co *VMICollector) updateVMIsPhase(vmis []*k6tv1.VirtualMachineInstance, ch
mv, err := prometheus.NewConstMetric(
vmiCountDesc, prometheus.GaugeValue,
float64(count),
vmc.NodeName, vmc.Phase, vmc.OS, vmc.Workload, vmc.Flavor, vmc.InstanceType,
vmc.NodeName, vmc.Phase, vmc.OS, vmc.Workload, vmc.Flavor, vmc.InstanceType, vmc.Preference,
)
if err != nil {
log.Log.Reason(err).Errorf("Failed to create metric for VMIs phase")
Expand Down
50 changes: 40 additions & 10 deletions pkg/monitoring/vmistats/collector_test.go
Expand Up @@ -242,12 +242,27 @@ var _ = Describe("Utility functions", func() {
},
}

countMap := co.makeVMICountMetricMap(vmis)
Expect(countMap).To(HaveLen(1))
ch := make(chan prometheus.Metric, 1)
defer close(ch)
co.updateVMIsPhase(vmis, ch)

if len(ch) != 1 {
Fail("Expected 1 metric")
}

for metric, count := range countMap {
Expect(metric.InstanceType).To(Equal(expected))
Expect(count).To(Equal(uint64(1)))
result := <-ch
dto := &io_prometheus_client.Metric{}
result.Write(dto)

Expect(result).ToNot(BeNil())
Expect(result.Desc().String()).To(ContainSubstring("kubevirt_vmi_phase_count"))
Expect(dto.Gauge.GetValue()).To(BeEquivalentTo(1))
Expect(dto.Label).To(HaveLen(7))
for _, pair := range dto.Label {
if pair.GetName() == "instance_type" {
Expect(pair.GetValue()).To(Equal(expected))
return
}
}
},
Entry("with no instance type expect <none>", k6tv1.InstancetypeAnnotation, "", "<none>"),
Expand All @@ -273,12 +288,27 @@ var _ = Describe("Utility functions", func() {
},
}

countMap := co.makeVMICountMetricMap(vmis)
Expect(countMap).To(HaveLen(1))
ch := make(chan prometheus.Metric, 1)
defer close(ch)
co.updateVMIsPhase(vmis, ch)

if len(ch) != 1 {
Fail("Expected 1 metric")
}

for metric, count := range countMap {
Expect(metric.Preference).To(Equal(expected))
Expect(count).To(Equal(uint64(1)))
result := <-ch
dto := &io_prometheus_client.Metric{}
result.Write(dto)

Expect(result).ToNot(BeNil())
Expect(result.Desc().String()).To(ContainSubstring("kubevirt_vmi_phase_count"))
Expect(dto.Gauge.GetValue()).To(BeEquivalentTo(1))
Expect(dto.Label).To(HaveLen(7))
for _, pair := range dto.Label {
if pair.GetName() == "preference" {
Expect(pair.GetValue()).To(Equal(expected))
return
}
}
},
Entry("with no preference expect <none>", k6tv1.PreferenceAnnotation, "", "<none>"),
Expand Down

0 comments on commit 09374fb

Please sign in to comment.