Skip to content

Commit c9018ef

Browse files
🐛 (go/v4): Fix e2e test to validate that metrics are exported without asserting a controller-specific metric (#5100)
Fix e2e test to validate that metrics are exported without asserting a controller-specific metric
1 parent 36e1538 commit c9018ef

File tree

7 files changed

+77
-70
lines changed

7 files changed

+77
-70
lines changed

docs/book/src/cronjob-tutorial/testdata/project/test/e2e/e2e_test.go

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -259,10 +259,13 @@ var _ = Describe("Manager", Ordered, func() {
259259
Eventually(verifyCurlUp, 5*time.Minute).Should(Succeed())
260260

261261
By("getting the metrics by checking curl-metrics logs")
262-
metricsOutput := getMetricsOutput()
263-
Expect(metricsOutput).To(ContainSubstring(
264-
"controller_runtime_reconcile_total",
265-
))
262+
verifyMetricsAvailable := func(g Gomega) {
263+
metricsOutput, err := getMetricsOutput()
264+
g.Expect(err).NotTo(HaveOccurred(), "Failed to retrieve logs from curl pod")
265+
g.Expect(metricsOutput).NotTo(BeEmpty())
266+
g.Expect(metricsOutput).To(ContainSubstring("< HTTP/1.1 200 OK"))
267+
}
268+
Eventually(verifyMetricsAvailable, 2*time.Minute).Should(Succeed())
266269
})
267270

268271
It("should provisioned cert-manager", func() {
@@ -308,7 +311,8 @@ var _ = Describe("Manager", Ordered, func() {
308311
// TODO: Customize the e2e test suite with scenarios specific to your project.
309312
// Consider applying sample/CR(s) and check their status and/or verifying
310313
// the reconciliation by using the metrics, i.e.:
311-
// metricsOutput := getMetricsOutput()
314+
// metricsOutput, err := getMetricsOutput()
315+
// Expect(err).NotTo(HaveOccurred(), "Failed to retrieve logs from curl pod")
312316
// Expect(metricsOutput).To(ContainSubstring(
313317
// fmt.Sprintf(`controller_runtime_reconcile_total{controller="%s",result="success"} 1`,
314318
// strings.ToLower(<Kind>),
@@ -358,13 +362,10 @@ func serviceAccountToken() (string, error) {
358362
}
359363

360364
// getMetricsOutput retrieves and returns the logs from the curl pod used to access the metrics endpoint.
361-
func getMetricsOutput() string {
365+
func getMetricsOutput() (string, error) {
362366
By("getting the curl-metrics logs")
363367
cmd := exec.Command("kubectl", "logs", "curl-metrics", "-n", namespace)
364-
metricsOutput, err := utils.Run(cmd)
365-
Expect(err).NotTo(HaveOccurred(), "Failed to retrieve logs from curl pod")
366-
Expect(metricsOutput).To(ContainSubstring("< HTTP/1.1 200 OK"))
367-
return metricsOutput
368+
return utils.Run(cmd)
368369
}
369370

370371
// tokenRequest is a simplified representation of the Kubernetes TokenRequest API response,

docs/book/src/getting-started/testdata/project/test/e2e/e2e_test.go

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -254,18 +254,22 @@ var _ = Describe("Manager", Ordered, func() {
254254
Eventually(verifyCurlUp, 5*time.Minute).Should(Succeed())
255255

256256
By("getting the metrics by checking curl-metrics logs")
257-
metricsOutput := getMetricsOutput()
258-
Expect(metricsOutput).To(ContainSubstring(
259-
"controller_runtime_reconcile_total",
260-
))
257+
verifyMetricsAvailable := func(g Gomega) {
258+
metricsOutput, err := getMetricsOutput()
259+
g.Expect(err).NotTo(HaveOccurred(), "Failed to retrieve logs from curl pod")
260+
g.Expect(metricsOutput).NotTo(BeEmpty())
261+
g.Expect(metricsOutput).To(ContainSubstring("< HTTP/1.1 200 OK"))
262+
}
263+
Eventually(verifyMetricsAvailable, 2*time.Minute).Should(Succeed())
261264
})
262265

263266
// +kubebuilder:scaffold:e2e-webhooks-checks
264267

265268
// TODO: Customize the e2e test suite with scenarios specific to your project.
266269
// Consider applying sample/CR(s) and check their status and/or verifying
267270
// the reconciliation by using the metrics, i.e.:
268-
// metricsOutput := getMetricsOutput()
271+
// metricsOutput, err := getMetricsOutput()
272+
// Expect(err).NotTo(HaveOccurred(), "Failed to retrieve logs from curl pod")
269273
// Expect(metricsOutput).To(ContainSubstring(
270274
// fmt.Sprintf(`controller_runtime_reconcile_total{controller="%s",result="success"} 1`,
271275
// strings.ToLower(<Kind>),
@@ -315,13 +319,10 @@ func serviceAccountToken() (string, error) {
315319
}
316320

317321
// getMetricsOutput retrieves and returns the logs from the curl pod used to access the metrics endpoint.
318-
func getMetricsOutput() string {
322+
func getMetricsOutput() (string, error) {
319323
By("getting the curl-metrics logs")
320324
cmd := exec.Command("kubectl", "logs", "curl-metrics", "-n", namespace)
321-
metricsOutput, err := utils.Run(cmd)
322-
Expect(err).NotTo(HaveOccurred(), "Failed to retrieve logs from curl pod")
323-
Expect(metricsOutput).To(ContainSubstring("< HTTP/1.1 200 OK"))
324-
return metricsOutput
325+
return utils.Run(cmd)
325326
}
326327

327328
// tokenRequest is a simplified representation of the Kubernetes TokenRequest API response,

docs/book/src/multiversion-tutorial/testdata/project/test/e2e/e2e_test.go

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -259,10 +259,13 @@ var _ = Describe("Manager", Ordered, func() {
259259
Eventually(verifyCurlUp, 5*time.Minute).Should(Succeed())
260260

261261
By("getting the metrics by checking curl-metrics logs")
262-
metricsOutput := getMetricsOutput()
263-
Expect(metricsOutput).To(ContainSubstring(
264-
"controller_runtime_reconcile_total",
265-
))
262+
verifyMetricsAvailable := func(g Gomega) {
263+
metricsOutput, err := getMetricsOutput()
264+
g.Expect(err).NotTo(HaveOccurred(), "Failed to retrieve logs from curl pod")
265+
g.Expect(metricsOutput).NotTo(BeEmpty())
266+
g.Expect(metricsOutput).To(ContainSubstring("< HTTP/1.1 200 OK"))
267+
}
268+
Eventually(verifyMetricsAvailable, 2*time.Minute).Should(Succeed())
266269
})
267270

268271
It("should provisioned cert-manager", func() {
@@ -322,7 +325,8 @@ var _ = Describe("Manager", Ordered, func() {
322325
// TODO: Customize the e2e test suite with scenarios specific to your project.
323326
// Consider applying sample/CR(s) and check their status and/or verifying
324327
// the reconciliation by using the metrics, i.e.:
325-
// metricsOutput := getMetricsOutput()
328+
// metricsOutput, err := getMetricsOutput()
329+
// Expect(err).NotTo(HaveOccurred(), "Failed to retrieve logs from curl pod")
326330
// Expect(metricsOutput).To(ContainSubstring(
327331
// fmt.Sprintf(`controller_runtime_reconcile_total{controller="%s",result="success"} 1`,
328332
// strings.ToLower(<Kind>),
@@ -372,13 +376,10 @@ func serviceAccountToken() (string, error) {
372376
}
373377

374378
// getMetricsOutput retrieves and returns the logs from the curl pod used to access the metrics endpoint.
375-
func getMetricsOutput() string {
379+
func getMetricsOutput() (string, error) {
376380
By("getting the curl-metrics logs")
377381
cmd := exec.Command("kubectl", "logs", "curl-metrics", "-n", namespace)
378-
metricsOutput, err := utils.Run(cmd)
379-
Expect(err).NotTo(HaveOccurred(), "Failed to retrieve logs from curl pod")
380-
Expect(metricsOutput).To(ContainSubstring("< HTTP/1.1 200 OK"))
381-
return metricsOutput
382+
return utils.Run(cmd)
382383
}
383384

384385
// tokenRequest is a simplified representation of the Kubernetes TokenRequest API response,

pkg/plugins/golang/v4/scaffolds/internal/templates/test/e2e/test.go

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -437,18 +437,22 @@ var _ = Describe("Manager", Ordered, func() {
437437
Eventually(verifyCurlUp, 5 * time.Minute).Should(Succeed())
438438
439439
By("getting the metrics by checking curl-metrics logs")
440-
metricsOutput := getMetricsOutput()
441-
Expect(metricsOutput).To(ContainSubstring(
442-
"controller_runtime_reconcile_total",
443-
))
440+
verifyMetricsAvailable := func(g Gomega) {
441+
metricsOutput, err := getMetricsOutput()
442+
g.Expect(err).NotTo(HaveOccurred(), "Failed to retrieve logs from curl pod")
443+
g.Expect(metricsOutput).NotTo(BeEmpty())
444+
g.Expect(metricsOutput).To(ContainSubstring("< HTTP/1.1 200 OK"))
445+
}
446+
Eventually(verifyMetricsAvailable, 2*time.Minute).Should(Succeed())
444447
})
445448
446449
// +kubebuilder:scaffold:e2e-webhooks-checks
447450
448451
// TODO: Customize the e2e test suite with scenarios specific to your project.
449452
// Consider applying sample/CR(s) and check their status and/or verifying
450453
// the reconciliation by using the metrics, i.e.:
451-
// metricsOutput := getMetricsOutput()
454+
// metricsOutput, err := getMetricsOutput()
455+
// Expect(err).NotTo(HaveOccurred(), "Failed to retrieve logs from curl pod")
452456
// Expect(metricsOutput).To(ContainSubstring(
453457
// fmt.Sprintf(` + "`controller_runtime_reconcile_total{controller=\"%s\",result=\"success\"} 1`" + `,
454458
// strings.ToLower(<Kind>),
@@ -498,13 +502,10 @@ func serviceAccountToken() (string, error) {
498502
}
499503
500504
// getMetricsOutput retrieves and returns the logs from the curl pod used to access the metrics endpoint.
501-
func getMetricsOutput() string {
505+
func getMetricsOutput() (string, error) {
502506
By("getting the curl-metrics logs")
503507
cmd := exec.Command("kubectl", "logs", "curl-metrics", "-n", namespace)
504-
metricsOutput, err := utils.Run(cmd)
505-
Expect(err).NotTo(HaveOccurred(), "Failed to retrieve logs from curl pod")
506-
Expect(metricsOutput).To(ContainSubstring("< HTTP/1.1 200 OK"))
507-
return metricsOutput
508+
return utils.Run(cmd)
508509
}
509510
510511
// tokenRequest is a simplified representation of the Kubernetes TokenRequest API response,

testdata/project-v4-multigroup/test/e2e/e2e_test.go

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -254,10 +254,13 @@ var _ = Describe("Manager", Ordered, func() {
254254
Eventually(verifyCurlUp, 5*time.Minute).Should(Succeed())
255255

256256
By("getting the metrics by checking curl-metrics logs")
257-
metricsOutput := getMetricsOutput()
258-
Expect(metricsOutput).To(ContainSubstring(
259-
"controller_runtime_reconcile_total",
260-
))
257+
verifyMetricsAvailable := func(g Gomega) {
258+
metricsOutput, err := getMetricsOutput()
259+
g.Expect(err).NotTo(HaveOccurred(), "Failed to retrieve logs from curl pod")
260+
g.Expect(metricsOutput).NotTo(BeEmpty())
261+
g.Expect(metricsOutput).To(ContainSubstring("< HTTP/1.1 200 OK"))
262+
}
263+
Eventually(verifyMetricsAvailable, 2*time.Minute).Should(Succeed())
261264
})
262265

263266
It("should provisioned cert-manager", func() {
@@ -317,7 +320,8 @@ var _ = Describe("Manager", Ordered, func() {
317320
// TODO: Customize the e2e test suite with scenarios specific to your project.
318321
// Consider applying sample/CR(s) and check their status and/or verifying
319322
// the reconciliation by using the metrics, i.e.:
320-
// metricsOutput := getMetricsOutput()
323+
// metricsOutput, err := getMetricsOutput()
324+
// Expect(err).NotTo(HaveOccurred(), "Failed to retrieve logs from curl pod")
321325
// Expect(metricsOutput).To(ContainSubstring(
322326
// fmt.Sprintf(`controller_runtime_reconcile_total{controller="%s",result="success"} 1`,
323327
// strings.ToLower(<Kind>),
@@ -367,13 +371,10 @@ func serviceAccountToken() (string, error) {
367371
}
368372

369373
// getMetricsOutput retrieves and returns the logs from the curl pod used to access the metrics endpoint.
370-
func getMetricsOutput() string {
374+
func getMetricsOutput() (string, error) {
371375
By("getting the curl-metrics logs")
372376
cmd := exec.Command("kubectl", "logs", "curl-metrics", "-n", namespace)
373-
metricsOutput, err := utils.Run(cmd)
374-
Expect(err).NotTo(HaveOccurred(), "Failed to retrieve logs from curl pod")
375-
Expect(metricsOutput).To(ContainSubstring("< HTTP/1.1 200 OK"))
376-
return metricsOutput
377+
return utils.Run(cmd)
377378
}
378379

379380
// tokenRequest is a simplified representation of the Kubernetes TokenRequest API response,

testdata/project-v4-with-plugins/test/e2e/e2e_test.go

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -254,10 +254,13 @@ var _ = Describe("Manager", Ordered, func() {
254254
Eventually(verifyCurlUp, 5*time.Minute).Should(Succeed())
255255

256256
By("getting the metrics by checking curl-metrics logs")
257-
metricsOutput := getMetricsOutput()
258-
Expect(metricsOutput).To(ContainSubstring(
259-
"controller_runtime_reconcile_total",
260-
))
257+
verifyMetricsAvailable := func(g Gomega) {
258+
metricsOutput, err := getMetricsOutput()
259+
g.Expect(err).NotTo(HaveOccurred(), "Failed to retrieve logs from curl pod")
260+
g.Expect(metricsOutput).NotTo(BeEmpty())
261+
g.Expect(metricsOutput).To(ContainSubstring("< HTTP/1.1 200 OK"))
262+
}
263+
Eventually(verifyMetricsAvailable, 2*time.Minute).Should(Succeed())
261264
})
262265

263266
It("should provisioned cert-manager", func() {
@@ -303,7 +306,8 @@ var _ = Describe("Manager", Ordered, func() {
303306
// TODO: Customize the e2e test suite with scenarios specific to your project.
304307
// Consider applying sample/CR(s) and check their status and/or verifying
305308
// the reconciliation by using the metrics, i.e.:
306-
// metricsOutput := getMetricsOutput()
309+
// metricsOutput, err := getMetricsOutput()
310+
// Expect(err).NotTo(HaveOccurred(), "Failed to retrieve logs from curl pod")
307311
// Expect(metricsOutput).To(ContainSubstring(
308312
// fmt.Sprintf(`controller_runtime_reconcile_total{controller="%s",result="success"} 1`,
309313
// strings.ToLower(<Kind>),
@@ -353,13 +357,10 @@ func serviceAccountToken() (string, error) {
353357
}
354358

355359
// getMetricsOutput retrieves and returns the logs from the curl pod used to access the metrics endpoint.
356-
func getMetricsOutput() string {
360+
func getMetricsOutput() (string, error) {
357361
By("getting the curl-metrics logs")
358362
cmd := exec.Command("kubectl", "logs", "curl-metrics", "-n", namespace)
359-
metricsOutput, err := utils.Run(cmd)
360-
Expect(err).NotTo(HaveOccurred(), "Failed to retrieve logs from curl pod")
361-
Expect(metricsOutput).To(ContainSubstring("< HTTP/1.1 200 OK"))
362-
return metricsOutput
363+
return utils.Run(cmd)
363364
}
364365

365366
// tokenRequest is a simplified representation of the Kubernetes TokenRequest API response,

testdata/project-v4/test/e2e/e2e_test.go

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -254,10 +254,13 @@ var _ = Describe("Manager", Ordered, func() {
254254
Eventually(verifyCurlUp, 5*time.Minute).Should(Succeed())
255255

256256
By("getting the metrics by checking curl-metrics logs")
257-
metricsOutput := getMetricsOutput()
258-
Expect(metricsOutput).To(ContainSubstring(
259-
"controller_runtime_reconcile_total",
260-
))
257+
verifyMetricsAvailable := func(g Gomega) {
258+
metricsOutput, err := getMetricsOutput()
259+
g.Expect(err).NotTo(HaveOccurred(), "Failed to retrieve logs from curl pod")
260+
g.Expect(metricsOutput).NotTo(BeEmpty())
261+
g.Expect(metricsOutput).To(ContainSubstring("< HTTP/1.1 200 OK"))
262+
}
263+
Eventually(verifyMetricsAvailable, 2*time.Minute).Should(Succeed())
261264
})
262265

263266
It("should provisioned cert-manager", func() {
@@ -317,7 +320,8 @@ var _ = Describe("Manager", Ordered, func() {
317320
// TODO: Customize the e2e test suite with scenarios specific to your project.
318321
// Consider applying sample/CR(s) and check their status and/or verifying
319322
// the reconciliation by using the metrics, i.e.:
320-
// metricsOutput := getMetricsOutput()
323+
// metricsOutput, err := getMetricsOutput()
324+
// Expect(err).NotTo(HaveOccurred(), "Failed to retrieve logs from curl pod")
321325
// Expect(metricsOutput).To(ContainSubstring(
322326
// fmt.Sprintf(`controller_runtime_reconcile_total{controller="%s",result="success"} 1`,
323327
// strings.ToLower(<Kind>),
@@ -367,13 +371,10 @@ func serviceAccountToken() (string, error) {
367371
}
368372

369373
// getMetricsOutput retrieves and returns the logs from the curl pod used to access the metrics endpoint.
370-
func getMetricsOutput() string {
374+
func getMetricsOutput() (string, error) {
371375
By("getting the curl-metrics logs")
372376
cmd := exec.Command("kubectl", "logs", "curl-metrics", "-n", namespace)
373-
metricsOutput, err := utils.Run(cmd)
374-
Expect(err).NotTo(HaveOccurred(), "Failed to retrieve logs from curl pod")
375-
Expect(metricsOutput).To(ContainSubstring("< HTTP/1.1 200 OK"))
376-
return metricsOutput
377+
return utils.Run(cmd)
377378
}
378379

379380
// tokenRequest is a simplified representation of the Kubernetes TokenRequest API response,

0 commit comments

Comments
 (0)