Skip to content
Merged
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
29 changes: 27 additions & 2 deletions internal/cmd/size/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ type ClusterSKU struct {
Replicas string `header:"replicas" json:"replicas"`

orig *planetscale.ClusterSKU
rate *int64
}

// ClusterSKUSingleEngine is the format for single-engine views (--engine mysql or --engine postgresql).
Expand All @@ -167,18 +168,36 @@ type ClusterSKUSingleEngine struct {
Replicas string `header:"replicas" json:"replicas"`

orig *planetscale.ClusterSKU
rate *int64
}

type clusterSKUJSON struct {
*planetscale.ClusterSKU
Rate *int64 `json:"rate"`
Configuration string `json:"configuration"`
Replicas string `json:"replicas"`
}

func (c *ClusterSKU) MarshalJSON() ([]byte, error) {
return json.MarshalIndent(c.orig, "", " ")
return json.MarshalIndent(&clusterSKUJSON{
ClusterSKU: c.orig,
Rate: c.rate,
Configuration: c.Configuration,
Replicas: c.Replicas,
}, "", " ")
}

func (c *ClusterSKU) MarshalCSVValue() interface{} {
return []*ClusterSKU{c}
}

func (c *ClusterSKUSingleEngine) MarshalJSON() ([]byte, error) {
return json.MarshalIndent(c.orig, "", " ")
return json.MarshalIndent(&clusterSKUJSON{
ClusterSKU: c.orig,
Rate: c.rate,
Configuration: c.Configuration,
Replicas: c.Replicas,
}, "", " ")

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Non-HA JSON shows HA price

High Severity

JSON marshaling embeds the shared API ClusterSKU (c.orig) while only adding a sibling Rate field. Table and CSV already use formatClusterFields with ReplicaRate for single-node rows, but JSON still surfaces the HA pricing from the embedded SKU, so non-HA entries keep the HA price (as noted in review).

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 109152c. Configure here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

You're wrong. The rate is correct for HA and single-node for all three output formats.

}

func (c *ClusterSKUSingleEngine) MarshalCSVValue() interface{} {
Expand Down Expand Up @@ -261,6 +280,7 @@ func toClusterSKUs(items []clusterSKUWithEngine, onlyMetal bool) []*ClusterSKU {
Configuration: "highly available",
Replicas: "2",
orig: item.sku,
rate: item.sku.Rate,
})

// Single node version using replica_rate (only for non-metal clusters)
Expand All @@ -277,6 +297,7 @@ func toClusterSKUs(items []clusterSKUWithEngine, onlyMetal bool) []*ClusterSKU {
Configuration: "single node",
Replicas: "0",
orig: item.sku,
rate: item.sku.ReplicaRate,
})
}
} else {
Expand All @@ -292,6 +313,7 @@ func toClusterSKUs(items []clusterSKUWithEngine, onlyMetal bool) []*ClusterSKU {
Configuration: "highly available",
Replicas: "2",
orig: item.sku,
rate: item.sku.Rate,
})
}
}
Expand Down Expand Up @@ -322,6 +344,7 @@ func toClusterSKUsSingleEngine(items []clusterSKUWithEngine, onlyMetal bool) []*
Configuration: "highly available",
Replicas: "2",
orig: item.sku,
rate: item.sku.Rate,
})

// Single node version using replica_rate (only for non-metal clusters)
Expand All @@ -337,6 +360,7 @@ func toClusterSKUsSingleEngine(items []clusterSKUWithEngine, onlyMetal bool) []*
Configuration: "single node",
Replicas: "0",
orig: item.sku,
rate: item.sku.ReplicaRate,
})
}
} else {
Expand All @@ -351,6 +375,7 @@ func toClusterSKUsSingleEngine(items []clusterSKUWithEngine, onlyMetal bool) []*
Configuration: "highly available",
Replicas: "2",
orig: item.sku,
rate: item.sku.Rate,
})
}
}
Expand Down
6 changes: 3 additions & 3 deletions internal/cmd/size/cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,8 @@ func TestSizeCluster_ListCmd_PostgreSQL(t *testing.T) {
// PostgreSQL clusters use ClusterSKUSingleEngine type (no engine column, has configuration and replicas)
// Each cluster shows twice: once as HA and once as single node
res := []*ClusterSKUSingleEngine{
{orig: orig[0]},
{orig: orig[0]},
{Configuration: "highly available", Replicas: "2", orig: orig[0], rate: orig[0].Rate},
{Configuration: "single node", Replicas: "0", orig: orig[0], rate: orig[0].ReplicaRate},
}

c.Assert(buf.String(), qt.JSONEquals, res)
Expand Down Expand Up @@ -158,7 +158,7 @@ func TestSizeCluster_ListCmd_MySQL(t *testing.T) {

// MySQL uses ClusterSKUSingleEngine type (no engine column, but has configuration and replicas)
res := []*ClusterSKUSingleEngine{
{orig: orig[0]},
{Configuration: "highly available", Replicas: "2", orig: orig[0], rate: orig[0].Rate},
}

c.Assert(buf.String(), qt.JSONEquals, res)
Expand Down