From 83b9c1604b6fe4912d34867e950dc3c066216544 Mon Sep 17 00:00:00 2001 From: Assaf Admi Date: Sun, 18 Feb 2024 12:44:50 +0200 Subject: [PATCH] Collect VMI OS info from the Guest agent Signed-off-by: assafad --- .../virt-controller/vmistats_collector.go | 43 +++++++++++-------- .../vmistats_collector_test.go | 26 +++++++---- 2 files changed, 44 insertions(+), 25 deletions(-) diff --git a/pkg/monitoring/metrics/virt-controller/vmistats_collector.go b/pkg/monitoring/metrics/virt-controller/vmistats_collector.go index 9fa7e881062e..d2448ebcfb7c 100644 --- a/pkg/monitoring/metrics/virt-controller/vmistats_collector.go +++ b/pkg/monitoring/metrics/virt-controller/vmistats_collector.go @@ -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( @@ -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 { @@ -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), }) } @@ -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) diff --git a/pkg/monitoring/metrics/virt-controller/vmistats_collector_test.go b/pkg/monitoring/metrics/virt-controller/vmistats_collector_test.go index 4d24e447ac21..b558105f7b73 100644 --- a/pkg/monitoring/metrics/virt-controller/vmistats_collector_test.go +++ b/pkg/monitoring/metrics/virt-controller/vmistats_collector_test.go @@ -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", + }, }, }, { @@ -197,12 +203,16 @@ var _ = Describe("Utility functions", func() { Preference: "", } pending := vmiCountMetric{ - Phase: "pending", - OS: "fedora33", - Workload: "workstation", - Flavor: "large", - InstanceType: "", - Preference: "", + Phase: "pending", + OS: "fedora33", + Workload: "workstation", + Flavor: "large", + InstanceType: "", + Preference: "", + GuestKernelRelease: "6.5.6-300.fc39.x86_64", + GuestMachine: "x86_64", + GuestName: "Fedora Linux", + GuestVersionID: "39", } scheduling := vmiCountMetric{ Phase: "scheduling", @@ -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 ", k6tv1.InstancetypeAnnotation, "", ""), @@ -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 ", k6tv1.PreferenceAnnotation, "", ""),