diff --git a/CHANGELOG.md b/CHANGELOG.md index d7b25481ffb..9d5ea37b196 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ 1. [19856](https://github.com/influxdata/influxdb/pull/19856): make tagKeys and tagValues work for edge cases involving _field 1. [19853](https://github.com/influxdata/influxdb/pull/19853): Use updated HTTP client for authorization service 1. [19886](https://github.com/influxdata/influxdb/pull/19886): Add Logger to constructor function to ensure log field is initialized +1. [19885](https://github.com/influxdata/influxdb/pull/19885): Remove extra multiplication of retention policies in onboarding ## v2.0.0-rc.3 [2020-10-29] diff --git a/cmd/influxd/upgrade/database_test.go b/cmd/influxd/upgrade/database_test.go index 949d4791f42..8238d6aba28 100644 --- a/cmd/influxd/upgrade/database_test.go +++ b/cmd/influxd/upgrade/database_test.go @@ -2,6 +2,7 @@ package upgrade import ( "context" + "github.com/dustin/go-humanize" "io/ioutil" "net/http" "net/url" @@ -62,6 +63,7 @@ func TestUpgradeRealDB(t *testing.T) { options.target = *v2opts req, err := nonInteractive() require.Nil(t, err) + assert.Equal(t, req.RetentionPeriod, humanize.Week, "Retention policy should pass through") resp, err := setupAdmin(ctx, v2, req) require.Nil(t, err) diff --git a/cmd/influxd/upgrade/setup.go b/cmd/influxd/upgrade/setup.go index 2343ea0df20..5c9c9d426c7 100644 --- a/cmd/influxd/upgrade/setup.go +++ b/cmd/influxd/upgrade/setup.go @@ -54,7 +54,7 @@ func nonInteractive() (*influxdb.OnboardingRequest, error) { return nil, err } if dur > 0 { - req.RetentionPeriod = dur / time.Hour + req.RetentionPeriod = dur } return req, nil } diff --git a/kv/onboarding.go b/kv/onboarding.go index e2ddebe7c40..80647cd5fb9 100644 --- a/kv/onboarding.go +++ b/kv/onboarding.go @@ -4,8 +4,6 @@ import ( "context" "errors" "fmt" - "time" - "github.com/influxdata/influxdb/v2" ) @@ -112,7 +110,7 @@ func (s *Service) OnboardInitialUser(ctx context.Context, req *influxdb.Onboardi o := &influxdb.Organization{Name: req.Org} bucket := &influxdb.Bucket{ Name: req.Bucket, - RetentionPeriod: time.Duration(req.RetentionPeriod) * time.Hour, + RetentionPeriod: req.RetentionPeriod, } mapping := &influxdb.UserResourceMapping{ ResourceType: influxdb.OrgsResourceType, diff --git a/tenant/service_onboarding.go b/tenant/service_onboarding.go index 2ad92d76ec6..59fdfa5e58a 100644 --- a/tenant/service_onboarding.go +++ b/tenant/service_onboarding.go @@ -3,8 +3,6 @@ package tenant import ( "context" "fmt" - "time" - "github.com/influxdata/influxdb/v2" icontext "github.com/influxdata/influxdb/v2/context" "github.com/influxdata/influxdb/v2/kv" @@ -122,7 +120,7 @@ func (s *OnboardService) onboardUser(ctx context.Context, req *influxdb.Onboardi OrgID: org.ID, Name: req.Bucket, Type: influxdb.BucketTypeUser, - RetentionPeriod: time.Duration(req.RetentionPeriod) * time.Hour, + RetentionPeriod: req.RetentionPeriod, } if err := s.service.CreateBucket(ctx, ub); err != nil { diff --git a/tenant/service_onboarding_test.go b/tenant/service_onboarding_test.go index 569a6b226b4..cfbdb1b7562 100644 --- a/tenant/service_onboarding_test.go +++ b/tenant/service_onboarding_test.go @@ -2,7 +2,9 @@ package tenant_test import ( "context" + "github.com/influxdata/influxdb/v2/pkg/testing/assert" "testing" + "time" "github.com/google/go-cmp/cmp" @@ -154,3 +156,30 @@ func TestOnboardAuth(t *testing.T) { } } + +func TestOnboardService_RetentionPolicy(t *testing.T) { + s, _, _ := NewTestInmemStore(t) + storage := tenant.NewStore(s) + ten := tenant.NewService(storage) + + // we will need an auth service as well + svc := tenant.NewOnboardService(ten, kv.NewService(zaptest.NewLogger(t), s)) + + ctx := icontext.SetAuthorizer(context.Background(), &influxdb.Authorization{ + UserID: 123, + }) + + retention := 72 * time.Hour + onboard, err := svc.OnboardInitialUser(ctx, &influxdb.OnboardingRequest{ + User: "name", + Org: "name", + Bucket: "name", + RetentionPeriod: retention, + }) + + if err != nil { + t.Fatal(err) + } + + assert.Equal(t, onboard.Bucket.RetentionPeriod, retention, "Retention policy should pass through") +} diff --git a/testing/onboarding.go b/testing/onboarding.go index d60800dcc0c..214745a5d33 100644 --- a/testing/onboarding.go +++ b/testing/onboarding.go @@ -158,7 +158,7 @@ func OnboardInitialUser( Org: "org1", Bucket: "bucket1", Password: "password1", - RetentionPeriod: 24 * 7, // 1 week + RetentionPeriod: time.Hour * 24 * 7, // 1 week }, }, wants: wants{