Skip to content

Commit

Permalink
chore(inmem): nuke the duplicative inmem store
Browse files Browse the repository at this point in the history
use kv store... its a thing
  • Loading branch information
jsteenb2 committed Dec 30, 2019
1 parent a207147 commit e6f1805
Show file tree
Hide file tree
Showing 42 changed files with 74 additions and 3,526 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
1. [16341](https://github.com/influxdata/influxdb/pull/16341): Extend pkger apply functionality with ability to provide secrets outside of pkg
1. [16345](https://github.com/influxdata/influxdb/pull/16345): Add hide headers flag to influx cli task find cmd
1. [16336](https://github.com/influxdata/influxdb/pull/16336): Manual Overrides for Readiness Endpoint
1. [16347](https://github.com/influxdata/influxdb/pull/16347): Drop legacy inmem service implementation in favor of kv service with inmem dependency

### Bug Fixes

Expand Down
22 changes: 16 additions & 6 deletions authorizer/task_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
pctx "github.com/influxdata/influxdb/context"
"github.com/influxdata/influxdb/http"
"github.com/influxdata/influxdb/inmem"
"github.com/influxdata/influxdb/kv"
"github.com/influxdata/influxdb/mock"
_ "github.com/influxdata/influxdb/query/builtin"
"github.com/influxdata/influxdb/task/backend"
Expand All @@ -18,7 +19,7 @@ import (
)

func TestOnboardingValidation(t *testing.T) {
svc := inmem.NewService()
svc := newKVSVC(t)
ts := authorizer.NewTaskService(zaptest.NewLogger(t), mockTaskService(3, 2, 1))

r, err := svc.Generate(context.Background(), &influxdb.OnboardingRequest{
Expand All @@ -28,7 +29,6 @@ func TestOnboardingValidation(t *testing.T) {
Bucket: "holder",
RetentionPeriod: 1,
})

if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -120,9 +120,9 @@ func TestValidations(t *testing.T) {
otherOrg = &influxdb.Organization{Name: "other_org"}
)

inmem := inmem.NewService()
svc := newKVSVC(t)

r, err := inmem.Generate(context.Background(), &influxdb.OnboardingRequest{
r, err := svc.Generate(context.Background(), &influxdb.OnboardingRequest{
User: "Setec Astronomy",
Password: "too many secrets",
Org: "thing",
Expand All @@ -133,7 +133,7 @@ func TestValidations(t *testing.T) {
t.Fatal(err)
}

if err := inmem.CreateOrganization(context.Background(), otherOrg); err != nil {
if err := svc.CreateOrganization(context.Background(), otherOrg); err != nil {
t.Fatal(err)
}

Expand All @@ -142,7 +142,7 @@ func TestValidations(t *testing.T) {
OrgID: otherOrg.ID,
}

if err = inmem.CreateBucket(context.Background(), otherBucket); err != nil {
if err = svc.CreateBucket(context.Background(), otherBucket); err != nil {
t.Fatal(err)
}

Expand Down Expand Up @@ -571,3 +571,13 @@ from(bucket:"holder") |> range(start:-5m) |> to(bucket:"holder", org:"thing")`
})
}
}

func newKVSVC(t *testing.T) *kv.Service {
t.Helper()

svc := kv.NewService(zaptest.NewLogger(t), inmem.NewKVStore())
if err := svc.Initialize(context.Background()); err != nil {
t.Fatal(err)
}
return svc
}
2 changes: 1 addition & 1 deletion crud_log.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func (log *CRUDLog) SetCreatedAt(now time.Time) {
log.CreatedAt = now
}

// SetUpdated set the updated time.
// SetUpdatedAt set the updated time.
func (log *CRUDLog) SetUpdatedAt(now time.Time) {
log.UpdatedAt = now
}
Expand Down
2 changes: 1 addition & 1 deletion http/auth_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -935,7 +935,7 @@ func initAuthorizationService(f platformtesting.AuthorizationFields, t *testing.

done := server.Close

return &AuthorizationService{Client: httpClient}, inmem.OpPrefix, done
return &AuthorizationService{Client: httpClient}, "", done
}

func TestAuthorizationService_CreateAuthorization(t *testing.T) {
Expand Down
5 changes: 2 additions & 3 deletions http/bucket_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1204,12 +1204,11 @@ func initBucketService(f platformtesting.BucketFields, t *testing.T) (platform.B
handler := NewBucketHandler(zaptest.NewLogger(t), bucketBackend)
server := httptest.NewServer(handler)
client := BucketService{
Client: mustNewHTTPClient(t, server.URL, ""),
OpPrefix: inmem.OpPrefix,
Client: mustNewHTTPClient(t, server.URL, ""),
}
done := server.Close

return &client, inmem.OpPrefix, done
return &client, "", done
}

func TestBucketService(t *testing.T) {
Expand Down
19 changes: 14 additions & 5 deletions http/dashboard_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"github.com/influxdata/httprouter"
platform "github.com/influxdata/influxdb"
"github.com/influxdata/influxdb/inmem"
"github.com/influxdata/influxdb/kv"
"github.com/influxdata/influxdb/mock"
platformtesting "github.com/influxdata/influxdb/testing"
"github.com/yudai/gojsondiff"
Expand Down Expand Up @@ -1755,9 +1756,8 @@ func Test_dashboardCellIDPath(t *testing.T) {

func initDashboardService(f platformtesting.DashboardFields, t *testing.T) (platform.DashboardService, string, func()) {
t.Helper()
svc := inmem.NewService()
svc := newInMemKVSVC(t)
svc.IDGenerator = f.IDGenerator
svc.TimeGenerator = f.TimeGenerator
ctx := context.Background()
for _, d := range f.Dashboards {
if err := svc.PutDashboard(ctx, d); err != nil {
Expand All @@ -1772,14 +1772,13 @@ func initDashboardService(f platformtesting.DashboardFields, t *testing.T) (plat
server := httptest.NewServer(h)

client := DashboardService{Client: mustNewHTTPClient(t, server.URL, "")}
done := server.Close

return &client, inmem.OpPrefix, done
return &client, "", server.Close
}

func TestDashboardService(t *testing.T) {
t.Parallel()
platformtesting.DashboardService(initDashboardService, t)
platformtesting.DeleteDashboard(initDashboardService, t)
}

func TestService_handlePostDashboardLabel(t *testing.T) {
Expand Down Expand Up @@ -1917,3 +1916,13 @@ func jsonEqual(s1, s2 string) (eq bool, diff string, err error) {

return cmp.Equal(o1, o2), diff, err
}

func newInMemKVSVC(t *testing.T) *kv.Service {
t.Helper()

svc := kv.NewService(zaptest.NewLogger(t), inmem.NewKVStore())
if err := svc.Initialize(context.Background()); err != nil {
t.Fatal(err)
}
return svc
}
5 changes: 2 additions & 3 deletions http/label_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -617,12 +617,11 @@ func initLabelService(f platformtesting.LabelFields, t *testing.T) (platform.Lab
handler := NewLabelHandler(zaptest.NewLogger(t), svc, ErrorHandler(0))
server := httptest.NewServer(handler)
client := LabelService{
Client: mustNewHTTPClient(t, server.URL, ""),
OpPrefix: inmem.OpPrefix,
Client: mustNewHTTPClient(t, server.URL, ""),
}
done := server.Close

return &client, inmem.OpPrefix, done
return &client, "", done
}

func TestLabelService(t *testing.T) {
Expand Down
5 changes: 2 additions & 3 deletions http/org_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,11 @@ func initOrganizationService(f platformtesting.OrganizationFields, t *testing.T)
handler := NewOrgHandler(zaptest.NewLogger(t), orgBackend)
server := httptest.NewServer(handler)
client := OrganizationService{
Client: mustNewHTTPClient(t, server.URL, ""),
OpPrefix: inmem.OpPrefix,
Client: mustNewHTTPClient(t, server.URL, ""),
}
done := server.Close

return &client, inmem.OpPrefix, done
return &client, "", done
}

func TestOrganizationService(t *testing.T) {
Expand Down
7 changes: 3 additions & 4 deletions http/query_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import (
platform "github.com/influxdata/influxdb"
icontext "github.com/influxdata/influxdb/context"
"github.com/influxdata/influxdb/http/metric"
"github.com/influxdata/influxdb/inmem"
"github.com/influxdata/influxdb/kit/check"
tracetesting "github.com/influxdata/influxdb/kit/tracing/testing"
influxmock "github.com/influxdata/influxdb/mock"
Expand Down Expand Up @@ -324,12 +323,12 @@ var _ metric.EventRecorder = noopEventRecorder{}
func TestFluxHandler_PostQuery_Errors(t *testing.T) {
defer tracetesting.SetupInMemoryTracing(t.Name())()

i := inmem.NewService()
orgSVC := newInMemKVSVC(t)
b := &FluxBackend{
HTTPErrorHandler: ErrorHandler(0),
log: zaptest.NewLogger(t),
QueryEventRecorder: noopEventRecorder{},
OrganizationService: i,
OrganizationService: orgSVC,
ProxyQueryService: &mock.ProxyQueryService{
QueryF: func(ctx context.Context, w io.Writer, req *query.ProxyRequest) (flux.Statistics, error) {
return flux.Statistics{}, &influxdb.Error{
Expand Down Expand Up @@ -409,7 +408,7 @@ func TestFluxHandler_PostQuery_Errors(t *testing.T) {

t.Run("valid request but executing query results in client error", func(t *testing.T) {
org := influxdb.Organization{Name: t.Name()}
if err := i.CreateOrganization(context.Background(), &org); err != nil {
if err := orgSVC.CreateOrganization(context.Background(), &org); err != nil {
t.Fatal(err)
}

Expand Down
12 changes: 5 additions & 7 deletions http/scraper_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import (
"github.com/influxdata/influxdb"
platcontext "github.com/influxdata/influxdb/context"
httpMock "github.com/influxdata/influxdb/http/mock"
"github.com/influxdata/influxdb/inmem"
"github.com/influxdata/influxdb/mock"
platformtesting "github.com/influxdata/influxdb/testing"
"go.uber.org/zap/zaptest"
Expand Down Expand Up @@ -814,7 +813,7 @@ func TestService_handlePatchScraperTarget(t *testing.T) {

func initScraperService(f platformtesting.TargetFields, t *testing.T) (influxdb.ScraperTargetStoreService, string, func()) {
t.Helper()
svc := inmem.NewService()
svc := newInMemKVSVC(t)
svc.IDGenerator = f.IDGenerator

ctx := context.Background()
Expand All @@ -824,7 +823,7 @@ func initScraperService(f platformtesting.TargetFields, t *testing.T) (influxdb.
}
}
for _, m := range f.UserResourceMappings {
if err := svc.PutUserResourceMapping(ctx, m); err != nil {
if err := svc.CreateUserResourceMapping(ctx, m); err != nil {
t.Fatalf("failed to populate user resource mapping")
}
}
Expand Down Expand Up @@ -864,14 +863,13 @@ func initScraperService(f platformtesting.TargetFields, t *testing.T) (influxdb.
UserResourceMappingService: svc,
OrganizationService: svc,
ScraperService: ScraperService{
Token: "tok",
Addr: server.URL,
OpPrefix: inmem.OpPrefix,
Token: "tok",
Addr: server.URL,
},
}
done := server.Close

return &client, inmem.OpPrefix, done
return &client, "", done
}

func TestScraperService(t *testing.T) {
Expand Down
10 changes: 5 additions & 5 deletions http/task_service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import (
"github.com/influxdata/httprouter"
platform "github.com/influxdata/influxdb"
pcontext "github.com/influxdata/influxdb/context"
"github.com/influxdata/influxdb/inmem"
"github.com/influxdata/influxdb/mock"
_ "github.com/influxdata/influxdb/query/builtin"
"github.com/influxdata/influxdb/task/backend"
Expand All @@ -27,6 +26,7 @@ import (

// NewMockTaskBackend returns a TaskBackend with mock services.
func NewMockTaskBackend(t *testing.T) *TaskBackend {
t.Helper()
return &TaskBackend{
log: zaptest.NewLogger(t).With(zap.String("handler", "task")),

Expand Down Expand Up @@ -55,7 +55,7 @@ func NewMockTaskBackend(t *testing.T) *TaskBackend {
return org, nil
},
},
UserResourceMappingService: inmem.NewService(),
UserResourceMappingService: newInMemKVSVC(t),
LabelService: mock.NewLabelService(),
UserService: mock.NewUserService(),
}
Expand Down Expand Up @@ -820,7 +820,7 @@ func TestTaskHandler_handleGetRuns(t *testing.T) {
func TestTaskHandler_NotFoundStatus(t *testing.T) {
// Ensure that the HTTP handlers return 404s for missing resources, and OKs for matching.

im := inmem.NewService()
im := newInMemKVSVC(t)
taskBackend := NewMockTaskBackend(t)
taskBackend.HTTPErrorHandler = ErrorHandler(0)
h := NewTaskHandler(zaptest.NewLogger(t), taskBackend)
Expand Down Expand Up @@ -1210,7 +1210,7 @@ func TestService_handlePostTaskLabel(t *testing.T) {
// Test that org name to org ID translation happens properly in the HTTP layer.
// Regression test for https://github.com/influxdata/influxdb/issues/12089.
func TestTaskHandler_CreateTaskWithOrgName(t *testing.T) {
i := inmem.NewService()
i := newInMemKVSVC(t)
ctx := context.Background()

// Set up user and org.
Expand Down Expand Up @@ -1303,7 +1303,7 @@ func TestTaskHandler_CreateTaskWithOrgName(t *testing.T) {
func TestTaskHandler_Sessions(t *testing.T) {
t.Skip("rework these")
// Common setup to get a working base for using tasks.
i := inmem.NewService()
i := newInMemKVSVC(t)

ctx := context.Background()

Expand Down
8 changes: 3 additions & 5 deletions http/user_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"testing"

platform "github.com/influxdata/influxdb"
"github.com/influxdata/influxdb/inmem"
"github.com/influxdata/influxdb/mock"
"github.com/influxdata/influxdb/pkg/testttp"
platformtesting "github.com/influxdata/influxdb/testing"
Expand All @@ -29,7 +28,7 @@ func NewMockUserBackend(t *testing.T) *UserBackend {

func initUserService(f platformtesting.UserFields, t *testing.T) (platform.UserService, string, func()) {
t.Helper()
svc := inmem.NewService()
svc := newInMemKVSVC(t)
svc.IDGenerator = f.IDGenerator

ctx := context.Background()
Expand All @@ -51,11 +50,10 @@ func initUserService(f platformtesting.UserFields, t *testing.T) (platform.UserS
}

client := UserService{
Client: httpClient,
OpPrefix: inmem.OpPrefix,
Client: httpClient,
}

return &client, inmem.OpPrefix, server.Close
return &client, "", server.Close
}

func TestUserService(t *testing.T) {
Expand Down
9 changes: 2 additions & 7 deletions http/variable_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ import (

"github.com/influxdata/httprouter"
platform "github.com/influxdata/influxdb"
"github.com/influxdata/influxdb/inmem"
"github.com/influxdata/influxdb/kv"
"github.com/influxdata/influxdb/mock"
platformtesting "github.com/influxdata/influxdb/testing"
"go.uber.org/zap/zaptest"
Expand Down Expand Up @@ -890,14 +888,11 @@ func TestService_handlePostVariableLabel(t *testing.T) {
}

func initVariableService(f platformtesting.VariableFields, t *testing.T) (platform.VariableService, string, func()) {
svc := kv.NewService(zaptest.NewLogger(t), inmem.NewKVStore())
svc := newInMemKVSVC(t)
svc.IDGenerator = f.IDGenerator
svc.TimeGenerator = f.TimeGenerator

ctx := context.Background()
if err := svc.Initialize(ctx); err != nil {
t.Fatal(err)
}

for _, v := range f.Variables {
if err := svc.ReplaceVariable(ctx, v); err != nil {
Expand All @@ -915,7 +910,7 @@ func initVariableService(f platformtesting.VariableFields, t *testing.T) (platfo
}
done := server.Close

return &client, inmem.OpPrefix, done
return &client, "", done
}

func TestVariableService(t *testing.T) {
Expand Down
Loading

0 comments on commit e6f1805

Please sign in to comment.