feat(cmd/inflxud): add support for writing to stdout in `export-lp` (#21046)
parent
85c1bb8cd6
commit
4ef09e1ccb
|
@ -31,6 +31,7 @@ or `/query` HTTP endpoints.
|
|||
1. [20971](https://github.com/influxdata/influxdb/pull/20971): Set a default `--http-idle-timeout` of 3m in `influxd`.
|
||||
1. [20861](https://github.com/influxdata/influxdb/pull/20861): Update Telegraf plugins in UI to include additions and changes in 1.18 release.
|
||||
1. [20894](https://github.com/influxdata/influxdb/pull/20894): Display task IDs in the UI.
|
||||
1. [21046](https://github.com/influxdata/influxdb/pull/21046): Write to standard out when `--output-path -` is passed to `influxd inspect export-lp`.
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
|
|
|
@ -98,8 +98,8 @@ func NewExportLineProtocolCommand(v *viper.Viper) (*cobra.Command, error) {
|
|||
This command will export all TSM data stored in a bucket
|
||||
to line protocol for inspection and re-ingestion.`,
|
||||
Args: cobra.NoArgs,
|
||||
RunE: func(*cobra.Command, []string) error {
|
||||
return exportRunE(flags)
|
||||
RunE: func(cmd *cobra.Command, _ []string) error {
|
||||
return exportRunE(cmd, flags)
|
||||
},
|
||||
}
|
||||
|
||||
|
@ -134,7 +134,7 @@ to line protocol for inspection and re-ingestion.`,
|
|||
{
|
||||
DestP: &flags.outputPath,
|
||||
Flag: "output-path",
|
||||
Desc: "path where exported line-protocol should be written",
|
||||
Desc: "path where exported line-protocol should be written. Use '-' to write to standard out",
|
||||
Required: true,
|
||||
},
|
||||
{
|
||||
|
@ -155,7 +155,7 @@ to line protocol for inspection and re-ingestion.`,
|
|||
return cmd, nil
|
||||
}
|
||||
|
||||
func exportRunE(flags *exportFlags) error {
|
||||
func exportRunE(cmd *cobra.Command, flags *exportFlags) error {
|
||||
logconf := zap.NewProductionConfig()
|
||||
logconf.Level = zap.NewAtomicLevelAt(flags.logLevel)
|
||||
logger, err := logconf.Build()
|
||||
|
@ -168,19 +168,25 @@ func exportRunE(flags *exportFlags) error {
|
|||
return err
|
||||
}
|
||||
|
||||
f, err := os.Create(flags.outputPath)
|
||||
if err != nil {
|
||||
return err
|
||||
var w io.Writer
|
||||
if flags.outputPath == "-" {
|
||||
w = cmd.OutOrStdout()
|
||||
} else {
|
||||
f, err := os.Create(flags.outputPath)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer f.Close()
|
||||
w = f
|
||||
}
|
||||
defer f.Close()
|
||||
|
||||
// Because calling (*os.File).Write is relatively expensive,
|
||||
// and we don't *need* to sync to disk on every written line of export,
|
||||
// use a sized buffered writer so that we only sync the file every megabyte.
|
||||
bw := bufio.NewWriterSize(f, 1024*1024)
|
||||
bw := bufio.NewWriterSize(w, 1024*1024)
|
||||
defer bw.Flush()
|
||||
w = bw
|
||||
|
||||
var w io.Writer = bw
|
||||
if flags.compress {
|
||||
gzw := gzip.NewWriter(w)
|
||||
defer gzw.Close()
|
||||
|
|
Loading…
Reference in New Issue