diff --git a/pkg/tests/tasks/observability/openshift_monitoring_test.go b/pkg/tests/tasks/observability/openshift_monitoring_test.go index 066eccc7..57fbe919 100644 --- a/pkg/tests/tasks/observability/openshift_monitoring_test.go +++ b/pkg/tests/tasks/observability/openshift_monitoring_test.go @@ -60,6 +60,7 @@ func TestOpenShiftMonitoring(t *testing.T) { kialiValues := map[string]string{ "SmcpName": smcpName, "SmcpNamespace": meshNamespace, + "KialiVersion": env.GetKialiVersion(), } t.Cleanup(func() { @@ -87,6 +88,8 @@ func TestOpenShiftMonitoring(t *testing.T) { oc.DeleteFromString(t, meshNamespace, enableTrafficMetrics) app.Uninstall(t, app.Httpbin(ns.Foo)) oc.DeleteFromTemplate(t, meshNamespace, meshTmpl, meshValues) + oc.RecreateNamespace(t, ns.Foo) + oc.RecreateNamespace(t, meshNamespace) }) t.LogStep("Deploying SMCP") @@ -113,6 +116,7 @@ func TestOpenShiftMonitoring(t *testing.T) { oc.ApplyString(t, meshNamespace, istiodMonitor) oc.ApplyString(t, ns.Foo, istioProxyMonitor) + waitUntilAllPrometheusTargetReady(t, kialiToken) generateTrafficAndcheckMetrics(t, kialiToken) }) @@ -124,6 +128,8 @@ func TestOpenShiftMonitoring(t *testing.T) { app.Uninstall(t, app.Httpbin(ns.Foo)) oc.DeleteFromTemplate(t, meshNamespace, networkPolicy, map[string]string{"namespace": meshNamespace}) oc.DeleteFromTemplate(t, meshNamespace, meshTmpl, meshValues) + oc.RecreateNamespace(t, ns.Foo) + oc.RecreateNamespace(t, meshNamespace) }) t.LogStep("Deploying SMCP") @@ -155,6 +161,7 @@ func TestOpenShiftMonitoring(t *testing.T) { oc.ApplyString(t, meshNamespace, istiodMonitor) oc.ApplyString(t, ns.Foo, istioProxyMonitor) + waitUntilAllPrometheusTargetReady(t, kialiToken) generateTrafficAndcheckMetrics(t, kialiToken) }) }) @@ -193,9 +200,12 @@ func generateTrafficAndcheckMetrics(t test.TestHelper, thanosToken string) { t.LogStep("Generate some ingress traffic") oc.ApplyFile(t, ns.Foo, "https://raw.githubusercontent.com/maistra/istio/maistra-2.6/samples/httpbin/httpbin-gateway.yaml") httpbinURL := fmt.Sprintf("http://%s/headers", istio.GetIngressGatewayHost(t, meshNamespace)) - retry.UntilSuccess(t, func(t test.TestHelper) { - curl.Request(t, httpbinURL, nil, assert.ResponseStatus(http.StatusOK)) - }) + + for i := 0; i < 5; i++ { + retry.UntilSuccess(t, func(t test.TestHelper) { + curl.Request(t, httpbinURL, nil, assert.ResponseStatus(http.StatusOK)) + }) + } t.LogStep("Check istiod metrics") checkMetricExists(t, meshNamespace, "pilot_info", thanosToken) @@ -218,12 +228,36 @@ func checkMetricExists(t test.TestHelper, ns, metricName, token string) { }) } +func waitUntilAllPrometheusTargetReady(t test.TestHelper, token string) { + waitUntilPrometheusTargetReady(t, "serviceMonitor", meshNamespace, "istiod-monitor", token) + waitUntilPrometheusTargetReady(t, "podMonitor", ns.Foo, "istio-proxies-monitor", token) +} + +func waitUntilPrometheusTargetReady(t test.TestHelper, monitorType string, ns string, targetName string, token string) { + retry.UntilSuccess(t, func(t test.TestHelper) { + oc.Exec(t, + pod.MatchingSelectorFirst("app.kubernetes.io/instance=thanos-querier", monitoringNs), + "thanos-query", + prometheusActiveTargetQuery(token), + assert.OutputContains( + fmt.Sprintf(`"scrapePool":"%s/%s/%s`, monitorType, ns, targetName), + fmt.Sprintf("The %s %s prometheus target is ready in namespace %s", monitorType, targetName, ns), + fmt.Sprintf("The %s %s prometheus target is not ready yet in namespace %s", monitorType, targetName, ns)), + ) + }) +} + func prometheusQuery(ns, metricName, token string) string { return fmt.Sprintf( `curl -X GET -kG "https://localhost:9091/api/v1/query?namespace=%s&query=%s" --data-urlencode "query=up" -H "Authorization: Bearer %s"`, ns, metricName, token) } +func prometheusActiveTargetQuery(token string) string { + return fmt.Sprintf( + `curl -X GET -kG "https://localhost:9091/api/v1/targets?state=active" --data-urlencode "query=up" -H "Authorization: Bearer %s"`, token) +} + func fetchKialiToken(t test.TestHelper) string { var kialiToken string retry.UntilSuccess(t, func(t test.TestHelper) { diff --git a/pkg/tests/tasks/observability/yaml/kiali-user-workload-monitoring.tmpl.yaml b/pkg/tests/tasks/observability/yaml/kiali-user-workload-monitoring.tmpl.yaml index 325e25d6..9c8ac65d 100644 --- a/pkg/tests/tasks/observability/yaml/kiali-user-workload-monitoring.tmpl.yaml +++ b/pkg/tests/tasks/observability/yaml/kiali-user-workload-monitoring.tmpl.yaml @@ -17,6 +17,10 @@ kind: Kiali metadata: name: kiali-user-workload-monitoring spec: + version: {{ .KialiVersion }} + # needed for v1.65 (https://github.com/kiali/kiali-operator/blob/v1.89/roles/v1.65/kiali-deploy/tasks/main.yml#L578), it will be overridden by istio operator so it is not important + deployment: + accessible_namespaces: ["**"] external_services: prometheus: auth: diff --git a/pkg/util/env/env.go b/pkg/util/env/env.go index 935b7266..46212821 100644 --- a/pkg/util/env/env.go +++ b/pkg/util/env/env.go @@ -114,3 +114,18 @@ func GetOutputDir() string { func IsMetalLBInternalIPEnabled() bool { return getenv("METALLB_INTERNAL_IP_ENABLED", "false") == "true" } + +func GetKialiVersion() string { + switch GetSMCPVersion() { + case version.SMCP_2_3: + return "v1.57" + case version.SMCP_2_4: + return "v1.65" + case version.SMCP_2_5: + return "v1.73" + case version.SMCP_2_6: + return "v1.73" + default: + return "v1.73" + } +}