Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(cmd/inflxud): add support for writing to stdout in export-lp #21046

Merged
merged 3 commits into from
Mar 23, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
26 changes: 16 additions & 10 deletions cmd/influxd/inspect/export_lp.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
},
}

Expand Down Expand Up @@ -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,
},
{
Expand All @@ -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()
Expand All @@ -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()
Expand Down