Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
Signed-off-by: Tim Vaillancourt <tim@timvaillancourt.com>
  • Loading branch information
timvaillancourt committed Jul 17, 2024
1 parent e4d7f05 commit 6f70835
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 1 deletion.
21 changes: 21 additions & 0 deletions go/flagutil/flagutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,3 +268,24 @@ func (v *DurationOrIntVar) Type() string { return "duration" }

// Value returns the underlying Duration value passed to the flag.
func (v *DurationOrIntVar) Value() time.Duration { return v.val }

type DurationOrSecondsFloatFlag float64

func (set *DurationOrSecondsFloatFlag) Set(s string) error {
if dur, err := time.ParseDuration(s); err == nil {
*set = DurationOrSecondsFloatFlag(dur.Seconds())
} else {
f, err := strconv.ParseFloat(s, 64)
if err != nil {
return err
}
*set = DurationOrSecondsFloatFlag(f)
}
return nil
}

func (set *DurationOrSecondsFloatFlag) String() string {
return strconv.FormatFloat(float64(*set), 'f', -1, 64)
}

func (set *DurationOrSecondsFloatFlag) Type() string { return "DurationOrSecondsFloatFlag" }
46 changes: 46 additions & 0 deletions go/flagutil/flagutil_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -159,3 +159,49 @@ func TestDurationOrIntVar(t *testing.T) {
assert.Equal(t, tt.want, flag.Value())
}
}

func TestDurationOrSecondsFloatFlag(t *testing.T) {
testCases := []struct {
Set string
Expected float64
ExpectedErr string
}{
{
Set: "1",
Expected: 1,
},
{
Set: "0.5",
Expected: 0.5,
},
{
Set: "1800",
Expected: 1800,
},
{
Set: "50ms",
Expected: 0.05,
},
{
Set: "42m",
Expected: 2520,
},
{
Set: "wont-parse",
ExpectedErr: `strconv.ParseFloat: parsing "wont-parse": invalid syntax`,
},
}

for _, testCase := range testCases {
testCase := testCase
t.Run(testCase.Set, func(t *testing.T) {
t.Parallel()
var f DurationOrSecondsFloatFlag
err := f.Set(testCase.Set)
if testCase.ExpectedErr != "" {
assert.ErrorContains(t, err, testCase.ExpectedErr)
}
assert.Equal(t, testCase.Expected, float64(f))
})
}
}
2 changes: 1 addition & 1 deletion go/vt/vttablet/tabletserver/tabletenv/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ func registerTabletEnvFlags(fs *pflag.FlagSet) {
SecondsVar(fs, &currentConfig.OltpReadPool.TimeoutSeconds, "queryserver-config-query-pool-timeout", defaultConfig.OltpReadPool.TimeoutSeconds, "query server query pool timeout (in seconds), it is how long vttablet waits for a connection from the query pool. If set to 0 (default) then the overall query timeout is used instead.")
SecondsVar(fs, &currentConfig.OlapReadPool.TimeoutSeconds, "queryserver-config-stream-pool-timeout", defaultConfig.OlapReadPool.TimeoutSeconds, "query server stream pool timeout (in seconds), it is how long vttablet waits for a connection from the stream pool. If set to 0 (default) then there is no timeout.")
SecondsVar(fs, &currentConfig.TxPool.TimeoutSeconds, "queryserver-config-txpool-timeout", defaultConfig.TxPool.TimeoutSeconds, "query server transaction pool timeout, it is how long vttablet waits if tx pool is full")
SecondsVar(fs, &currentConfig.OltpReadPool.IdleTimeoutSeconds, "queryserver-config-idle-timeout", defaultConfig.OltpReadPool.IdleTimeoutSeconds, "query server idle timeout (in seconds), vttablet manages various mysql connection pools. This config means if a connection has not been used in given idle timeout, this connection will be removed from pool. This effectively manages number of connection objects and optimize the pool performance.")
fs.Var((*flagutil.DurationOrSecondsFloatFlag)(&currentConfig.OltpReadPool.IdleTimeoutSeconds), "queryserver-config-idle-timeout", "query server idle timeout (in seconds), vttablet manages various mysql connection pools. This config means if a connection has not been used in given idle timeout, this connection will be removed from pool. This effectively manages number of connection objects and optimize the pool performance.")
fs.IntVar(&currentConfig.OltpReadPool.MaxWaiters, "queryserver-config-query-pool-waiter-cap", defaultConfig.OltpReadPool.MaxWaiters, "query server query pool waiter limit, this is the maximum number of queries that can be queued waiting to get a connection")
fs.IntVar(&currentConfig.OlapReadPool.MaxWaiters, "queryserver-config-stream-pool-waiter-cap", defaultConfig.OlapReadPool.MaxWaiters, "query server stream pool waiter limit, this is the maximum number of streaming queries that can be queued waiting to get a connection")
fs.IntVar(&currentConfig.TxPool.MaxWaiters, "queryserver-config-txpool-waiter-cap", defaultConfig.TxPool.MaxWaiters, "query server transaction pool waiter limit, this is the maximum number of transactions that can be queued waiting to get a connection")
Expand Down

0 comments on commit 6f70835

Please sign in to comment.