Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: Enable Prometheus metrics in K8sHubbleTest #11508

Merged
merged 1 commit into from May 15, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
26 changes: 22 additions & 4 deletions test/k8sT/hubble.go
Expand Up @@ -17,6 +17,7 @@ package k8sTest
import (
"context"
"fmt"
"net"
"strings"

"github.com/cilium/cilium/pkg/annotation"
Expand All @@ -39,9 +40,10 @@ var _ = Describe("K8sHubbleTest", func() {

demoPath string

app1Service = "app1-service"
app1Labels = "id=app1,zgroup=testapp"
apps = []string{helpers.App1, helpers.App2, helpers.App3}
app1Service = "app1-service"
app1Labels = "id=app1,zgroup=testapp"
apps = []string{helpers.App1, helpers.App2, helpers.App3}
prometheusPort = "9091"
)

addVisibilityAnnotation := func(ns, podLabels, direction, port, l4proto, l7proto string) {
Expand Down Expand Up @@ -84,7 +86,9 @@ var _ = Describe("K8sHubbleTest", func() {
demoPath = helpers.ManifestGet(kubectl.BasePath(), "demo.yaml")

DeployCiliumOptionsAndDNS(kubectl, ciliumFilename, map[string]string{
"global.hubble.cli.enabled": "true",
"global.hubble.cli.enabled": "true",
"global.hubble.metricsServer": fmt.Sprintf(":%s", prometheusPort),
"global.hubble.metrics.enabled": `"{dns:query;ignoreAAAA,drop,tcp,flow,port-distribution,icmp,http}"`,
})

err := kubectl.WaitforPods(hubbleNamespace, hubbleSelector, helpers.HelperTimeout)
Expand Down Expand Up @@ -156,6 +160,13 @@ var _ = Describe("K8sHubbleTest", func() {

err := follow.WaitUntilMatchFilterLineTimeout(`{$.Type}`, "L3_L4", helpers.ShortCommandTimeout)
Expect(err).To(BeNil(), fmt.Sprintf("hubble observe query timed out on %q", follow.OutputPrettyPrint()))

// Basic check for L4 Prometheus metrics.
_, nodeIP := kubectl.GetNodeInfo(helpers.K8s1)
metricsUrl := fmt.Sprintf("%s/metrics", net.JoinHostPort(nodeIP, prometheusPort))
res = kubectl.ExecPodCmd(hubbleNamespace, hubblePodK8s1, helpers.CurlFail(metricsUrl))
res.ExpectSuccess("%s/%s cannot curl metrics %q", hubblePodK8s1, hubblePodK8s1, app1ClusterIP)
res.ExpectContains(`hubble_flows_processed_total{subtype="to-endpoint",type="Trace",verdict="FORWARDED"}`)
})

It("Test L7 Flow", func() {
Expand All @@ -174,6 +185,13 @@ var _ = Describe("K8sHubbleTest", func() {

err := follow.WaitUntilMatchFilterLineTimeout(`{$.Type}`, "L7", helpers.ShortCommandTimeout)
Expect(err).To(BeNil(), fmt.Sprintf("hubble observe query timed out on %q", follow.OutputPrettyPrint()))

// Basic check for L7 Prometheus metrics.
_, nodeIP := kubectl.GetNodeInfo(helpers.K8s1)
metricsUrl := fmt.Sprintf("%s/metrics", net.JoinHostPort(nodeIP, prometheusPort))
res = kubectl.ExecPodCmd(hubbleNamespace, hubblePodK8s1, helpers.CurlFail(metricsUrl))
res.ExpectSuccess("%s/%s cannot curl metrics %q", hubbleNamespace, hubblePodK8s1, app1ClusterIP)
res.ExpectContains(`hubble_flows_processed_total{subtype="HTTP",type="L7",verdict="FORWARDED"}`)
})
})
})