Skip to content

Commit

Permalink
Update metrics tests to expect float64 output
Browse files Browse the repository at this point in the history
Signed-off-by: João Vilaça <[email protected]>
  • Loading branch information
machadovilaca committed Jul 28, 2023
1 parent 98575ef commit 014a6db
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
10 changes: 5 additions & 5 deletions tests/monitoring/prometheus_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,12 @@ func getAlerts(cli kubecli.KubevirtClient) ([]prometheusv1.Alert, error) {
return result.Alerts.Alerts, nil
}

func waitForMetricValue(client kubecli.KubevirtClient, metric string, expectedValue int64) {
func waitForMetricValue(client kubecli.KubevirtClient, metric string, expectedValue float64) {
waitForMetricValueWithLabels(client, metric, expectedValue, nil)
}

func waitForMetricValueWithLabels(client kubecli.KubevirtClient, metric string, expectedValue int64, labels map[string]string) {
EventuallyWithOffset(1, func() int {
func waitForMetricValueWithLabels(client kubecli.KubevirtClient, metric string, expectedValue float64, labels map[string]string) {
EventuallyWithOffset(1, func() float64 {
i, err := getMetricValueWithLabels(client, metric, labels)
if err != nil {
return -1
Expand All @@ -80,7 +80,7 @@ func waitForMetricValueWithLabels(client kubecli.KubevirtClient, metric string,
}, 3*time.Minute, 1*time.Second).Should(BeNumerically("==", expectedValue))
}

func getMetricValueWithLabels(cli kubecli.KubevirtClient, query string, labels map[string]string) (int, error) {
func getMetricValueWithLabels(cli kubecli.KubevirtClient, query string, labels map[string]string) (float64, error) {
result, err := fetchMetric(cli, query)
if err != nil {
return -1, err
Expand All @@ -99,7 +99,7 @@ func getMetricValueWithLabels(cli kubecli.KubevirtClient, query string, labels m
return -1, fmt.Errorf("metric value is not string")
}

returnVal, err := strconv.Atoi(output)
returnVal, err := strconv.ParseFloat(output, 64)
if err != nil {
return -1, err
}
Expand Down
14 changes: 7 additions & 7 deletions tests/monitoring/vm_monitoring.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ var _ = Describe("[Serial][sig-monitoring]VM Monitoring", Serial, decorators.Sig
Expect(err).ToNot(HaveOccurred())
}

waitForMetricValue(virtClient, "kubevirt_number_of_vms", int64(5))
waitForMetricValue(virtClient, "kubevirt_number_of_vms", 5)
})
})

Expand All @@ -91,7 +91,7 @@ var _ = Describe("[Serial][sig-monitoring]VM Monitoring", Serial, decorators.Sig
})

checkMetricTo := func(metric string, labels map[string]string, matcher types.GomegaMatcher, description string) {
EventuallyWithOffset(1, func() int {
EventuallyWithOffset(1, func() float64 {
i, err := getMetricValueWithLabels(virtClient, metric, labels)
if err != nil {
return -1
Expand Down Expand Up @@ -230,14 +230,14 @@ var _ = Describe("[Serial][sig-monitoring]VM Monitoring", Serial, decorators.Sig
It("[test_id:8639]Number of disks restored and total restored bytes metric values should be correct", func() {
totalMetric := fmt.Sprintf("kubevirt_vmsnapshot_disks_restored_from_source_total{vm_name='simple-vm',vm_namespace='%s'}", util.NamespaceTestDefault)
bytesMetric := fmt.Sprintf("kubevirt_vmsnapshot_disks_restored_from_source_bytes{vm_name='simple-vm',vm_namespace='%s'}", util.NamespaceTestDefault)
numPVCs := 2
numPVCs := 2.0

for i := 1; i < numPVCs+1; i++ {
for i := 1.0; i < numPVCs+1; i++ {
// Create dummy PVC that is labelled as "restored" from VM snapshot
createSimplePVCWithRestoreLabels(fmt.Sprintf("vmsnapshot-restored-pvc-%d", i))
createSimplePVCWithRestoreLabels(fmt.Sprintf("vmsnapshot-restored-pvc-%f", i))
// Metric values increases per restored disk
waitForMetricValue(virtClient, totalMetric, int64(i))
waitForMetricValue(virtClient, bytesMetric, quantity.Value()*int64(i))
waitForMetricValue(virtClient, totalMetric, i)
waitForMetricValue(virtClient, bytesMetric, float64(quantity.Value())*i)
}
})
})
Expand Down

0 comments on commit 014a6db

Please sign in to comment.