From bcbb7c997c653daeb64675510099ed0f84de9e5c Mon Sep 17 00:00:00 2001 From: Dan Moran Date: Tue, 23 Mar 2021 14:16:26 -0400 Subject: [PATCH 1/2] feat(cmd/inflxud): add support for writing to stdout in `export-lp` --- cmd/influxd/inspect/export_lp.go | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/cmd/influxd/inspect/export_lp.go b/cmd/influxd/inspect/export_lp.go index c04938adf84..8f329be9fd3 100644 --- a/cmd/influxd/inspect/export_lp.go +++ b/cmd/influxd/inspect/export_lp.go @@ -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() From 9cbbe278f3bcac672807eda84a4b4d6a2a654c76 Mon Sep 17 00:00:00 2001 From: Dan Moran Date: Tue, 23 Mar 2021 14:20:51 -0400 Subject: [PATCH 2/2] chore: update CHANGELOG --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index f826fd9dbe5..6430fbec3d8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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