Skip to content

Commit

Permalink
e2e: add tests to verify metrics endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
camilamacedo86 committed Dec 13, 2024
1 parent e461013 commit 56b63ee
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions test/e2e/metrics_endpoint_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package e2e

import (
"bytes"
"os/exec"

. "github.com/onsi/ginkgo/v2"
. "github.com/onsi/gomega"
)

var _ = Describe("Catalogd Metrics Workflow Validation", func() {

var (
token string
namespace = "olmv1-system"
)

BeforeEach(func() {
By("Creating ClusterRoleBinding for catalogd metrics")
_, err := exec.Command("kubectl", "create", "clusterrolebinding", "catalogd-metrics-binding",
"--clusterrole=catalogd-metrics-reader",
"--serviceaccount="+namespace+":catalogd-controller-manager").CombinedOutput()
Expect(err).ToNot(HaveOccurred())

By("Generating a token for the catalogd-controller-manager ServiceAccount")
out, err := exec.Command("kubectl", "create", "token", "catalogd-controller-manager", "-n", namespace).Output()
Expect(err).ToNot(HaveOccurred())
token = string(bytes.TrimSpace(out))
})

It("Validates the metrics endpoint", func() {
By("Calling the metrics endpoint directly using kubectl exec")
metricsURL := "https://catalogd-service.olmv1-system.svc.cluster.local:7443/metrics"
curlCmd := []string{
"run", "--rm", "-it", "--restart=Never", "--image=curlimages/curl:7.87.0",
"--serviceaccount=catalogd-controller-manager", "curl-test",
"--", "curl", "-v", "-k", "-H", "Authorization: Bearer " + token, metricsURL,
}
cmd := exec.Command("kubectl", curlCmd...)
output, err := cmd.CombinedOutput()
Expect(err).ToNot(HaveOccurred())
Expect(string(output)).To(ContainSubstring("200"))
Expect(string(output)).To(ContainSubstring("# HELP"))
})

AfterEach(func() {
By("Cleaning up resources")
_ = exec.Command("kubectl", "delete", "clusterrolebinding", "catalogd-metrics-binding", "--ignore-not-found=true").Run()
})
})

0 comments on commit 56b63ee

Please sign in to comment.