From 2273c66f835c56225b254624b907a6dbe1b50737 Mon Sep 17 00:00:00 2001 From: Max Ma Date: Fri, 3 Oct 2025 23:18:47 +0200 Subject: [PATCH] add blueray cluster support for saving the cluster information --- stage/pulumi_run_recorder.go | 45 ++++++++++++++++++++++++++++++- stage/pulumi_run_recorder_test.go | 35 ++++++++++++++++++++++++ 2 files changed, 79 insertions(+), 1 deletion(-) create mode 100644 stage/pulumi_run_recorder_test.go diff --git a/stage/pulumi_run_recorder.go b/stage/pulumi_run_recorder.go index f6a53b3e..84934a34 100644 --- a/stage/pulumi_run_recorder.go +++ b/stage/pulumi_run_recorder.go @@ -12,6 +12,7 @@ import ( "os" "pbench/log" "regexp" + "strings" "time" ) @@ -163,8 +164,50 @@ func (p *PulumiMySQLRunRecorder) findPulumiStackFromClusterFQDN(ctx context.Cont return nil } +func (p *PulumiMySQLRunRecorder) findStackFromClusterFQDN(ctx context.Context, clusterFQDN string) *PulumiResource { + // Check if the cluster FQDN matches the Presto DB pattern + if strings.HasSuffix(clusterFQDN, ".ibm.prestodb.dev") { + return p.findPulumiStackFromClusterFQDN(ctx, clusterFQDN) + } + + // Check if the cluster FQDN matches the blueray pattern + if strings.HasSuffix(clusterFQDN, ".cloud.ibm.com") { + return p.findBluerayStackFromClusterFQDN(clusterFQDN) + } + + // Log if the FQDN doesn't match any known pattern + log.Warn().Str("cluster_fqdn", clusterFQDN).Msg("cluster FQDN does not match any known pattern") + return nil +} + +func (p *PulumiMySQLRunRecorder) findBluerayStackFromClusterFQDN(clusterFQDN string) *PulumiResource { + // Extract cluster name as the first part of the FQDN (before the first dot) + parts := strings.SplitN(clusterFQDN, ".", 2) + if len(parts) < 2 { + log.Error().Str("cluster_fqdn", clusterFQDN).Msg("failed to extract cluster name from Blueray FQDN") + return nil + } + + clusterName := parts[0] + + // Create a PulumiResource with the extracted information + resource := &PulumiResource{ + Type: PulumiResourceTypeStack, + Created: time.Now(), + } + + // Set the outputs + resource.Outputs.ClusterFQDN = clusterFQDN + resource.Outputs.ClusterName = clusterName + + log.Info().Str("cluster_name", clusterName).Str("cluster_fqdn", clusterFQDN). + Msg("extracted cluster information from Blueray FQDN") + + return resource +} + func (p *PulumiMySQLRunRecorder) Start(ctx context.Context, s *Stage) error { - stack := p.findPulumiStackFromClusterFQDN(ctx, s.States.ServerFQDN) + stack := p.findStackFromClusterFQDN(ctx, s.States.ServerFQDN) if stack == nil { log.Info().Msgf("did not find a matching Pulumi stack for %s", s.States.ServerFQDN) return nil diff --git a/stage/pulumi_run_recorder_test.go b/stage/pulumi_run_recorder_test.go new file mode 100644 index 00000000..0e190abb --- /dev/null +++ b/stage/pulumi_run_recorder_test.go @@ -0,0 +1,35 @@ +package stage + +import ( + "testing" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" +) + +func TestFindBluerayStackFromClusterFQDN(t *testing.T) { + // Create a recorder with minimal initialization for testing + recorder := &PulumiMySQLRunRecorder{} + + // Test FQDN + testFQDN := "xlarge-b109n-yabin-eng.k9b9rz3nk2.staging.cvpc.lakehouse.test.cloud.ibm.com" + expectedClusterName := "xlarge-b109n-yabin-eng" + + // Call the function + resource := recorder.findBluerayStackFromClusterFQDN(testFQDN) + + // Verify resource is not nil + require.NotNil(t, resource) + + // Verify the cluster FQDN + assert.Equal(t, testFQDN, resource.Outputs.ClusterFQDN) + + // Verify the cluster name + assert.Equal(t, expectedClusterName, resource.Outputs.ClusterName) + + // Verify the resource type + assert.Equal(t, PulumiResourceTypeStack, resource.Type) + + // Verify Created timestamp is not zero + assert.False(t, resource.Created.IsZero()) +}