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/influx): allow setting shard-group durations for buckets via API and CLI #20911

Merged
merged 20 commits into from
Mar 11, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
a09639d
fix(cmd/influx): make shard duration configurable
Jan 23, 2021
a323bac
fix(cmd/influx): make shard duration configurable from command-line c…
Jan 24, 2021
76cf16b
fix(cmd/influx): make shard duration configurable from command-line c…
Jan 24, 2021
4ab0f73
fix(cmd/influx): added API documentation for shardGroupDuration field
Jan 25, 2021
0aa1927
fix(cmd/influx): shortened shard group duration column title in comma…
Jan 27, 2021
c10caf0
chore: update CHANGELOG
Jan 27, 2021
8ea0af4
fix(influx/cmd): reformatted bucket.go
Jan 27, 2021
cf59685
feat: refactor API based on review suggestions
danxmoran Mar 9, 2021
c17feba
test: fix existing test for updating RP
danxmoran Mar 9, 2021
5b753c8
fix: record ShardGroupDuration in bucket metadata, add backfill migra…
danxmoran Mar 9, 2021
d410020
fix: fix listing buckets with infinite retention
danxmoran Mar 9, 2021
db5da5b
chore: update CHANGELOG
danxmoran Mar 9, 2021
3c85d9d
fix: update input validation to fix tests
danxmoran Mar 10, 2021
93eca2c
test: add more tests for updating shard-group duration.
danxmoran Mar 10, 2021
74ba621
fix: add validation of shard-group duration values
danxmoran Mar 11, 2021
f989f89
test: add more test cases to bucket_service suite
danxmoran Mar 11, 2021
a23c7cb
test: add e2e case for updating both durations at once
danxmoran Mar 11, 2021
d65d99c
test: move HTTP-only validation tests out of common suite
danxmoran Mar 11, 2021
69c1df7
fix: use consistent terminology
danxmoran Mar 11, 2021
eff0ad5
test: add test for shard-group duration migration
danxmoran Mar 11, 2021
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
Prev Previous commit
Next Next commit
test: add more tests for updating shard-group duration.
  • Loading branch information
danxmoran committed Mar 11, 2021
commit 93eca2ca8ff6029d1b342b7a589c49cc5c425829
25 changes: 25 additions & 0 deletions cmd/influx/bucket_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,21 @@ func TestCmdBucket(t *testing.T) {
OrgID: orgID,
},
},
{
name: "with explicit shard-group duration",
flags: []string{
"-r=1h",
"--shard-group-duration=1m",
"-o=org name",
"-n=new name",
},
expectedBucket: influxdb.Bucket{
Name: "new name",
RetentionPeriod: time.Hour,
ShardGroupDuration: time.Minute,
OrgID: orgID,
},
},
}

cmdFn := func(expectedBkt influxdb.Bucket) func(*globalFlags, genericCLIOpts) *cobra.Command {
Expand Down Expand Up @@ -408,6 +423,16 @@ func TestCmdBucket(t *testing.T) {
RetentionPeriod: durPtr(time.Minute),
},
},
{
name: "shard-group duration",
flags: []string{
"-i=" + influxdb.ID(3).String(),
"--shard-group-duration=1m",
},
expected: influxdb.BucketUpdate{
ShardGroupDuration: durPtr(time.Minute),
},
},
}

cmdFn := func(expectedUpdate influxdb.BucketUpdate) func(*globalFlags, genericCLIOpts) *cobra.Command {
Expand Down
135 changes: 120 additions & 15 deletions cmd/influxd/launcher/storage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ import (
"testing"
"time"

"github.com/dustin/go-humanize"
"github.com/google/go-cmp/cmp"
"github.com/influxdata/influxdb/v2"
"github.com/influxdata/influxdb/v2/cmd/influxd/launcher"
"github.com/influxdata/influxdb/v2/http"
"github.com/influxdata/influxdb/v2/pkg/testing/assert"
"github.com/stretchr/testify/require"
)

Expand Down Expand Up @@ -200,20 +200,125 @@ func TestLauncher_DeleteWithPredicate(t *testing.T) {
}

func TestLauncher_UpdateRetentionPolicy(t *testing.T) {
l := launcher.RunAndSetupNewLauncherOrFail(ctx, t)
defer l.ShutdownOrFail(t, ctx)
durPtr := func(d time.Duration) *time.Duration {
return &d
}

bucket, err := l.BucketService(t).FindBucket(ctx, influxdb.BucketFilter{ID: &l.Bucket.ID})
require.NoError(t, err)
require.NotNil(t, bucket)
testCases := []struct {
name string
initRp time.Duration
initSgd time.Duration
derivedSgd *time.Duration
newRp *time.Duration
newSgd *time.Duration
expectInitErr bool
expectUpdateErr bool
}{
{
name: "infinite to 1w",
initRp: 0,
derivedSgd: durPtr(humanize.Week),
newRp: durPtr(humanize.Week),
},
{
name: "1w to 1d",
initRp: humanize.Week,
derivedSgd: durPtr(humanize.Day),
newRp: durPtr(humanize.Day),
},
{
name: "1d to 1h",
initRp: humanize.Day,
derivedSgd: durPtr(time.Hour),
newRp: durPtr(time.Hour),
},
{
name: "infinite, update shard duration",
initSgd: humanize.Month,
derivedSgd: durPtr(humanize.Month),
newSgd: durPtr(humanize.Week),
},
{
name: "1w, update shard duration",
initRp: humanize.Week,
initSgd: humanize.Week,
newSgd: durPtr(time.Hour),
},
{
name: "1d, update shard duration",
initRp: humanize.Day,
initSgd: 3 * time.Hour,
newSgd: durPtr(1*time.Hour + 30*time.Minute),
},
{
name: "init shard duration larger than RP",
initRp: time.Hour,
initSgd: humanize.Day,
expectInitErr: true,
},
{
name: "updated shard duration larger than RP",
initRp: humanize.Day,
initSgd: time.Hour,
newSgd: durPtr(humanize.Week),
expectUpdateErr: true,
},
}

newRetentionPeriod := 1 * time.Hour
newSgDuration := 1 * time.Hour
bucket, err = l.BucketService(t).UpdateBucket(ctx, bucket.ID, influxdb.BucketUpdate{
RetentionPeriod: &newRetentionPeriod,
ShardGroupDuration: &newSgDuration,
})
require.NoError(t, err)
assert.Equal(t, bucket.RetentionPeriod, newRetentionPeriod)
assert.Equal(t, bucket.ShardGroupDuration, newSgDuration)
for _, tc := range testCases {
tc := tc
t.Run(tc.name, func(t *testing.T) {
t.Parallel()

l := launcher.RunAndSetupNewLauncherOrFail(ctx, t)
defer l.ShutdownOrFail(t, ctx)
bucketService := l.BucketService(t)

bucket := &influxdb.Bucket{
OrgID: l.Org.ID,
RetentionPeriod: tc.initRp,
ShardGroupDuration: tc.initSgd,
}
err := bucketService.CreateBucket(ctx, bucket)
if tc.expectInitErr {
require.Error(t, err)
return
}
require.NoError(t, err)
defer bucketService.DeleteBucket(ctx, bucket.ID)

bucket, err = bucketService.FindBucketByID(ctx, bucket.ID)
require.NoError(t, err)

expectedSgd := tc.initSgd
if tc.derivedSgd != nil {
expectedSgd = *tc.derivedSgd
}
require.Equal(t, tc.initRp, bucket.RetentionPeriod)
require.Equal(t, expectedSgd, bucket.ShardGroupDuration)

bucket, err = bucketService.UpdateBucket(ctx, bucket.ID, influxdb.BucketUpdate{
RetentionPeriod: tc.newRp,
ShardGroupDuration: tc.newSgd,
})
if tc.expectUpdateErr {
require.Error(t, err)
return
}
require.NoError(t, err)

bucket, err = bucketService.FindBucketByID(ctx, bucket.ID)
require.NoError(t, err)

expectedRp := tc.initRp
if tc.newRp != nil {
expectedRp = *tc.newRp
}
if tc.newSgd != nil {
expectedSgd = *tc.newSgd
}
require.Equal(t, expectedRp, bucket.RetentionPeriod)
require.Equal(t, expectedSgd, bucket.ShardGroupDuration)
})
}
}