Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ require (
github.com/mattn/go-shellwords v1.0.12
github.com/mitchellh/go-homedir v1.1.0
github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c
github.com/planetscale/planetscale-go v0.157.0
github.com/planetscale/planetscale-go v0.158.0
github.com/planetscale/psdb v0.0.0-20250717190954-65c6661ab6e4
github.com/planetscale/psdbproxy v0.0.0-20250728082226-3f4ea3a74ec7
github.com/spf13/cobra v1.10.2
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,8 @@ github.com/planetscale/noglog v0.2.1-0.20210421230640-bea75fcd2e8e h1:MZ8D+Z3m2v
github.com/planetscale/noglog v0.2.1-0.20210421230640-bea75fcd2e8e/go.mod h1:hwAsSPQdvPa3WcfKfzTXxtEq/HlqwLjQasfO6QbGo4Q=
github.com/planetscale/planetscale-go v0.157.0 h1:b0kWxC39F4/FQw2/Y+5/H4tRWUAzvl2ZukimrsTYP7M=
github.com/planetscale/planetscale-go v0.157.0/go.mod h1:paQCI5SgquuoewvMQM7R+r1XJO868bdP6/ihGidYRM0=
github.com/planetscale/planetscale-go v0.158.0 h1:6Y/f2+24nHnkRd2Bfkz+d2P4T3Lx/kyZaBdsEd6EEWA=
github.com/planetscale/planetscale-go v0.158.0/go.mod h1:paQCI5SgquuoewvMQM7R+r1XJO868bdP6/ihGidYRM0=
github.com/planetscale/psdb v0.0.0-20250717190954-65c6661ab6e4 h1:Xv5pj20Rhfty1Tv0OVcidg4ez4PvGrpKvb6rvUwQgDs=
github.com/planetscale/psdb v0.0.0-20250717190954-65c6661ab6e4/go.mod h1:M52h5IWxAcbdQ1hSZrLAGQC4ZXslxEsK/Wh9nu3wdWs=
github.com/planetscale/psdbproxy v0.0.0-20250728082226-3f4ea3a74ec7 h1:aRd6vdE1fyuSI4RVj7oCr8lFmgqXvpnPUmN85VbZCp8=
Expand Down
17 changes: 11 additions & 6 deletions internal/cmd/trafficcontrol/budget_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@ import (

func BudgetCreateCmd(ch *cmdutil.Helper) *cobra.Command {
var flags struct {
name string
mode string
capacity int
rate int
burst int
concurrency int
name string
mode string
capacity int
rate int
burst int
concurrency int
warningThreshold int
}

cmd := &cobra.Command{
Expand Down Expand Up @@ -57,6 +58,9 @@ func BudgetCreateCmd(ch *cmdutil.Helper) *cobra.Command {
if cmd.Flags().Changed("concurrency") {
req.Concurrency = &flags.concurrency
}
if cmd.Flags().Changed("warning-threshold") {
req.WarningThreshold = &flags.warningThreshold
}

budget, err := client.TrafficBudgets.Create(ctx, req)
if err != nil {
Expand Down Expand Up @@ -86,6 +90,7 @@ func BudgetCreateCmd(ch *cmdutil.Helper) *cobra.Command {
cmd.Flags().IntVar(&flags.rate, "rate", 0, "Rate at which capacity refills, as a percentage of server resources (0-100). Unlimited when not set.")
cmd.Flags().IntVar(&flags.burst, "burst", 0, "Maximum capacity a single query can consume (0-6000). Unlimited when not set.")
cmd.Flags().IntVar(&flags.concurrency, "concurrency", 0, "Percentage of available worker processes (0-100). Unlimited when not set.")
cmd.Flags().IntVar(&flags.warningThreshold, "warning-threshold", 0, "Percentage (0-100) of capacity, burst, or concurrency at which to emit warnings for enforced budgets.`")

cmd.MarkFlagRequired("name") // nolint:errcheck

Expand Down
23 changes: 13 additions & 10 deletions internal/cmd/trafficcontrol/budget_create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,19 @@ func TestBudgetCreateCmd(t *testing.T) {
p := printer.NewPrinter(&format)
p.SetResourceOutput(&buf)

cap, rate, burst, conc := 80, 50, 60, 40
cap, rate, burst, conc, warnTh := 80, 50, 60, 40, 30

created := &ps.TrafficBudget{
ID: budgetID,
Name: "CPU Limiter",
Mode: "enforce",
Capacity: &cap,
Rate: &rate,
Burst: &burst,
Concurrency: &conc,
CreatedAt: time.Date(2025, 6, 15, 10, 0, 0, 0, time.UTC),
UpdatedAt: time.Date(2025, 6, 15, 10, 0, 0, 0, time.UTC),
ID: budgetID,
Name: "CPU Limiter",
Mode: "enforce",
Capacity: &cap,
Rate: &rate,
Burst: &burst,
Concurrency: &conc,
WarningThreshold: &warnTh,
CreatedAt: time.Date(2025, 6, 15, 10, 0, 0, 0, time.UTC),
UpdatedAt: time.Date(2025, 6, 15, 10, 0, 0, 0, time.UTC),
}

svc := &mock.TrafficBudgetsService{
Expand All @@ -47,6 +48,7 @@ func TestBudgetCreateCmd(t *testing.T) {
c.Assert(*req.Rate, qt.Equals, 50)
c.Assert(*req.Burst, qt.Equals, 60)
c.Assert(*req.Concurrency, qt.Equals, 40)
c.Assert(*req.WarningThreshold, qt.Equals, 30)
return created, nil
},
}
Expand All @@ -67,6 +69,7 @@ func TestBudgetCreateCmd(t *testing.T) {
"--rate", "50",
"--burst", "60",
"--concurrency", "40",
"--warning-threshold", "30",
})
err := cmd.Execute()

Expand Down
17 changes: 11 additions & 6 deletions internal/cmd/trafficcontrol/budget_update.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@ import (

func BudgetUpdateCmd(ch *cmdutil.Helper) *cobra.Command {
var flags struct {
name string
mode string
capacity int
rate int
burst int
concurrency int
name string
mode string
capacity int
rate int
burst int
concurrency int
warningThreshold int
}

cmd := &cobra.Command{
Expand Down Expand Up @@ -59,6 +60,9 @@ func BudgetUpdateCmd(ch *cmdutil.Helper) *cobra.Command {
if cmd.Flags().Changed("concurrency") {
req.Concurrency = &flags.concurrency
}
if cmd.Flags().Changed("warning-threshold") {
req.WarningThreshold = &flags.warningThreshold
}

end := ch.Printer.PrintProgress(fmt.Sprintf("Updating traffic budget %s in %s/%s",
printer.BoldBlue(budgetID), printer.BoldBlue(database), printer.BoldBlue(branch)))
Expand Down Expand Up @@ -91,6 +95,7 @@ func BudgetUpdateCmd(ch *cmdutil.Helper) *cobra.Command {
cmd.Flags().IntVar(&flags.rate, "rate", 0, "Rate at which capacity refills, as a percentage of server resources (0-100). Unlimited when not set.")
cmd.Flags().IntVar(&flags.burst, "burst", 0, "Maximum capacity a single query can consume (0-6000). Unlimited when not set.")
cmd.Flags().IntVar(&flags.concurrency, "concurrency", 0, "Percentage of available worker processes (0-100). Unlimited when not set.")
cmd.Flags().IntVar(&flags.warningThreshold, "warning-threshold", 0, "Percentage (0-100) of capacity, burst, or concurrency at which to emit warnings for enforced budgets.")

return cmd
}
1 change: 1 addition & 0 deletions internal/cmd/trafficcontrol/budget_update_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ func TestBudgetUpdateCmd(t *testing.T) {
c.Assert(req.Rate, qt.IsNil)
c.Assert(req.Burst, qt.IsNil)
c.Assert(req.Concurrency, qt.IsNil)
c.Assert(req.WarningThreshold, qt.IsNil)
c.Assert(req.Rules, qt.IsNil)
return updated, nil
},
Expand Down
40 changes: 21 additions & 19 deletions internal/cmd/trafficcontrol/traffic_control.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,16 @@ func TrafficCmd(ch *cmdutil.Helper) *cobra.Command {
}

type TrafficBudget struct {
ID string `header:"id" json:"id"`
Name string `header:"name" json:"name"`
Mode string `header:"mode" json:"mode"`
Capacity string `header:"capacity" json:"capacity"`
Rate string `header:"rate" json:"rate"`
Burst string `header:"burst" json:"burst"`
Concurrency string `header:"concurrency" json:"concurrency"`
CreatedAt int64 `header:"created_at,timestamp(ms|utc|human)" json:"created_at"`
UpdatedAt int64 `header:"updated_at,timestamp(ms|utc|human)" json:"updated_at"`
ID string `header:"id" json:"id"`
Name string `header:"name" json:"name"`
Mode string `header:"mode" json:"mode"`
Capacity string `header:"capacity" json:"capacity"`
Rate string `header:"rate" json:"rate"`
Burst string `header:"burst" json:"burst"`
Concurrency string `header:"concurrency" json:"concurrency"`
WarningThreshold string `header:"warning_threshold" json:"warning_threshold"`
CreatedAt int64 `header:"created_at,timestamp(ms|utc|human)" json:"created_at"`
UpdatedAt int64 `header:"updated_at,timestamp(ms|utc|human)" json:"updated_at"`

orig *ps.TrafficBudget
}
Expand All @@ -72,16 +73,17 @@ func (b *TrafficBudget) MarshalCSVValue() any {

func toTrafficBudget(b *ps.TrafficBudget) *TrafficBudget {
return &TrafficBudget{
ID: b.ID,
Name: b.Name,
Mode: b.Mode,
Capacity: formatOptionalInt(b.Capacity),
Rate: formatOptionalInt(b.Rate),
Burst: formatOptionalInt(b.Burst),
Concurrency: formatOptionalInt(b.Concurrency),
CreatedAt: printer.GetMilliseconds(b.CreatedAt),
UpdatedAt: printer.GetMilliseconds(b.UpdatedAt),
orig: b,
ID: b.ID,
Name: b.Name,
Mode: b.Mode,
Capacity: formatOptionalInt(b.Capacity),
Rate: formatOptionalInt(b.Rate),
Burst: formatOptionalInt(b.Burst),
Concurrency: formatOptionalInt(b.Concurrency),
WarningThreshold: formatOptionalInt(b.WarningThreshold),
CreatedAt: printer.GetMilliseconds(b.CreatedAt),
UpdatedAt: printer.GetMilliseconds(b.UpdatedAt),
orig: b,
}
}

Expand Down