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

fix(influx): have delete cmd respect the config settings #18345

Merged
merged 1 commit into from
Jun 2, 2020
Merged
Show file tree
Hide file tree
Changes from all 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 @@ -10,6 +10,7 @@

1. [18331](https://github.com/influxdata/influxdb/pull/18331): Support organization name in addition to ID in DBRP operations
1. [18335](https://github.com/influxdata/influxdb/pull/18335): Disable failing when providing an unexpected error to influx CLI
1. [18345](https://github.com/influxdata/influxdb/pull/18345): Have influx delete cmd respect the config

## v2.0.0-beta.11 [2020-05-26]

Expand Down
47 changes: 32 additions & 15 deletions cmd/influx/delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,36 +9,49 @@ import (
"github.com/spf13/cobra"
)

var deleteFlags http.DeleteRequest

func cmdDelete(f *globalFlags, opt genericCLIOpts) *cobra.Command {
cmd := opt.newCmd("delete", fluxDeleteF, true)
builder := &cmdDeleteBuilder{
genericCLIOpts: opt,
globalFlags: f,
}
return builder.cmd()
}

type cmdDeleteBuilder struct {
genericCLIOpts
*globalFlags

flags http.DeleteRequest
}

func (b *cmdDeleteBuilder) cmd() *cobra.Command {
cmd := b.newCmd("delete", b.fluxDeleteF, true)
cmd.Short = "Delete points from influxDB"
cmd.Long = `Delete points from influxDB, by specify start, end time
and a sql like predicate string.`

opts := flagOpts{
{
DestP: &deleteFlags.OrgID,
DestP: &b.flags.OrgID,
Flag: "org-id",
Desc: "The ID of the organization that owns the bucket",
Persistent: true,
},
{
DestP: &deleteFlags.Org,
DestP: &b.flags.Org,
Flag: "org",
Short: 'o',
Desc: "The name of the organization that owns the bucket",
Persistent: true,
},
{
DestP: &deleteFlags.BucketID,
DestP: &b.flags.BucketID,
Flag: "bucket-id",
Desc: "The ID of the destination bucket",
Persistent: true,
},
{
DestP: &deleteFlags.Bucket,
DestP: &b.flags.Bucket,
Flag: "bucket",
Desc: "The name of destination bucket",
EnvVar: "BUCKET_NAME",
Expand All @@ -47,23 +60,27 @@ func cmdDelete(f *globalFlags, opt genericCLIOpts) *cobra.Command {
}
opts.mustRegister(cmd)

cmd.PersistentFlags().StringVar(&deleteFlags.Start, "start", "", "the start time in RFC3339Nano format, exp 2009-01-02T23:00:00Z")
cmd.PersistentFlags().StringVar(&deleteFlags.Stop, "stop", "", "the stop time in RFC3339Nano format, exp 2009-01-02T23:00:00Z")
cmd.PersistentFlags().StringVarP(&deleteFlags.Predicate, "predicate", "p", "", "sql like predicate string, exp 'tag1=\"v1\" and (tag2=123)'")
cmd.PersistentFlags().StringVar(&b.flags.Start, "start", "", "the start time in RFC3339Nano format, exp 2009-01-02T23:00:00Z")
cmd.PersistentFlags().StringVar(&b.flags.Stop, "stop", "", "the stop time in RFC3339Nano format, exp 2009-01-02T23:00:00Z")
cmd.PersistentFlags().StringVarP(&b.flags.Predicate, "predicate", "p", "", "sql like predicate string, exp 'tag1=\"v1\" and (tag2=123)'")

return cmd
}

func fluxDeleteF(cmd *cobra.Command, args []string) error {
if deleteFlags.Org == "" && deleteFlags.OrgID == "" {
func (b *cmdDeleteBuilder) fluxDeleteF(cmd *cobra.Command, args []string) error {
org := b.flags.Org
if org == "" {
org = b.globalFlags.Org
}
if org == "" && b.flags.OrgID == "" {
return fmt.Errorf("please specify one of org or org-id")
}

if deleteFlags.Bucket == "" && deleteFlags.BucketID == "" {
if b.flags.Bucket == "" && b.flags.BucketID == "" {
return fmt.Errorf("please specify one of bucket or bucket-id")
}

if deleteFlags.Start == "" || deleteFlags.Stop == "" {
if b.flags.Start == "" || b.flags.Stop == "" {
return fmt.Errorf("both start and stop are required")
}

Expand All @@ -74,7 +91,7 @@ func fluxDeleteF(cmd *cobra.Command, args []string) error {
}

ctx := signals.WithStandardSignals(context.Background())
if err := s.DeleteBucketRangePredicate(ctx, deleteFlags); err != nil && err != context.Canceled {
if err := s.DeleteBucketRangePredicate(ctx, b.flags); err != nil && err != context.Canceled {
return fmt.Errorf("failed to delete data: %v", err)
}

Expand Down