Skip to content

Commit

Permalink
Collect VMI OS info from the Guest agent
Browse files Browse the repository at this point in the history
Signed-off-by: assafad <aadmi@redhat.com>
  • Loading branch information
assafad committed Feb 18, 2024
1 parent 2817318 commit 83b9c16
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 25 deletions.
43 changes: 26 additions & 17 deletions pkg/monitoring/metrics/virt-controller/vmistats_collector.go
Expand Up @@ -61,7 +61,7 @@ var (
Name: "kubevirt_vmi_phase_count",
Help: "Sum of VMIs per phase and node. `phase` can be one of the following: [`Pending`, `Scheduling`, `Scheduled`, `Running`, `Succeeded`, `Failed`, `Unknown`].",
},
[]string{"node", "phase", "os", "workload", "flavor", "instance_type", "preference"},
[]string{"node", "phase", "os", "workload", "flavor", "instance_type", "preference", "guest_kernel_release", "guest_machine", "guest_name", "guest_version_id"},
)

vmiEvictionBlocker = operatormetrics.NewGaugeVec(
Expand All @@ -74,13 +74,17 @@ var (
)

type vmiCountMetric struct {
Phase string
OS string
Workload string
Flavor string
InstanceType string
Preference string
NodeName string
Phase string
OS string
Workload string
Flavor string
InstanceType string
Preference string
NodeName string
GuestKernelRelease string
GuestMachine string
GuestName string
GuestVersionID string
}

func vmiStatsCollectorCallback() []operatormetrics.CollectorResult {
Expand Down Expand Up @@ -117,8 +121,9 @@ func getVmisPhase(vmis []*k6tv1.VirtualMachineInstance) []operatormetrics.Collec
for vmc, count := range countMap {
cr = append(cr, operatormetrics.CollectorResult{
Metric: vmiCount,
Labels: []string{vmc.NodeName, vmc.Phase, vmc.OS, vmc.Workload, vmc.Flavor, vmc.InstanceType, vmc.Preference},
Value: float64(count),
Labels: []string{vmc.NodeName, vmc.Phase, vmc.OS, vmc.Workload, vmc.Flavor,
vmc.InstanceType, vmc.Preference, vmc.GuestKernelRelease, vmc.GuestMachine, vmc.GuestName, vmc.GuestVersionID},
Value: float64(count),
})
}

Expand All @@ -137,13 +142,17 @@ func makeVMICountMetricMap(vmis []*k6tv1.VirtualMachineInstance) map[vmiCountMet

func newVMICountMetric(vmi *k6tv1.VirtualMachineInstance) vmiCountMetric {
vmc := vmiCountMetric{
Phase: strings.ToLower(string(vmi.Status.Phase)),
OS: none,
Workload: none,
Flavor: none,
InstanceType: none,
Preference: none,
NodeName: vmi.Status.NodeName,
Phase: strings.ToLower(string(vmi.Status.Phase)),
OS: none,
Workload: none,
Flavor: none,
InstanceType: none,
Preference: none,
NodeName: vmi.Status.NodeName,
GuestKernelRelease: vmi.Status.GuestOSInfo.KernelRelease,
GuestMachine: vmi.Status.GuestOSInfo.Machine,
GuestName: vmi.Status.GuestOSInfo.Name,
GuestVersionID: vmi.Status.GuestOSInfo.VersionID,
}

updateFromAnnotations(&vmc, vmi.Annotations)
Expand Down
26 changes: 18 additions & 8 deletions pkg/monitoring/metrics/virt-controller/vmistats_collector_test.go
Expand Up @@ -152,6 +152,12 @@ var _ = Describe("Utility functions", func() {
},
Status: k6tv1.VirtualMachineInstanceStatus{
Phase: "Pending",
GuestOSInfo: k6tv1.VirtualMachineInstanceGuestOSInfo{
KernelRelease: "6.5.6-300.fc39.x86_64",
Machine: "x86_64",
Name: "Fedora Linux",
VersionID: "39",
},
},
},
{
Expand Down Expand Up @@ -197,12 +203,16 @@ var _ = Describe("Utility functions", func() {
Preference: "<none>",
}
pending := vmiCountMetric{
Phase: "pending",
OS: "fedora33",
Workload: "workstation",
Flavor: "large",
InstanceType: "<none>",
Preference: "<none>",
Phase: "pending",
OS: "fedora33",
Workload: "workstation",
Flavor: "large",
InstanceType: "<none>",
Preference: "<none>",
GuestKernelRelease: "6.5.6-300.fc39.x86_64",
GuestMachine: "x86_64",
GuestName: "Fedora Linux",
GuestVersionID: "39",
}
scheduling := vmiCountMetric{
Phase: "scheduling",
Expand Down Expand Up @@ -243,7 +253,7 @@ var _ = Describe("Utility functions", func() {
Expect(phaseResultMetric).ToNot(BeNil())
Expect(phaseResultMetric.Metric.GetOpts().Name).To(ContainSubstring("kubevirt_vmi_phase_count"))
Expect(phaseResultMetric.Value).To(BeEquivalentTo(1))
Expect(phaseResultMetric.Labels).To(HaveLen(7))
Expect(phaseResultMetric.Labels).To(HaveLen(11))
Expect(phaseResultMetric.Labels[5]).To(Equal(expected))
},
Entry("with no instance type expect <none>", k6tv1.InstancetypeAnnotation, "", "<none>"),
Expand Down Expand Up @@ -276,7 +286,7 @@ var _ = Describe("Utility functions", func() {

Expect(phaseResultMetric.Metric.GetOpts().Name).To(ContainSubstring("kubevirt_vmi_phase_count"))
Expect(phaseResultMetric.Value).To(BeEquivalentTo(1))
Expect(phaseResultMetric.Labels).To(HaveLen(7))
Expect(phaseResultMetric.Labels).To(HaveLen(11))
Expect(phaseResultMetric.Labels[6]).To(Equal(expected))
},
Entry("with no preference expect <none>", k6tv1.PreferenceAnnotation, "", "<none>"),
Expand Down

0 comments on commit 83b9c16

Please sign in to comment.