Skip to content

Commit

Permalink
Merge branch 'master' into issue-1620
Browse files Browse the repository at this point in the history
  • Loading branch information
AstroProfundis authored Dec 2, 2021
2 parents 099397a + e0b5a7b commit 8f76494
Show file tree
Hide file tree
Showing 6 changed files with 109 additions and 19 deletions.
2 changes: 1 addition & 1 deletion components/playground/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ if you don't specified a version.
Examples:
$ tiup playground nightly # Start a TiDB nightly version local cluster
$ tiup playground v5.0.1 --db 3 --pd 3 --kv 3 # Start a local cluster with 10 nodes
$ tiup playground nightly --monitor=false # Start a local cluster and disable monitor system
$ tiup playground nightly --without-monitor # Start a local cluster and disable monitor system
$ tiup playground --pd.config ~/config/pd.toml # Start a local cluster with specified configuration file
$ tiup playground --db.binpath /xx/tidb-server # Start a local cluster with component binary path
$ tiup playground --mode tikv-slim # Start a local tikv only cluster (No TiDB or TiFlash Available)
Expand Down
47 changes: 39 additions & 8 deletions doc/user/playground.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,48 @@ The command line arguments for playground state:
```bash
Usage:
tiup playground [version] [flags]
tiup [command]

Available Commands:
completion generate the autocompletion script for the specified shell
display
help Help about any command
scale-in
scale-out

Flags:
--db int TiDB instance number (default 1)
--db int TiDB instance number
--db.host host Playground TiDB host. If not provided, TiDB will still use host flag as its host
--db.port int Playground TiDB port. If not provided, TiDB will use 4000 as its port
--db.binpath string TiDB instance binary path
--db.config string TiDB instance configuration file
--db.timeout int TiDB max wait time in seconds for starting, 0 means no limit
--drainer int Drainer instance number
--drainer.binpath string Drainer instance binary path
--drainer.config string Drainer instance configuration file
-h, --help help for tiup
--host string Playground cluster host (default "127.0.0.1")
--kv int TiKV instance number (default 1)
--host string Playground cluster host
--kv int TiKV instance number
--kv.binpath string TiKV instance binary path
--kv.config string TiKV instance configuration file
--monitor Start prometheus component
--pd int PD instance number (default 1)
--mode string TiUP playground mode: 'tidb', 'tikv-slim' (default "tidb")
--pd int PD instance number
--pd.Host host Playground PD host. If not provided, PD will still use host flag as its host
--pd.binpath string PD instance binary path
--pd.config string PD instance configuration file
--pump int Pump instance number
--pump.binpath string Pump instance binary path
--pump.config string Pump instance configuration file
-T, --tag string Specify a tag for playground
--ticdc int TiCDC instance number
--ticdc.binpath string TiCDC instance binary path
--ticdc.config string TiCDC instance configuration file
--tiflash int TiFlash instance number
--tiflash.binpath string TiFlash instance binary path
--tiflash.config string TiFlash instance configuration file
--tiflash.timeout int TiFlash max wait time in seconds for starting, 0 means no limit
-v, --version version for tiup
--without-monitor Don't start prometheus and grafana component
```
## Example
Expand All @@ -51,13 +76,19 @@ tiup playground nightly
Nightly is the version number of this cluster, and similar ones can be `tiup playground v4.0.0-rc` etc.
### Start a cluster with monitoring.
### Start a cluster with or without monitoring.
```shell
tiup playground nightly
```
This command launches Prometheus on port 9090 and Grafana on port 3000 for displaying timing data within the cluster.
```shell
tiup playground nightly --monitor
tiup playground nightly --without-monitor
```
This command launches prometheus on port 9090 for displaying timing data within the cluster.
This won't launch Prometheus or Grafana. This can be used to save resources.

### Overrides the default configuration of the PD

Expand Down
29 changes: 23 additions & 6 deletions pkg/cluster/task/step.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ func (s *StepDisplay) Execute(ctx context.Context) error {
}

switch s.DisplayMode {
case log.DisplayModeJSON:
case log.DisplayModeJSON,
log.DisplayModePlain:
break
default:
if singleBar, ok := s.progressBar.(*progress.SingleBar); ok {
Expand Down Expand Up @@ -126,7 +127,9 @@ func (s *StepDisplay) Execute(ctx context.Context) error {

switch s.DisplayMode {
case log.DisplayModeJSON:
_ = printDp(dp)
_ = printDpJSON(dp)
case log.DisplayModePlain:
printDpPlain(dp)
default:
s.progressBar.UpdateDisplay(dp)
}
Expand All @@ -153,7 +156,9 @@ func (s *StepDisplay) handleTaskBegin(task Task) {
}
switch s.DisplayMode {
case log.DisplayModeJSON:
_ = printDp(dp)
_ = printDpJSON(dp)
case log.DisplayModePlain:
printDpPlain(dp)
default:
s.progressBar.UpdateDisplay(dp)
}
Expand All @@ -169,7 +174,9 @@ func (s *StepDisplay) handleTaskProgress(task Task, p string) {
}
switch s.DisplayMode {
case log.DisplayModeJSON:
_ = printDp(dp)
_ = printDpJSON(dp)
case log.DisplayModePlain:
printDpPlain(dp)
default:
s.progressBar.UpdateDisplay(dp)
}
Expand Down Expand Up @@ -209,7 +216,8 @@ func (ps *ParallelStepDisplay) SetDisplayMode(m log.DisplayMode) *ParallelStepDi
// Execute implements the Task interface
func (ps *ParallelStepDisplay) Execute(ctx context.Context) error {
switch ps.DisplayMode {
case log.DisplayModeJSON:
case log.DisplayModeJSON,
log.DisplayModePlain:
break
default:
ps.progressBar.StartRenderLoop()
Expand All @@ -229,11 +237,20 @@ func (ps *ParallelStepDisplay) String() string {
return ps.inner.String()
}

func printDp(dp *progress.DisplayProps) error {
func printDpJSON(dp *progress.DisplayProps) error {
output, err := json.Marshal(dp)
if err != nil {
return err
}
fmt.Println(string(output))
return nil
}

func printDpPlain(dp *progress.DisplayProps) {
switch dp.Mode {
case progress.ModeError:
log.Errorf("progress: %s", dp)
default:
log.Infof("progress: %s", dp)
}
}
19 changes: 16 additions & 3 deletions pkg/logger/log/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ import (

var (
outputFmt DisplayMode = DisplayModeDefault // global output format of logger

stdout io.Writer = os.Stdout
stderr io.Writer = os.Stderr
)

// DisplayMode control the output format
Expand Down Expand Up @@ -76,19 +79,29 @@ func Debugf(format string, args ...interface{}) {
// Deprecated: Use zap.L().Info() instead
func Infof(format string, args ...interface{}) {
zap.L().Info(fmt.Sprintf(format, args...))
printLog(os.Stdout, "info", format, args...)
printLog(stdout, "info", format, args...)
}

// Warnf output the warning message to console
// Deprecated: Use zap.L().Warn() instead
func Warnf(format string, args ...interface{}) {
zap.L().Warn(fmt.Sprintf(format, args...))
printLog(os.Stderr, "warn", format, args...)
printLog(stderr, "warn", format, args...)
}

// Errorf output the error message to console
// Deprecated: Use zap.L().Error() instead
func Errorf(format string, args ...interface{}) {
zap.L().Error(fmt.Sprintf(format, args...))
printLog(os.Stderr, "error", format, args...)
printLog(stderr, "error", format, args...)
}

// SetStdout redirect stdout to a custom writer
func SetStdout(w io.Writer) {
stdout = w
}

// SetStderr redirect stderr to a custom writer
func SetStderr(w io.Writer) {
stderr = w
}
2 changes: 1 addition & 1 deletion pkg/logger/log/verbose.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@ func Verbose(format string, args ...interface{}) {
if !verbose {
return
}
fmt.Fprintln(os.Stderr, "Verbose:", fmt.Sprintf(format, args...))
fmt.Fprintln(stderr, "Verbose:", fmt.Sprintf(format, args...))
}
29 changes: 29 additions & 0 deletions pkg/tui/progress/display_props.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ package progress

import (
"encoding/json"
"fmt"
"strings"
)

Expand Down Expand Up @@ -72,9 +73,37 @@ func (m *Mode) UnmarshalJSON(b []byte) error {
return nil
}

// String implements string
func (m Mode) String() string {
var s string
switch m {
case ModeSpinner:
s = "spinner"
case ModeProgress:
s = "progress"
case ModeDone:
s = "done"
case ModeError:
s = "error"
default:
s = "unknown"
}
return s
}

// DisplayProps controls the display of the progress bar.
type DisplayProps struct {
Prefix string `json:"prefix,omitempty"`
Suffix string `json:"suffix,omitempty"` // If `Mode == Done / Error`, Suffix is not printed
Mode Mode `json:"mode,omitempty"`
}

// String implements string
func (dp *DisplayProps) String() string {
return fmt.Sprintf(
"(%s) %s: %s",
dp.Mode,
dp.Prefix,
dp.Suffix,
)
}

0 comments on commit 8f76494

Please sign in to comment.