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
|
|
|
package tenant
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"encoding/json"
|
|
|
|
"time"
|
|
|
|
|
2021-03-30 18:10:02 +00:00
|
|
|
"github.com/influxdata/influxdb/v2/kit/platform"
|
|
|
|
|
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"
|
|
|
|
"github.com/influxdata/influxdb/v2/kv"
|
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
orgOperationLogKeyPrefix = "org"
|
|
|
|
bucketOperationLogKeyPrefix = "bucket"
|
|
|
|
userOperationLogKeyPrefix = "user"
|
|
|
|
)
|
|
|
|
|
|
|
|
// OpLogStore is a type which persists and reports operation log entries on a backing
|
|
|
|
// kv store transaction.
|
|
|
|
type OpLogStore interface {
|
|
|
|
AddLogEntryTx(ctx context.Context, tx kv.Tx, k, v []byte, t time.Time) error
|
|
|
|
ForEachLogEntryTx(ctx context.Context, tx kv.Tx, k []byte, opts influxdb.FindOptions, fn func([]byte, time.Time) error) error
|
|
|
|
}
|
|
|
|
|
|
|
|
// OpLogService is a type which stores operation logs for buckets, users and orgs.
|
|
|
|
type OpLogService struct {
|
|
|
|
kv kv.Store
|
|
|
|
|
|
|
|
opLogStore OpLogStore
|
|
|
|
|
|
|
|
TimeGenerator influxdb.TimeGenerator
|
|
|
|
}
|
|
|
|
|
|
|
|
// NewOpLogService constructs and configures a new op log service.
|
|
|
|
func NewOpLogService(store kv.Store, opLogStore OpLogStore) *OpLogService {
|
|
|
|
return &OpLogService{
|
|
|
|
kv: store,
|
|
|
|
opLogStore: opLogStore,
|
|
|
|
TimeGenerator: influxdb.RealTimeGenerator{},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetOrganizationOperationLog retrieves a organization operation log.
|
2021-03-30 18:10:02 +00:00
|
|
|
func (s *OpLogService) GetOrganizationOperationLog(ctx context.Context, id platform.ID, opts influxdb.FindOptions) ([]*influxdb.OperationLogEntry, int, error) {
|
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
|
|
|
// TODO(desa): might be worthwhile to allocate a slice of size opts.Limit
|
|
|
|
log := []*influxdb.OperationLogEntry{}
|
|
|
|
|
|
|
|
err := s.kv.View(ctx, func(tx kv.Tx) error {
|
|
|
|
key, err := encodeOrganizationOperationLogKey(id)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return s.opLogStore.ForEachLogEntryTx(ctx, tx, key, opts, func(v []byte, t time.Time) error {
|
|
|
|
e := &influxdb.OperationLogEntry{}
|
|
|
|
if err := json.Unmarshal(v, e); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
e.Time = t
|
|
|
|
|
|
|
|
log = append(log, e)
|
|
|
|
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
if err != nil && err != kv.ErrKeyValueLogBoundsNotFound {
|
|
|
|
return nil, 0, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return log, len(log), nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetBucketOperationLog retrieves a buckets operation log.
|
2021-03-30 18:10:02 +00:00
|
|
|
func (s *OpLogService) GetBucketOperationLog(ctx context.Context, id platform.ID, opts influxdb.FindOptions) ([]*influxdb.OperationLogEntry, int, error) {
|
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
|
|
|
// TODO(desa): might be worthwhile to allocate a slice of size opts.Limit
|
|
|
|
log := []*influxdb.OperationLogEntry{}
|
|
|
|
|
|
|
|
err := s.kv.View(ctx, func(tx kv.Tx) error {
|
|
|
|
key, err := encodeBucketOperationLogKey(id)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return s.opLogStore.ForEachLogEntryTx(ctx, tx, key, opts, func(v []byte, t time.Time) error {
|
|
|
|
e := &influxdb.OperationLogEntry{}
|
|
|
|
if err := json.Unmarshal(v, e); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
e.Time = t
|
|
|
|
|
|
|
|
log = append(log, e)
|
|
|
|
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
if err != nil && err != kv.ErrKeyValueLogBoundsNotFound {
|
|
|
|
return nil, 0, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return log, len(log), nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// GetUserOperationLog retrieves a user operation log.
|
2021-03-30 18:10:02 +00:00
|
|
|
func (s *OpLogService) GetUserOperationLog(ctx context.Context, id platform.ID, opts influxdb.FindOptions) ([]*influxdb.OperationLogEntry, int, error) {
|
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
|
|
|
// TODO(desa): might be worthwhile to allocate a slice of size opts.Limit
|
|
|
|
log := []*influxdb.OperationLogEntry{}
|
|
|
|
|
|
|
|
err := s.kv.View(ctx, func(tx kv.Tx) error {
|
|
|
|
key, err := encodeUserOperationLogKey(id)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return s.opLogStore.ForEachLogEntryTx(ctx, tx, key, opts, func(v []byte, t time.Time) error {
|
|
|
|
e := &influxdb.OperationLogEntry{}
|
|
|
|
if err := json.Unmarshal(v, e); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
e.Time = t
|
|
|
|
|
|
|
|
log = append(log, e)
|
|
|
|
|
|
|
|
return nil
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
if err != nil && err != kv.ErrKeyValueLogBoundsNotFound {
|
|
|
|
return nil, 0, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return log, len(log), nil
|
|
|
|
}
|
|
|
|
|
2021-03-30 18:10:02 +00:00
|
|
|
func encodeOrganizationOperationLogKey(id platform.ID) ([]byte, error) {
|
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
|
|
|
buf, err := id.Encode()
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return append([]byte(orgOperationLogKeyPrefix), buf...), nil
|
|
|
|
}
|
|
|
|
|
2021-03-30 18:10:02 +00:00
|
|
|
func encodeBucketOperationLogKey(id platform.ID) ([]byte, error) {
|
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
|
|
|
buf, err := id.Encode()
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return append([]byte(bucketOperationLogKeyPrefix), buf...), nil
|
|
|
|
}
|
|
|
|
|
2021-03-30 18:10:02 +00:00
|
|
|
func encodeUserOperationLogKey(id platform.ID) ([]byte, error) {
|
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
|
|
|
buf, err := id.Encode()
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return append([]byte(userOperationLogKeyPrefix), buf...), nil
|
|
|
|
}
|