Skip to content

Commit f480cf4

Browse files
committed
Added testing of custom metrics to e2e test deploy_app.
1 parent cee3cb1 commit f480cf4

File tree

3 files changed

+41
-0
lines changed

3 files changed

+41
-0
lines changed

test/e2e/common.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,37 @@ func DownloadFromAppInWorkloadCluster(ctx context.Context, workloadKubeconfigPat
192192
return KubectlExec(ctx, "run", workloadKubeconfigPath, runArgs...)
193193
}
194194

195+
func DownloadMetricsFromCAPCManager(ctx context.Context, bootstrapKubeconfigPath string) (string, error) {
196+
// Expose the CAPC manager metrics port via a K8S service
197+
runArgs := []string{
198+
"--port=8080", "--target-port=metrics", "--name=capc-controller-manager-metrics", "--namespace=capc-system", "deployment", "capc-controller-manager",
199+
}
200+
_, err := KubectlExec(ctx, "expose", bootstrapKubeconfigPath, runArgs...)
201+
if err != nil {
202+
fmt.Println(err)
203+
return "", err
204+
}
205+
206+
// Scrape the metrics from the service
207+
runArgs = []string{
208+
"-i", "--restart=Never", "dummy", "--image=dockerqa/curl:ubuntu-trusty", "--command", "--", "curl", "--silent", "capc-controller-manager-metrics.capc-system:8080/metrics",
209+
}
210+
result, err := KubectlExec(ctx, "run", bootstrapKubeconfigPath, runArgs...)
211+
if err != nil {
212+
return result, err
213+
}
214+
215+
// Remove the metrics service
216+
runArgs = []string{
217+
"--namespace=capc-system", "service", "capc-controller-manager-metrics",
218+
}
219+
_, err = KubectlExec(ctx, "delete", bootstrapKubeconfigPath, runArgs...)
220+
if err != nil {
221+
return "", err
222+
}
223+
return result, err
224+
}
225+
195226
type cloudConfig struct {
196227
APIURL string `ini:"api-url"`
197228
APIKey string `ini:"api-key"`

test/e2e/config/cloudstack.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,8 @@ providers:
101101
replacements:
102102
- old: --metrics-bind-addr=localhost:8080
103103
new: --metrics-bind-addr=:8080
104+
- old: "--leader-elect"
105+
new: "--leader-elect\n - --metrics-bind-addr=:8080"
104106

105107
variables:
106108
KUBERNETES_VERSION_MANAGEMENT: "v1.20.10"

test/e2e/deploy_app.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,14 @@ func DeployAppSpec(ctx context.Context, inputGetter func() CommonSpecInput) {
110110

111111
Expect(actualHtml).To(Equal(expectedHtml))
112112

113+
By("Confirming that the custom reconciliation error metric is scrape-able")
114+
// BIG NOTE: The first reconciliation attempt of isolated_network!AssociatePublicIPAddress() returns
115+
// a CloudStack error 9999. This test expects that to happen.
116+
// No acs_reconciliation_errors appear in the scrape until logged.
117+
// If that error ever gets fixed, this test will break.
118+
metricsScrape, err := DownloadMetricsFromCAPCManager(ctx, input.BootstrapClusterProxy.GetKubeconfigPath())
119+
Expect(err).To(BeNil())
120+
Expect(metricsScrape).To(MatchRegexp("acs_reconciliation_errors\\{acs_error_code=\"9999\"\\} [0-9]+"))
113121
By("PASSED!")
114122
})
115123

0 commit comments

Comments
 (0)