2020-06-26 19:52:15 +00:00
|
|
|
package checks
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/influxdata/influxdb/v2"
|
refactor(kv): delete deprecated kv service code
This includes removal of a lot of kv.Service responsibilities. However,
it does not finish the re-wiring. It removes documents, telegrafs,
notification rules + endpoints, checks, orgs, users, buckets, passwords,
urms, labels and authorizations. There are some oustanding pieces that
are needed to get kv service compiling (dashboard service urm
dependency). Then all the call sites for kv service need updating and
the new implementations of telegraf and notification rules + endpoints
needed installing (along with any necessary migrations).
2020-10-20 13:25:36 +00:00
|
|
|
_ "github.com/influxdata/influxdb/v2/fluxinit/static"
|
2020-06-26 19:52:15 +00:00
|
|
|
"github.com/influxdata/influxdb/v2/inmem"
|
|
|
|
"github.com/influxdata/influxdb/v2/kv"
|
2020-07-01 11:08:20 +00:00
|
|
|
"github.com/influxdata/influxdb/v2/kv/migration/all"
|
refactor(kv): delete deprecated kv service code
This includes removal of a lot of kv.Service responsibilities. However,
it does not finish the re-wiring. It removes documents, telegrafs,
notification rules + endpoints, checks, orgs, users, buckets, passwords,
urms, labels and authorizations. There are some oustanding pieces that
are needed to get kv service compiling (dashboard service urm
dependency). Then all the call sites for kv service need updating and
the new implementations of telegraf and notification rules + endpoints
needed installing (along with any necessary migrations).
2020-10-20 13:25:36 +00:00
|
|
|
"github.com/influxdata/influxdb/v2/mock"
|
2020-06-26 19:52:15 +00:00
|
|
|
"github.com/influxdata/influxdb/v2/query/fluxlang"
|
2021-04-07 18:42:55 +00:00
|
|
|
"github.com/influxdata/influxdb/v2/task/taskmodel"
|
refactor(kv): delete deprecated kv service code
This includes removal of a lot of kv.Service responsibilities. However,
it does not finish the re-wiring. It removes documents, telegrafs,
notification rules + endpoints, checks, orgs, users, buckets, passwords,
urms, labels and authorizations. There are some oustanding pieces that
are needed to get kv service compiling (dashboard service urm
dependency). Then all the call sites for kv service need updating and
the new implementations of telegraf and notification rules + endpoints
needed installing (along with any necessary migrations).
2020-10-20 13:25:36 +00:00
|
|
|
"github.com/influxdata/influxdb/v2/tenant"
|
2020-06-26 19:52:15 +00:00
|
|
|
"go.uber.org/zap/zaptest"
|
|
|
|
)
|
|
|
|
|
|
|
|
func NewKVTestStore(t *testing.T) (kv.Store, func()) {
|
2020-07-01 11:08:20 +00:00
|
|
|
t.Helper()
|
|
|
|
|
|
|
|
store := inmem.NewKVStore()
|
|
|
|
|
|
|
|
if err := all.Up(context.Background(), zaptest.NewLogger(t), store); err != nil {
|
|
|
|
t.Fatal(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return store, func() {}
|
2020-06-26 19:52:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestCheckService(t *testing.T) {
|
|
|
|
CheckService(initCheckService, t)
|
|
|
|
}
|
|
|
|
|
2021-04-07 18:42:55 +00:00
|
|
|
func initCheckService(f CheckFields, t *testing.T) (influxdb.CheckService, taskmodel.TaskService, string, func()) {
|
2020-06-26 19:52:15 +00:00
|
|
|
store, closeKVStore := NewKVTestStore(t)
|
|
|
|
logger := zaptest.NewLogger(t)
|
refactor(kv): delete deprecated kv service code
This includes removal of a lot of kv.Service responsibilities. However,
it does not finish the re-wiring. It removes documents, telegrafs,
notification rules + endpoints, checks, orgs, users, buckets, passwords,
urms, labels and authorizations. There are some oustanding pieces that
are needed to get kv service compiling (dashboard service urm
dependency). Then all the call sites for kv service need updating and
the new implementations of telegraf and notification rules + endpoints
needed installing (along with any necessary migrations).
2020-10-20 13:25:36 +00:00
|
|
|
|
|
|
|
tenantStore := tenant.NewStore(store)
|
|
|
|
tenantSvc := tenant.NewService(tenantStore)
|
|
|
|
|
|
|
|
svc := kv.NewService(logger, store, tenantSvc, kv.ServiceConfig{
|
2020-06-26 19:52:15 +00:00
|
|
|
FluxLanguageService: fluxlang.DefaultService,
|
|
|
|
})
|
|
|
|
svc.IDGenerator = f.IDGenerator
|
|
|
|
svc.TimeGenerator = f.TimeGenerator
|
|
|
|
if f.TimeGenerator == nil {
|
|
|
|
svc.TimeGenerator = influxdb.RealTimeGenerator{}
|
|
|
|
}
|
|
|
|
|
refactor(kv): delete deprecated kv service code
This includes removal of a lot of kv.Service responsibilities. However,
it does not finish the re-wiring. It removes documents, telegrafs,
notification rules + endpoints, checks, orgs, users, buckets, passwords,
urms, labels and authorizations. There are some oustanding pieces that
are needed to get kv service compiling (dashboard service urm
dependency). Then all the call sites for kv service need updating and
the new implementations of telegraf and notification rules + endpoints
needed installing (along with any necessary migrations).
2020-10-20 13:25:36 +00:00
|
|
|
checkService := NewService(logger, store, tenantSvc, svc)
|
2020-06-26 19:52:15 +00:00
|
|
|
checkService.idGenerator = f.IDGenerator
|
|
|
|
if f.TimeGenerator != nil {
|
|
|
|
checkService.timeGenerator = f.TimeGenerator
|
|
|
|
}
|
|
|
|
|
|
|
|
ctx := context.Background()
|
|
|
|
for _, o := range f.Organizations {
|
refactor(kv): delete deprecated kv service code
This includes removal of a lot of kv.Service responsibilities. However,
it does not finish the re-wiring. It removes documents, telegrafs,
notification rules + endpoints, checks, orgs, users, buckets, passwords,
urms, labels and authorizations. There are some oustanding pieces that
are needed to get kv service compiling (dashboard service urm
dependency). Then all the call sites for kv service need updating and
the new implementations of telegraf and notification rules + endpoints
needed installing (along with any necessary migrations).
2020-10-20 13:25:36 +00:00
|
|
|
mock.SetIDForFunc(&tenantStore.OrgIDGen, o.ID, func() {
|
|
|
|
if err := tenantSvc.CreateOrganization(ctx, o); err != nil {
|
|
|
|
t.Fatalf("failed to populate organizations")
|
|
|
|
}
|
|
|
|
})
|
2020-06-26 19:52:15 +00:00
|
|
|
}
|
|
|
|
for _, c := range f.Checks {
|
|
|
|
if err := checkService.PutCheck(ctx, c); err != nil {
|
|
|
|
t.Fatalf("failed to populate checks")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for _, tc := range f.Tasks {
|
|
|
|
if _, err := svc.CreateTask(ctx, tc); err != nil {
|
|
|
|
t.Fatalf("failed to populate tasks: %v", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return checkService, svc, kv.OpPrefix, func() {
|
|
|
|
for _, o := range f.Organizations {
|
refactor(kv): delete deprecated kv service code
This includes removal of a lot of kv.Service responsibilities. However,
it does not finish the re-wiring. It removes documents, telegrafs,
notification rules + endpoints, checks, orgs, users, buckets, passwords,
urms, labels and authorizations. There are some oustanding pieces that
are needed to get kv service compiling (dashboard service urm
dependency). Then all the call sites for kv service need updating and
the new implementations of telegraf and notification rules + endpoints
needed installing (along with any necessary migrations).
2020-10-20 13:25:36 +00:00
|
|
|
if err := tenantSvc.DeleteOrganization(ctx, o.ID); err != nil {
|
2020-06-26 19:52:15 +00:00
|
|
|
t.Logf("failed to remove organization: %v", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for _, c := range f.Checks {
|
|
|
|
if err := checkService.DeleteCheck(ctx, c.GetID()); err != nil {
|
|
|
|
t.Logf("failed to remove check: %v", err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
closeKVStore()
|
|
|
|
}
|
|
|
|
}
|