Skip to content

Commit 6b5d6c1

Browse files
wip
1 parent d8b2eaf commit 6b5d6c1

3 files changed

Lines changed: 62 additions & 24 deletions

File tree

test/e2e/multik8s/misc_test.go

Lines changed: 33 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,39 @@ import (
1414
"k8s.io/apimachinery/pkg/api/meta"
1515
)
1616

17+
var _ = Describe("metrics tests", func() {
18+
namespace := util.GetUniqueName("ns-")
19+
pvcName := util.GetUniqueName("pvc-")
20+
backupName := util.GetUniqueName("mb-")
21+
backupConfigName := util.GetUniqueName("mbc-")
22+
23+
It("should setup", func(ctx SpecContext) {
24+
SetupEnvironment(namespace)
25+
CreatePVC(ctx, PrimaryK8sCluster, namespace, pvcName)
26+
CreateMantleBackup(PrimaryK8sCluster, namespace, pvcName, backupName)
27+
WaitMantleBackupSynced(namespace, backupName)
28+
CreateMantleBackupConfig(PrimaryK8sCluster, namespace, pvcName, backupConfigName)
29+
})
30+
31+
DescribeTable("metrics should be exposed",
32+
func(ctx SpecContext, metricName string) {
33+
Eventually(ctx, func(g Gomega) {
34+
controllerPod, err := GetControllerPodName(PrimaryK8sCluster)
35+
g.Expect(err).NotTo(HaveOccurred())
36+
stdout, _, err := Kubectl(PrimaryK8sCluster, nil, "exec", "-n", CephClusterNamespace, controllerPod, "--",
37+
"curl", "-s", "http://localhost:8080/metrics")
38+
g.Expect(err).NotTo(HaveOccurred())
39+
g.Expect(strings.Contains(string(stdout), metricName)).To(BeTrue())
40+
}).Should(Succeed())
41+
},
42+
Entry(`mantle_backup_duration_seconds_total`, `mantle_backup_duration_seconds_total`),
43+
Entry(`mantle_mantlebackupconfig_info`, `mantle_mantlebackupconfig_info`),
44+
Entry(`mantle_backup_duration_seconds_bucket`, `mantle_backup_duration_seconds_bucket`),
45+
Entry(`mantle_backup_duration_seconds_sum`, `mantle_backup_duration_seconds_sum`),
46+
Entry(`mantle_backup_duration_seconds_count`, `mantle_backup_duration_seconds_count`),
47+
)
48+
})
49+
1750
var _ = Describe("miscellaneous tests", func() {
1851
It("should succeed to back up if backup-transfer-part-size is changed during uploading", func(ctx SpecContext) {
1952
namespace := util.GetUniqueName("ns-")
@@ -348,28 +381,4 @@ spec:
348381
0, // reset an import Job to the original one to revive the Job.
349382
),
350383
)
351-
352-
It("should get metrics from the controller pod in the primary cluster", func(ctx SpecContext) {
353-
metrics := []string{
354-
`mantle_backup_duration_seconds_total`,
355-
`mantle_mantlebackupconfig_info`,
356-
`mantle_backup_duration_seconds_buckets`,
357-
`mantle_backup_duration_seconds_sum`,
358-
`mantle_backup_duration_seconds_count`,
359-
}
360-
ensureMetricsAreExposed(metrics)
361-
})
362384
})
363-
364-
func ensureMetricsAreExposed(metrics []string) {
365-
GinkgoHelper()
366-
controllerPod, err := GetControllerPodName(PrimaryK8sCluster)
367-
Expect(err).NotTo(HaveOccurred())
368-
369-
stdout, _, err := Kubectl(PrimaryK8sCluster, nil, "exec", "-n", CephClusterNamespace, controllerPod, "--",
370-
"curl", "-s", "http://localhost:8080/metrics")
371-
Expect(err).NotTo(HaveOccurred())
372-
for _, metric := range metrics {
373-
Expect(strings.Contains(string(stdout), metric)).To(BeTrue())
374-
}
375-
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
apiVersion: mantle.cybozu.io/v1
2+
kind: MantleBackupConfig
3+
metadata:
4+
name: %s
5+
namespace: %s
6+
spec:
7+
pvc: %s
8+
expire: "1d"
9+
schedule: "00 00 * * *"
10+
suspend: false

test/e2e/multik8s/testutil/util.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ var (
4646
testRBDPoolSCTemplate string
4747
//go:embed testdata/mantlebackup-template.yaml
4848
testMantleBackupTemplate string
49+
//go:embed testdata/mantlebackupconfig-template.yaml
50+
testMantleBackupConfigTemplate string
4951
//go:embed testdata/mantlerestore-template.yaml
5052
testMantleRestoreTemplate string
5153
//go:embed testdata/mount-deploy-template.yaml
@@ -137,6 +139,15 @@ func ApplyMantleBackupTemplate(clusterNo int, namespace, pvcName, backupName str
137139
return nil
138140
}
139141

142+
func ApplyMantleBackupConfigTemplate(clusterNo int, namespace, pvcName, backupConfigName string) error {
143+
manifest := fmt.Sprintf(testMantleBackupConfigTemplate, backupConfigName, namespace, pvcName)
144+
_, _, err := Kubectl(clusterNo, []byte(manifest), "apply", "-f", "-")
145+
if err != nil {
146+
return fmt.Errorf("kubectl apply mantlebackup failed. err: %w", err)
147+
}
148+
return nil
149+
}
150+
140151
func ApplyMantleRestoreTemplate(clusterNo int, namespace, restoreName, backupName string) error {
141152
manifest := fmt.Sprintf(testMantleRestoreTemplate, restoreName, restoreName, namespace, backupName)
142153
_, _, err := Kubectl(clusterNo, []byte(manifest), "apply", "-f", "-")
@@ -487,6 +498,14 @@ func CreateMantleBackup(cluster int, namespace, pvcName, backupName string) {
487498
}).Should(Succeed())
488499
}
489500

501+
func CreateMantleBackupConfig(cluster int, namespace, pvcName, backupConfigName string) {
502+
GinkgoHelper()
503+
By("creating a MantleBackupConfig object")
504+
Eventually(func() error {
505+
return ApplyMantleBackupConfigTemplate(cluster, namespace, pvcName, backupConfigName)
506+
}).Should(Succeed())
507+
}
508+
490509
func WaitMantleBackupReadyToUse(cluster int, namespace, backupName string) {
491510
GinkgoHelper()
492511
By("checking MantleBackup's ReadyToUse status")

0 commit comments

Comments
 (0)