app/vmctl: automatically check tty (#3938)

app/vmctl: automatically detect if TTY is available
This commit is contained in:
Dmytro Kozlov 2023-03-20 12:16:08 +02:00 committed by Aliaksandr Valialkin
parent 95b60c2777
commit aed59b9029
No known key found for this signature in database
GPG key ID: A72BEC6CD3D0DED1
5 changed files with 42 additions and 5 deletions

View file

@ -15,6 +15,7 @@ import (
"github.com/VictoriaMetrics/VictoriaMetrics/app/vmctl/backoff"
"github.com/VictoriaMetrics/VictoriaMetrics/app/vmctl/native"
"github.com/VictoriaMetrics/VictoriaMetrics/app/vmctl/remoteread"
"github.com/VictoriaMetrics/VictoriaMetrics/app/vmctl/terminal"
"github.com/urfave/cli/v2"
"github.com/VictoriaMetrics/VictoriaMetrics/app/vmctl/influx"
@ -71,7 +72,7 @@ func main() {
}
otsdbProcessor := newOtsdbProcessor(otsdbClient, importer, c.Int(otsdbConcurrency))
return otsdbProcessor.run(c.Bool(globalSilent), c.Bool(globalVerbose))
return otsdbProcessor.run(isNonInteractive(c), c.Bool(globalVerbose))
},
},
{
@ -112,7 +113,7 @@ func main() {
c.String(influxMeasurementFieldSeparator),
c.Bool(influxSkipDatabaseLabel),
c.Bool(influxPrometheusMode))
return processor.run(c.Bool(globalSilent), c.Bool(globalVerbose))
return processor.run(isNonInteractive(c), c.Bool(globalVerbose))
},
},
{
@ -152,7 +153,7 @@ func main() {
},
cc: c.Int(remoteReadConcurrency),
}
return rmp.run(ctx, c.Bool(globalSilent), c.Bool(globalVerbose))
return rmp.run(ctx, isNonInteractive(c), c.Bool(globalVerbose))
},
},
{
@ -186,7 +187,7 @@ func main() {
im: importer,
cc: c.Int(promConcurrency),
}
return pp.run(c.Bool(globalSilent), c.Bool(globalVerbose))
return pp.run(isNonInteractive(c), c.Bool(globalVerbose))
},
},
{
@ -244,7 +245,7 @@ func main() {
backoff: backoff.New(),
cc: c.Int(vmConcurrency),
}
return p.run(ctx, c.Bool(globalSilent))
return p.run(ctx, isNonInteractive(c))
},
},
{
@ -317,3 +318,8 @@ func initConfigVM(c *cli.Context) vm.Config {
DisableProgressBar: c.Bool(vmDisableProgressBar),
}
}
func isNonInteractive(c *cli.Context) bool {
isTerminal := terminal.IsTerminal(int(os.Stdout.Fd()))
return c.Bool(globalSilent) || !isTerminal
}

View file

@ -0,0 +1,14 @@
//go:build darwin || linux || solaris
// +build darwin linux solaris
package terminal
import (
"golang.org/x/sys/unix"
)
// IsTerminal returns true if the file descriptor is terminal
func IsTerminal(fd int) bool {
_, err := unix.IoctlGetTermios(fd, ioctlReadTermios)
return err == nil
}

View file

@ -0,0 +1,8 @@
//go:build aix || linux || solaris || zos
// +build aix linux solaris zos
package terminal
import "golang.org/x/sys/unix"
const ioctlReadTermios = unix.TCGETS

View file

@ -0,0 +1,8 @@
//go:build darwin
// +build darwin
package terminal
import "golang.org/x/sys/unix"
const ioctlReadTermios = unix.TIOCGETA

View file

@ -27,6 +27,7 @@ created by v1.90.0 or newer versions. The solution is to upgrade to v1.90.0 or n
* FEATURE: [vmui](https://docs.victoriametrics.com/#vmui): add support for drag'n'drop and paste from clipboard in the "Trace analyzer" page. See [this pull request](https://github.com/VictoriaMetrics/VictoriaMetrics/pull/3971).
* FEATURE: [vmui](https://docs.victoriametrics.com/#vmui): Hide messages longer than 3 lines in the trace. You can view the full message by clicking on the `show more` button. See [this pull request](https://github.com/VictoriaMetrics/VictoriaMetrics/pull/3971).
* FEATURE: [vmui](https://docs.victoriametrics.com/#vmui): Add the ability to manually input date and time when selecting a time range. See [this pull request](https://github.com/VictoriaMetrics/VictoriaMetrics/pull/3968).
* FEATURE: [vmctl](https://docs.victoriametrics.com/vmctl.html): `vmctl` check whether TTY is available and disable prompt automatically and progress bar when TTY not available. See [this issue](https://github.com/VictoriaMetrics/VictoriaMetrics/issues/3823).
* BUGFIX: prevent from slow [snapshot creating](https://docs.victoriametrics.com/#how-to-work-with-snapshots) under high data ingestion rate. See [this issue](https://github.com/VictoriaMetrics/VictoriaMetrics/issues/3551).