fix(onboard): remove extra multiplication of RP to avoid overflow

Fixes #19884.
pull/19894/head
Dan Moran 2020-11-02 17:38:43 -05:00 committed by Daniel Moran
parent 9b78357bce
commit 64ef556c2b
2 changed files with 30 additions and 3 deletions

View File

@ -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 {

View File

@ -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")
}