Metrics: Add --metrics-per-undefined-host argument. (#11818)
Signed-off-by: Jon Carl <grounded042@joncarl.com>
This commit is contained in:
parent
93f9f9fbb3
commit
034c3ccad4
11 changed files with 172 additions and 28 deletions
|
|
@ -36,6 +36,7 @@ const waitForMetrics = 2 * time.Second
|
|||
var _ = framework.IngressNginxDescribe("[metrics] exported prometheus metrics", func() {
|
||||
f := framework.NewDefaultFramework("metrics")
|
||||
host := "foo.com"
|
||||
wildcardHost := "wildcard." + host
|
||||
|
||||
ginkgo.BeforeEach(func() {
|
||||
f.NewEchoDeployment()
|
||||
|
|
@ -91,4 +92,50 @@ var _ = framework.IngressNginxDescribe("[metrics] exported prometheus metrics",
|
|||
assert.Nil(ginkgo.GinkgoT(), err)
|
||||
assert.NotNil(ginkgo.GinkgoT(), mf)
|
||||
})
|
||||
ginkgo.It("request metrics per undefined host are present when flag is set", func() {
|
||||
err := f.UpdateIngressControllerDeployment(func(deployment *appsv1.Deployment) error {
|
||||
args := deployment.Spec.Template.Spec.Containers[0].Args
|
||||
args = append(args, "--metrics-per-undefined-host=true")
|
||||
deployment.Spec.Template.Spec.Containers[0].Args = args
|
||||
_, err := f.KubeClientSet.AppsV1().Deployments(f.Namespace).Update(context.TODO(), deployment, metav1.UpdateOptions{})
|
||||
return err
|
||||
})
|
||||
assert.Nil(ginkgo.GinkgoT(), err, "updating deployment")
|
||||
|
||||
f.HTTPTestClient().
|
||||
GET("/").
|
||||
WithHeader("Host", wildcardHost).
|
||||
Expect().
|
||||
Status(http.StatusNotFound)
|
||||
time.Sleep(waitForMetrics)
|
||||
|
||||
ip := f.GetNginxPodIP()
|
||||
reqMetrics, err := f.GetMetric("nginx_ingress_controller_requests", ip)
|
||||
assert.Nil(ginkgo.GinkgoT(), err)
|
||||
assert.NotNil(ginkgo.GinkgoT(), reqMetrics.Metric)
|
||||
assert.Len(ginkgo.GinkgoT(), reqMetrics.Metric, 1)
|
||||
|
||||
containedLabel := false
|
||||
for _, label := range reqMetrics.Metric[0].Label {
|
||||
if *label.Name == "host" && *label.Value == wildcardHost {
|
||||
containedLabel = true
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
assert.Truef(ginkgo.GinkgoT(), containedLabel, "expected reqMetrics to contain label with \"name\"=\"host\" \"value\"=%q, but it did not: %s", wildcardHost, reqMetrics.String())
|
||||
})
|
||||
ginkgo.It("request metrics per undefined host are not present when flag is not set", func() {
|
||||
f.HTTPTestClient().
|
||||
GET("/").
|
||||
WithHeader("Host", wildcardHost).
|
||||
Expect().
|
||||
Status(http.StatusNotFound)
|
||||
time.Sleep(waitForMetrics)
|
||||
|
||||
ip := f.GetNginxPodIP()
|
||||
reqMetrics, err := f.GetMetric("nginx_ingress_controller_requests", ip)
|
||||
assert.EqualError(ginkgo.GinkgoT(), err, "there is no metric with name nginx_ingress_controller_requests")
|
||||
assert.Nil(ginkgo.GinkgoT(), reqMetrics)
|
||||
})
|
||||
})
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue