Skip to content

Commit

Permalink
Fix the monitoring test
Browse files Browse the repository at this point in the history
The "KubeVirtCRModified alert should fired when there is a modification
on a CR" functional test became flacky.

The test changes the KubeVirt CI, and then checks several metrics and
alert. When checking the "kubevirt_hyperconverged_operator_health_status"
alert, the test sometimes fails, as KubeVirt get into non stable state
for a short while for every chenage in the KubeVirt CR, making the
health alret to be in "critical" status, instead of "warning".

This PR fixes the issue by modifiying the CDI CR instead of the KubeVirt
CR, to get the same effect.

Signed-off-by: Nahshon Unna-Tsameret <[email protected]>
  • Loading branch information
nunnatsa committed Dec 22, 2024
1 parent d70d3c3 commit c6c35a8
Showing 1 changed file with 7 additions and 9 deletions.
16 changes: 7 additions & 9 deletions tests/func-tests/monitoring_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"crypto/tls"
"flag"
"fmt"
cdiv1beta1 "kubevirt.io/containerized-data-importer-api/pkg/apis/core/v1beta1"
"net/http"
"strconv"
"time"
Expand All @@ -29,8 +30,6 @@ import (
"k8s.io/client-go/rest"
"sigs.k8s.io/controller-runtime/pkg/client"

kubevirtcorev1 "kubevirt.io/api/core/v1"

hcoalerts "github.com/kubevirt/hyperconverged-cluster-operator/pkg/monitoring/rules/alerts"
"github.com/kubevirt/hyperconverged-cluster-operator/pkg/monitoring/rules/recordingrules"
hcoutil "github.com/kubevirt/hyperconverged-cluster-operator/pkg/util"
Expand Down Expand Up @@ -107,8 +106,8 @@ var _ = Describe("[crit:high][vendor:[email protected]][level:system]Monitoring"
It("KubeVirtCRModified alert should fired when there is a modification on a CR", Serial, func(ctx context.Context) {

const (
query = `kubevirt_hco_out_of_band_modifications_total{component_name="kubevirt/kubevirt-kubevirt-hyperconverged"}`
jsonPatch = `[{"op": "add", "path": "/spec/configuration/developerConfiguration/featureGates/-", "value": "fake-fg-for-testing"}]`
query = `kubevirt_hco_out_of_band_modifications_total{component_name="cdi/cdi-kubevirt-hyperconverged"}`
jsonPatch = `[{"op": "add", "path": "/spec/config/logVerbosity", "value": 5}]`
)

By(fmt.Sprintf("Reading the `%s` metric from HCO prometheus endpoint", query))
Expand All @@ -120,17 +119,16 @@ var _ = Describe("[crit:high][vendor:[email protected]][level:system]Monitoring"
}).WithTimeout(10 * time.Second).WithPolling(500 * time.Millisecond).WithContext(ctx).Should(Succeed())
GinkgoWriter.Printf("The metric value before the test is: %0.2f\n", valueBefore)

By("Patching kubevirt object")
By("Patching the CDI object")
patch := client.RawPatch(types.JSONPatchType, []byte(jsonPatch))

kv := &kubevirtcorev1.KubeVirt{
cdi := &cdiv1beta1.CDI{
ObjectMeta: metav1.ObjectMeta{
Name: "kubevirt-kubevirt-hyperconverged",
Namespace: tests.InstallNamespace,
Name: "cdi-kubevirt-hyperconverged",
},
}

Expect(cli.Patch(ctx, kv, patch)).To(Succeed())
Expect(cli.Patch(ctx, cdi, patch)).To(Succeed())

By("checking that the HCO metric was increased by 1")
Eventually(func(g Gomega, ctx context.Context) float64 {
Expand Down

0 comments on commit c6c35a8

Please sign in to comment.