Skip to content

Commit

Permalink
[OSSM-8136] Add Kiali version into kiali cr + improve stability of Te…
Browse files Browse the repository at this point in the history
…stOpenShiftMonitoring test (#740)
  • Loading branch information
mkralik3 authored Sep 23, 2024
1 parent a456227 commit e5c249a
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 3 deletions.
40 changes: 37 additions & 3 deletions pkg/tests/tasks/observability/openshift_monitoring_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ func TestOpenShiftMonitoring(t *testing.T) {
kialiValues := map[string]string{
"SmcpName": smcpName,
"SmcpNamespace": meshNamespace,
"KialiVersion": env.GetKialiVersion(),
}

t.Cleanup(func() {
Expand Down Expand Up @@ -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")
Expand All @@ -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)
})

Expand All @@ -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")
Expand Down Expand Up @@ -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)
})
})
Expand Down Expand Up @@ -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)
Expand All @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
15 changes: 15 additions & 0 deletions pkg/util/env/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}

0 comments on commit e5c249a

Please sign in to comment.