Skip to content
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

Fix kubevirt_vmi_phase_count not being created #10001

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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,
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you please elaborate on why the absence of vmc.Preference caused the metric to not be pushed and not to be collected?

Copy link
Member Author

Choose a reason for hiding this comment

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

NewConstMetric was throwing an error saying the number of labels set in vmiCountDesc and the number of labels used as arguments differed. The issue was being logged.

Also, the unit tests were incomplete, testing only the reading of the VMIs details, and were missing the creation of the metric

)
if err != nil {
log.Log.Reason(err).Errorf("Failed to create metric for VMIs phase")
Expand Down
44 changes: 34 additions & 10 deletions pkg/monitoring/vmistats/collector_test.go
Expand Up @@ -242,12 +242,24 @@ 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)

Expect(ch).To(HaveLen(1), "Expected 1 metric")
result := <-ch
dto := &io_prometheus_client.Metric{}
result.Write(dto)

for metric, count := range countMap {
Expect(metric.InstanceType).To(Equal(expected))
Expect(count).To(Equal(uint64(1)))
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 +285,24 @@ 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)

Expect(ch).To(HaveLen(1), "Expected 1 metric")
result := <-ch
dto := &io_prometheus_client.Metric{}
result.Write(dto)

for metric, count := range countMap {
Expect(metric.Preference).To(Equal(expected))
Expect(count).To(Equal(uint64(1)))
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