Skip to content

Commit

Permalink
[CLOUDGA-23744] : Do not show CP Status in cluster list if FF disabled (
Browse files Browse the repository at this point in the history
#253)

* [CLOUDGA-23744] : Do not show CP Status in cluster list if FF disabled

* Fixed UT and describe

---------

Co-authored-by: Aditya Kaushik <[email protected]>
  • Loading branch information
adityakaushik99-yb and Aditya Kaushik authored Sep 27, 2024
1 parent b62d4e7 commit 7d974dc
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 7 deletions.
4 changes: 2 additions & 2 deletions cmd/cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,8 +253,8 @@ stunning-sole Dedicated 2.16.0.1-b7 ACTIVE 💚 AWS us-we
Name ID Version State Health
stunning-sole 5f80730f-ba3f-4f7e-8c01-f8fa4c90dad8 2.16.0.1-b7 ACTIVE 💚
Provider Tier Fault Tolerance Nodes Node Res.(Vcpu/Mem/DiskGB/IOPS)
AWS Dedicated NONE, RF 1 1 2 / 8GB / 100GB / -
Provider Tier Fault Tolerance Nodes Node Res.(Vcpu/Mem/DiskGB/IOPS) Connection Pooling Enabled
AWS Dedicated NONE, RF 1 1 2 / 8GB / 100GB / - false
Regions
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ require (
github.com/spf13/cobra v1.8.0
github.com/spf13/viper v1.17.0
github.com/t-tomalak/logrus-easy-formatter v0.0.0-20190827215021-c074f06c5816
github.com/yugabyte/yugabytedb-managed-go-client-internal v0.0.0-20240910231830-cdba4214092b
github.com/yugabyte/yugabytedb-managed-go-client-internal v0.0.0-20240925202023-da1620747493
golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56
golang.org/x/mod v0.20.0
golang.org/x/term v0.23.0
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,8 @@ github.com/t-tomalak/logrus-easy-formatter v0.0.0-20190827215021-c074f06c5816 h1
github.com/t-tomalak/logrus-easy-formatter v0.0.0-20190827215021-c074f06c5816/go.mod h1:tzym/CEb5jnFI+Q0k4Qq3+LvRF4gO3E2pxS8fHP8jcA=
github.com/yugabyte/yugabytedb-managed-go-client-internal v0.0.0-20240910231830-cdba4214092b h1:zHdbakF62w4cA/V4oMfV37W/u3nWwRNG82/EIrSrHMs=
github.com/yugabyte/yugabytedb-managed-go-client-internal v0.0.0-20240910231830-cdba4214092b/go.mod h1:5vW0xIzIZw+1djkiWKx0qqNmqbRBSf4mjc4qw8lIMik=
github.com/yugabyte/yugabytedb-managed-go-client-internal v0.0.0-20240925202023-da1620747493 h1:MAJZvwCT5Jl2zoW+QoZZg6lXj2YXytMOFn2MuwQzyQQ=
github.com/yugabyte/yugabytedb-managed-go-client-internal v0.0.0-20240925202023-da1620747493/go.mod h1:5vW0xIzIZw+1djkiWKx0qqNmqbRBSf4mjc4qw8lIMik=
github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
Expand Down
35 changes: 33 additions & 2 deletions internal/formatter/clusters.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,15 @@ import (
"github.com/enescakir/emoji"
"github.com/inhies/go-bytesize"
"github.com/sirupsen/logrus"
"github.com/yugabyte/ybm-cli/cmd/util"
ybmclient "github.com/yugabyte/yugabytedb-managed-go-client-internal"
"golang.org/x/exp/maps"
"golang.org/x/exp/slices"
)

const (
defaultClusterListing = "table {{.Name}}\t{{.Tier}}\t{{.SoftwareVersion}}\t{{.State}}\t{{.HealthState}}\t{{.Provider}}\t{{.Regions}}\t{{.Nodes}}\t{{.NodesSpec}}\t{{.ConnectionPoolingStatus}}"
defaultClusterListing = "table {{.Name}}\t{{.Tier}}\t{{.SoftwareVersion}}\t{{.State}}\t{{.HealthState}}\t{{.Provider}}\t{{.Regions}}\t{{.Nodes}}\t{{.NodesSpec}}"
defaultClusterListingV2 = "table {{.Name}}\t{{.Tier}}\t{{.SoftwareVersion}}\t{{.State}}\t{{.HealthState}}\t{{.Provider}}\t{{.Regions}}\t{{.Nodes}}\t{{.NodesSpec}}\t{{.ConnectionPoolingStatus}}"
numNodesHeader = "Nodes"
nodeInfoHeader = "Node Res.(Vcpu/Mem/DiskGB/IOPS)"
healthStateHeader = "Health"
Expand All @@ -50,6 +52,9 @@ func NewClusterFormat(source string) Format {
switch source {
case "table", "":
format := defaultClusterListing
if util.IsFeatureFlagEnabled(util.CONNECTION_POOLING){
format = defaultClusterListingV2
}
return Format(format)
default: // custom format or json or pretty
return Format(source)
Expand All @@ -68,11 +73,37 @@ func ClusterWrite(ctx Context, clusters []ybmclient.ClusterData) error {
}
return nil
}
return ctx.Write(NewClusterContext(), render)

clusterContext := NewClusterContext()

if util.IsFeatureFlagEnabled(util.CONNECTION_POOLING){
clusterContext = NewClusterContextV2()
}

return ctx.Write(clusterContext, render)
}

// NewClusterContext creates a new context for rendering cluster
func NewClusterContext() *ClusterContext {
clusterCtx := ClusterContext{}
clusterCtx.Header = SubHeaderContext{
"Name": nameHeader,
"ID": "ID",
"Regions": regionsHeader,
"Nodes": numNodesHeader,
"NodesSpec": nodeInfoHeader,
"SoftwareVersion": softwareVersionHeader,
"State": stateHeader,
"HealthState": healthStateHeader,
"Provider": providerHeader,
"FaultTolerance": faultToleranceHeader,
"DataDistribution": dataDistributionHeader,
"Tier": tierHeader,
}
return &clusterCtx
}

func NewClusterContextV2() *ClusterContext {
clusterCtx := ClusterContext{}
clusterCtx.Header = SubHeaderContext{
"Name": nameHeader,
Expand Down
18 changes: 16 additions & 2 deletions internal/formatter/clusters_full.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,14 @@ func (c *FullClusterContext) Write() error {
if err := c.contextFormat(tmpl, fcc.Cluster); err != nil {
return err
}
c.postFormat(tmpl, NewClusterContext())

clusterContext := NewClusterContext()


if util.IsFeatureFlagEnabled(util.CONNECTION_POOLING){
clusterContext = NewClusterContextV2()
}
c.postFormat(tmpl, clusterContext)



Expand All @@ -174,7 +181,14 @@ func (c *FullClusterContext) Write() error {
if err := c.contextFormat(tmpl, fcc.Cluster); err != nil {
return err
}
c.postFormat(tmpl, NewClusterContext())

clusterContext = NewClusterContext()


if util.IsFeatureFlagEnabled(util.CONNECTION_POOLING){
clusterContext = NewClusterContextV2()
}
c.postFormat(tmpl, clusterContext)

//Regions Subsection
tmpl, err = c.startSubsection(defaultDefaultFullClusterRegion)
Expand Down

0 comments on commit 7d974dc

Please sign in to comment.