Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 44 additions & 1 deletion stage/pulumi_run_recorder.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"os"
"pbench/log"
"regexp"
"strings"
"time"
)

Expand Down Expand Up @@ -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
Expand Down
35 changes: 35 additions & 0 deletions stage/pulumi_run_recorder_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package stage

import (
"testing"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can import "github.com/stretchr/testify/assert" and "github.com/stretchr/testify/require" here and use assert/require libraries below. You can check client_test.go as an example.


"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())
}