Skip to content

Commit b8e97ad

Browse files
jmelisclaude
andcommitted
Add timing instrumentation to HCP lifecycle e2e tests
Record per-spec wall-clock durations to $SHARED_DIR/timing.jsonl so the timing report in rosa-regional-platform can show granular HCP lifecycle phases (vpc-create, cluster-ready-wait, vpc-delete, etc.) instead of a single opaque "hcp-tests" bar. Companion to openshift-online/rosa-hyperfleet#664. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent fb6b7b3 commit b8e97ad

1 file changed

Lines changed: 38 additions & 1 deletion

File tree

‎test/e2e-cli/cluster_test.go‎

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import (
3838
"net/url"
3939
"os"
4040
"os/exec"
41+
"path/filepath"
4142
"strings"
4243
"time"
4344

@@ -48,6 +49,29 @@ import (
4849
"github.com/openshift/rosa-regional-platform-api/internal/test/thanos"
4950
)
5051

52+
func recordTiming(phase string) func() {
53+
start := float64(time.Now().UnixNano()) / 1e9
54+
return func() {
55+
end := float64(time.Now().UnixNano()) / 1e9
56+
shared := os.Getenv("SHARED_DIR")
57+
if shared == "" {
58+
return
59+
}
60+
status := "ok"
61+
if CurrentSpecReport().Failed() {
62+
status = "error"
63+
}
64+
record := fmt.Sprintf(`{"phase":%q,"start":%.3f,"end":%.3f,"step":"e2e","status":%q}`,
65+
phase, start, end, status)
66+
f, err := os.OpenFile(filepath.Join(shared, "timing.jsonl"), os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
67+
if err != nil {
68+
return
69+
}
70+
defer f.Close()
71+
fmt.Fprintln(f, record)
72+
}
73+
}
74+
5175
func customerEnv() []string {
5276
return []string{"AWS_PROFILE=" + os.Getenv("CUSTOMER_AWS_PROFILE")}
5377
}
@@ -304,7 +328,7 @@ var _ = Describe("ROSACTL CLI E2E Tests", Ordered, func() {
304328

305329
// create a new cluster-vpc
306330
It("should be able to create a new cluster-vpc", Label("vpc-create", "setup"), func() {
307-
// wait for the command to complete, it will take a few minutes.
331+
defer recordTiming("hcp-vpc-create")()
308332
GinkgoWriter.Printf("Creating new cluster-vpc: %s\n", clusterName)
309333
// GinkgoWriter.Printf("Command: %s %s %s %s %s\n", ROSACTL_BIN, "cluster-vpc", "create", clusterName, "--region", region, "--availability-zones", "us-east-1a")
310334
cmd := exec.Command(ROSACTL_BIN, "cluster-vpc", "create", clusterName, "--region", region, "--availability-zones", "us-east-1a")
@@ -334,6 +358,7 @@ var _ = Describe("ROSACTL CLI E2E Tests", Ordered, func() {
334358

335359
// create a new cluster-iam
336360
It("should be able to create the cluster-iam", Label("iam-create", "setup"), func() {
361+
defer recordTiming("hcp-iam-create")()
337362
GinkgoWriter.Printf("Creating new cluster-iam: %s\n", clusterName)
338363
cmd := exec.Command(ROSACTL_BIN, "cluster-iam", "create", clusterName, "--region", region)
339364
cmd.Env = append(os.Environ(), customerEnv()...)
@@ -382,6 +407,7 @@ var _ = Describe("ROSACTL CLI E2E Tests", Ordered, func() {
382407
})
383408

384409
It("should be able to create the hcp cluster", Label("hcp-create", "create"), func() {
410+
defer recordTiming("hcp-cluster-create")()
385411
GinkgoWriter.Printf("Creating new HCP cluster: %s\n", clusterName)
386412
cmd := exec.Command(ROSACTL_BIN, "cluster", "create", clusterName, "--region", region, "--output", "json")
387413
cmd.Env = append(os.Environ(), customerEnv()...)
@@ -455,6 +481,7 @@ var _ = Describe("ROSACTL CLI E2E Tests", Ordered, func() {
455481
})
456482

457483
It("should be able to create the cluster-oidc", Label("oidc-create", "setup"), func() {
484+
defer recordTiming("hcp-oidc-create")()
458485
GinkgoWriter.Printf("Creating new cluster-oidc: %s\n", clusterName)
459486
if cloudUrl == "" {
460487
cloudUrl = os.Getenv("HCP_ROSA_ISSUER_URL")
@@ -488,6 +515,7 @@ var _ = Describe("ROSACTL CLI E2E Tests", Ordered, func() {
488515
// GET /api/v0/clusters/{id} and /statuses use the Hyperfleet resource id (e.g. "2pdl6eud5btdtvgv2f4roaca96e9mvtn"),
489516
// not the cluster display name. List responses are { "items": [ { "id", "name", "spec", "status", ... } ], ... }.
490517
It("should be able to wait for the hcp cluster to be ready", Label("cluster-status", "monitor"), func() {
518+
defer recordTiming("hcp-cluster-ready-wait")()
491519
id := clusterID
492520
if id == "" {
493521
id = os.Getenv("HCP_INSTANCE_ID")
@@ -568,6 +596,7 @@ var _ = Describe("ROSACTL CLI E2E Tests", Ordered, func() {
568596
})
569597

570598
It("should have valid DNS and TLS for the KAS endpoint", Label("dns-verify", "monitor"), func() {
599+
defer recordTiming("hcp-dns-tls-verify")()
571600
id := clusterID
572601
if id == "" {
573602
id = os.Getenv("HCP_INSTANCE_ID")
@@ -625,6 +654,7 @@ var _ = Describe("ROSACTL CLI E2E Tests", Ordered, func() {
625654
})
626655

627656
It("should have nodepools ready", Label("nodepools-wait", "monitor"), func() {
657+
defer recordTiming("hcp-nodepools-wait")()
628658
id := clusterID
629659
if id == "" {
630660
id = os.Getenv("HCP_INSTANCE_ID")
@@ -705,6 +735,7 @@ var _ = Describe("ROSACTL CLI E2E Tests", Ordered, func() {
705735
})
706736

707737
It("should be able to delete the hcp cluster", Label("hcp-delete", "cleanup"), func() {
738+
defer recordTiming("hcp-cluster-delete")()
708739
if clusterID == "" {
709740
clusterID = os.Getenv("HCP_INSTANCE_ID")
710741
if clusterID == "" {
@@ -720,6 +751,7 @@ var _ = Describe("ROSACTL CLI E2E Tests", Ordered, func() {
720751

721752
// it should be able to query the /cluster/id until it is deleted
722753
It("should be able to query the /cluster/id until it is deleted", Label("hcp-delete", "cluster-query", "cleanup"), func() {
754+
defer recordTiming("hcp-cluster-delete-wait")()
723755
GinkgoWriter.Printf("Querying the hcp clusterId: %s\n", clusterID)
724756
if clusterID == "" {
725757
clusterID = os.Getenv("HCP_INSTANCE_ID")
@@ -736,6 +768,7 @@ var _ = Describe("ROSACTL CLI E2E Tests", Ordered, func() {
736768
})
737769

738770
It("should be able to delete the resource bundles", Label("hcp-delete", "bundles-delete", "cleanup"), func() {
771+
defer recordTiming("hcp-bundles-delete")()
739772
if clusterID == "" {
740773
clusterID = os.Getenv("HCP_INSTANCE_ID")
741774
if clusterID == "" {
@@ -748,6 +781,7 @@ var _ = Describe("ROSACTL CLI E2E Tests", Ordered, func() {
748781
})
749782

750783
It("should wait for resource bundles to be fully removed", Label("bundles-wait", "cleanup"), func() {
784+
defer recordTiming("hcp-bundles-wait")()
751785
if clusterID == "" {
752786
clusterID = os.Getenv("HCP_INSTANCE_ID")
753787
if clusterID == "" {
@@ -767,6 +801,7 @@ var _ = Describe("ROSACTL CLI E2E Tests", Ordered, func() {
767801
})
768802

769803
It("should be able to delete the cluster-oidc", Label("oidc-delete", "cleanup"), func() {
804+
defer recordTiming("hcp-oidc-delete")()
770805
GinkgoWriter.Printf("Deleting the cluster-oidc: %s\n", clusterName)
771806
cmd := exec.Command(ROSACTL_BIN, "cluster-oidc", "delete", clusterName, "--region", region)
772807
cmd.Env = append(os.Environ(), customerEnv()...)
@@ -779,6 +814,7 @@ var _ = Describe("ROSACTL CLI E2E Tests", Ordered, func() {
779814

780815
// Delete cluster-vpc with up to 3 attempts; fail the spec if all attempts return an error.
781816
It("should be able to try to delete the cluster-vpc, trying 3 times", Label("vpc-delete", "cleanup"), func() {
817+
defer recordTiming("hcp-vpc-delete")()
782818
const maxAttempts = 3
783819
const backoffBetweenAttempts = 5 * time.Minute
784820

@@ -818,6 +854,7 @@ var _ = Describe("ROSACTL CLI E2E Tests", Ordered, func() {
818854
})
819855

820856
It("should be able to delete the cluster-iam", Label("iam-delete", "cleanup"), func() {
857+
defer recordTiming("hcp-iam-delete")()
821858
GinkgoWriter.Printf("Deleting the cluster-iam: %s\n", clusterName)
822859
cmd := exec.Command(ROSACTL_BIN, "cluster-iam", "delete", clusterName, "--region", region)
823860
cmd.Env = append(os.Environ(), customerEnv()...)

0 commit comments

Comments
 (0)