Skip to content

Commit

Permalink
chore: delete old-style DBRP mapping (#22339)
Browse files Browse the repository at this point in the history
  • Loading branch information
danxmoran committed Aug 30, 2021
1 parent f251415 commit cc6accf
Show file tree
Hide file tree
Showing 48 changed files with 1,647 additions and 2,990 deletions.
2 changes: 1 addition & 1 deletion authorizer/authorize_find.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
)

// AuthorizeFindDBRPs takes the given items and returns only the ones that the user is authorized to access.
func AuthorizeFindDBRPs(ctx context.Context, rs []*influxdb.DBRPMappingV2) ([]*influxdb.DBRPMappingV2, int, error) {
func AuthorizeFindDBRPs(ctx context.Context, rs []*influxdb.DBRPMapping) ([]*influxdb.DBRPMapping, int, error) {
// This filters without allocating
// https://github.com/golang/go/wiki/SliceTricks#filtering-without-allocating
rrs := rs[:0]
Expand Down
2 changes: 1 addition & 1 deletion cmd/influxd/launcher/launcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -1257,7 +1257,7 @@ func (m *Launcher) CheckService() platform.CheckService {
return m.apibackend.CheckService
}

func (m *Launcher) DBRPMappingServiceV2() platform.DBRPMappingServiceV2 {
func (m *Launcher) DBRPMappingService() platform.DBRPMappingService {
return m.apibackend.DBRPService
}

Expand Down
2 changes: 1 addition & 1 deletion cmd/influxd/upgrade/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ func upgradeDatabases(ctx context.Context, cli clients.CLI, v1 *influxDBv1, v2 *
return nil, fmt.Errorf("error creating database %s: %w", bucket.ID.String(), err)
}

mapping := &influxdb.DBRPMappingV2{
mapping := &influxdb.DBRPMapping{
Database: db.Name,
RetentionPolicy: rp.Name,
Default: db.DefaultRetentionPolicy == rp.Name,
Expand Down
2 changes: 1 addition & 1 deletion cmd/influxd/upgrade/upgrade.go
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ type influxDBv2 struct {
kvStore kv.SchemaStore
tenantStore *tenant.Store
ts *tenant.Service
dbrpSvc influxdb.DBRPMappingServiceV2
dbrpSvc influxdb.DBRPMappingService
bucketSvc influxdb.BucketService
onboardSvc influxdb.OnboardingService
authSvc *authv1.Service
Expand Down
2 changes: 1 addition & 1 deletion cmd/influxd/upgrade/v2_dump_meta.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ var v2DumpMetaCommand = &cobra.Command{
fmt.Fprintln(os.Stdout, "Mappings")
fmt.Fprintln(os.Stdout, "---------")
fmt.Fprintf(tw, "%s\t%s\t%s\t%s\t%s\n", "Database", "RP", "Org", "Bucket", "Default")
mappings, _, err := svc.dbrpSvc.FindMany(ctx, influxdb.DBRPMappingFilterV2{})
mappings, _, err := svc.dbrpSvc.FindMany(ctx, influxdb.DBRPMappingFilter{})
if err != nil {
return err
}
Expand Down
6 changes: 3 additions & 3 deletions dbrp/bucket_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ import (
type BucketService struct {
influxdb.BucketService
Logger *zap.Logger
DBRPMappingService influxdb.DBRPMappingServiceV2
DBRPMappingService influxdb.DBRPMappingService
}

func NewBucketService(logger *zap.Logger, bucketService influxdb.BucketService, dbrpService influxdb.DBRPMappingServiceV2) *BucketService {
func NewBucketService(logger *zap.Logger, bucketService influxdb.BucketService, dbrpService influxdb.DBRPMappingService) *BucketService {
return &BucketService{
Logger: logger,
BucketService: bucketService,
Expand All @@ -33,7 +33,7 @@ func (s *BucketService) DeleteBucket(ctx context.Context, id platform.ID) error
}

logger := s.Logger.With(zap.String("bucket_id", id.String()))
mappings, _, err := s.DBRPMappingService.FindMany(ctx, influxdb.DBRPMappingFilterV2{
mappings, _, err := s.DBRPMappingService.FindMany(ctx, influxdb.DBRPMappingFilter{
OrgID: &bucket.OrgID,
BucketID: &bucket.ID,
})
Expand Down
6 changes: 3 additions & 3 deletions dbrp/bucket_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func TestBucketService(t *testing.T) {

logger = zap.NewNop()
bucketServiceMock = mocks.NewMockBucketService(ctrl)
dbrpService = mocks.NewMockDBRPMappingServiceV2(ctrl)
dbrpService = mocks.NewMockDBRPMappingService(ctrl)

bucket = &influxdb.Bucket{
ID: bucketID,
Expand All @@ -42,10 +42,10 @@ func TestBucketService(t *testing.T) {
Return(nil)

findMapping := dbrpService.EXPECT().
FindMany(gomock.Any(), influxdb.DBRPMappingFilterV2{
FindMany(gomock.Any(), influxdb.DBRPMappingFilter{
BucketID: &bucketID,
OrgID: &orgID,
}).Return([]*influxdb.DBRPMappingV2{
}).Return([]*influxdb.DBRPMapping{
{ID: mappingID},
}, 1, nil)
deleteMapping := dbrpService.EXPECT().
Expand Down
14 changes: 7 additions & 7 deletions dbrp/http_client_dbrp.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
"github.com/influxdata/influxdb/v2/pkg/httpc"
)

var _ influxdb.DBRPMappingServiceV2 = (*Client)(nil)
var _ influxdb.DBRPMappingService = (*Client)(nil)

// Client connects to Influx via HTTP using tokens to manage DBRPs.
type Client struct {
Expand All @@ -32,7 +32,7 @@ func (c *Client) dbrpURL(id platform.ID) string {
return path.Join(c.Prefix, id.String())
}

func (c *Client) FindByID(ctx context.Context, orgID, id platform.ID) (*influxdb.DBRPMappingV2, error) {
func (c *Client) FindByID(ctx context.Context, orgID, id platform.ID) (*influxdb.DBRPMapping, error) {
span, _ := tracing.StartSpanFromContext(ctx)
defer span.Finish()

Expand All @@ -47,7 +47,7 @@ func (c *Client) FindByID(ctx context.Context, orgID, id platform.ID) (*influxdb
return resp.Content, nil
}

func (c *Client) FindMany(ctx context.Context, filter influxdb.DBRPMappingFilterV2, opts ...influxdb.FindOptions) ([]*influxdb.DBRPMappingV2, int, error) {
func (c *Client) FindMany(ctx context.Context, filter influxdb.DBRPMappingFilter, opts ...influxdb.FindOptions) ([]*influxdb.DBRPMapping, int, error) {
span, _ := tracing.StartSpanFromContext(ctx)
defer span.Finish()

Expand Down Expand Up @@ -84,11 +84,11 @@ func (c *Client) FindMany(ctx context.Context, filter influxdb.DBRPMappingFilter
return resp.Content, len(resp.Content), nil
}

func (c *Client) Create(ctx context.Context, dbrp *influxdb.DBRPMappingV2) error {
func (c *Client) Create(ctx context.Context, dbrp *influxdb.DBRPMapping) error {
span, _ := tracing.StartSpanFromContext(ctx)
defer span.Finish()

var newDBRP influxdb.DBRPMappingV2
var newDBRP influxdb.DBRPMapping
if err := c.Client.
PostJSON(createDBRPRequest{
Database: dbrp.Database,
Expand All @@ -105,15 +105,15 @@ func (c *Client) Create(ctx context.Context, dbrp *influxdb.DBRPMappingV2) error
return nil
}

func (c *Client) Update(ctx context.Context, dbrp *influxdb.DBRPMappingV2) error {
func (c *Client) Update(ctx context.Context, dbrp *influxdb.DBRPMapping) error {
span, _ := tracing.StartSpanFromContext(ctx)
defer span.Finish()

if err := dbrp.Validate(); err != nil {
return err
}

var newDBRP influxdb.DBRPMappingV2
var newDBRP influxdb.DBRPMapping
if err := c.Client.
PatchJSON(dbrp, c.dbrpURL(dbrp.ID)).
QueryParams([2]string{"orgID", dbrp.OrganizationID.String()}).
Expand Down
18 changes: 9 additions & 9 deletions dbrp/http_client_dbrp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ import (

func setup(t *testing.T) (*dbrp.Client, func()) {
t.Helper()
dbrpSvc := &mock.DBRPMappingServiceV2{
CreateFn: func(ctx context.Context, dbrp *influxdb.DBRPMappingV2) error {
dbrpSvc := &mock.DBRPMappingService{
CreateFn: func(ctx context.Context, dbrp *influxdb.DBRPMapping) error {
dbrp.ID = 1
return nil
},
FindByIDFn: func(ctx context.Context, orgID, id platform.ID) (*influxdb.DBRPMappingV2, error) {
return &influxdb.DBRPMappingV2{
FindByIDFn: func(ctx context.Context, orgID, id platform.ID) (*influxdb.DBRPMapping, error) {
return &influxdb.DBRPMapping{
ID: id,
Database: "db",
RetentionPolicy: "rp",
Expand All @@ -31,8 +31,8 @@ func setup(t *testing.T) (*dbrp.Client, func()) {
BucketID: 1,
}, nil
},
FindManyFn: func(ctx context.Context, dbrp influxdb.DBRPMappingFilterV2, opts ...influxdb.FindOptions) ([]*influxdb.DBRPMappingV2, int, error) {
return []*influxdb.DBRPMappingV2{}, 0, nil
FindManyFn: func(ctx context.Context, dbrp influxdb.DBRPMappingFilter, opts ...influxdb.FindOptions) ([]*influxdb.DBRPMapping, int, error) {
return []*influxdb.DBRPMapping{}, 0, nil
},
}
orgSvc := &mock.OrganizationService{
Expand Down Expand Up @@ -60,7 +60,7 @@ func TestClient(t *testing.T) {
client, shutdown := setup(t)
defer shutdown()

if err := client.Create(context.Background(), &influxdb.DBRPMappingV2{
if err := client.Create(context.Background(), &influxdb.DBRPMapping{
Database: "db",
RetentionPolicy: "rp",
Default: false,
Expand All @@ -79,7 +79,7 @@ func TestClient(t *testing.T) {
t.Error(err)
}
oid := platform.ID(1)
if _, _, err := client.FindMany(context.Background(), influxdb.DBRPMappingFilterV2{OrgID: &oid}); err != nil {
if _, _, err := client.FindMany(context.Background(), influxdb.DBRPMappingFilter{OrgID: &oid}); err != nil {
t.Error(err)
}
})
Expand All @@ -88,7 +88,7 @@ func TestClient(t *testing.T) {
client, shutdown := setup(t)
defer shutdown()

if err := client.Update(context.Background(), &influxdb.DBRPMappingV2{
if err := client.Update(context.Background(), &influxdb.DBRPMapping{
ID: 1,
Database: "db",
RetentionPolicy: "rp",
Expand Down
14 changes: 7 additions & 7 deletions dbrp/http_server_dbrp.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ type Handler struct {
chi.Router
api *kithttp.API
log *zap.Logger
dbrpSvc influxdb.DBRPMappingServiceV2
dbrpSvc influxdb.DBRPMappingService
orgSvc influxdb.OrganizationService
}

// NewHTTPHandler constructs a new http server.
func NewHTTPHandler(log *zap.Logger, dbrpSvc influxdb.DBRPMappingServiceV2, orgSvc influxdb.OrganizationService) *Handler {
func NewHTTPHandler(log *zap.Logger, dbrpSvc influxdb.DBRPMappingService, orgSvc influxdb.OrganizationService) *Handler {
h := &Handler{
api: kithttp.NewAPI(kithttp.WithLog(log)),
log: log,
Expand Down Expand Up @@ -114,7 +114,7 @@ func (h *Handler) handlePostDBRP(w http.ResponseWriter, r *http.Request) {
return
}

dbrp := &influxdb.DBRPMappingV2{
dbrp := &influxdb.DBRPMapping{
Database: req.Database,
RetentionPolicy: req.RetentionPolicy,
Default: req.Default,
Expand All @@ -129,7 +129,7 @@ func (h *Handler) handlePostDBRP(w http.ResponseWriter, r *http.Request) {
}

type getDBRPsResponse struct {
Content []*influxdb.DBRPMappingV2 `json:"content"`
Content []*influxdb.DBRPMapping `json:"content"`
}

func (h *Handler) handleGetDBRPs(w http.ResponseWriter, r *http.Request) {
Expand All @@ -150,7 +150,7 @@ func (h *Handler) handleGetDBRPs(w http.ResponseWriter, r *http.Request) {
}

type getDBRPResponse struct {
Content *influxdb.DBRPMappingV2 `json:"content"`
Content *influxdb.DBRPMapping `json:"content"`
}

func (h *Handler) handleGetDBRP(w http.ResponseWriter, r *http.Request) {
Expand Down Expand Up @@ -244,7 +244,7 @@ func (h *Handler) handlePatchDBRP(w http.ResponseWriter, r *http.Request) {
}

h.api.Respond(w, r, http.StatusOK, struct {
Content *influxdb.DBRPMappingV2 `json:"content"`
Content *influxdb.DBRPMapping `json:"content"`
}{
Content: dbrp,
})
Expand Down Expand Up @@ -281,7 +281,7 @@ func (h *Handler) handleDeleteDBRP(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusNoContent)
}

func (h *Handler) getFilterFromHTTPRequest(r *http.Request) (f influxdb.DBRPMappingFilterV2, err error) {
func (h *Handler) getFilterFromHTTPRequest(r *http.Request) (f influxdb.DBRPMappingFilter, err error) {
// Always provide OrgID.
f.OrgID, err = h.mustGetOrgIDFromHTTPRequest(r)
if err != nil {
Expand Down
Loading

0 comments on commit cc6accf

Please sign in to comment.