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(onboard): remove extra multiplication of RP to avoid overflow #19885

Merged
merged 5 commits into from
Nov 3, 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 @@ -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]

Expand Down
2 changes: 2 additions & 0 deletions cmd/influxd/upgrade/database_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package upgrade

import (
"context"
"github.com/dustin/go-humanize"
"io/ioutil"
"net/http"
"net/url"
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion cmd/influxd/upgrade/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
4 changes: 1 addition & 3 deletions kv/onboarding.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import (
"context"
"errors"
"fmt"
"time"

"github.com/influxdata/influxdb/v2"
)

Expand Down Expand Up @@ -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,
Expand Down
4 changes: 1 addition & 3 deletions tenant/service_onboarding.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 {
Expand Down
29 changes: 29 additions & 0 deletions tenant/service_onboarding_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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")
}
2 changes: 1 addition & 1 deletion testing/onboarding.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down