2019-02-19 23:47:19 +00:00
|
|
|
package kv
|
|
|
|
|
|
|
|
import (
|
2019-12-06 03:55:26 +00:00
|
|
|
"github.com/benbjohnson/clock"
|
2020-04-03 17:39:20 +00:00
|
|
|
"github.com/influxdata/influxdb/v2"
|
2021-03-30 18:10:02 +00:00
|
|
|
"github.com/influxdata/influxdb/v2/kit/platform"
|
2021-04-07 18:42:55 +00:00
|
|
|
"github.com/influxdata/influxdb/v2/query/fluxlang"
|
2020-04-03 17:39:20 +00:00
|
|
|
"github.com/influxdata/influxdb/v2/rand"
|
|
|
|
"github.com/influxdata/influxdb/v2/resource"
|
|
|
|
"github.com/influxdata/influxdb/v2/resource/noop"
|
|
|
|
"github.com/influxdata/influxdb/v2/snowflake"
|
2019-12-06 03:55:26 +00:00
|
|
|
"go.uber.org/zap"
|
2019-02-19 23:47:19 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// OpPrefix is the prefix for kv errors.
|
|
|
|
const OpPrefix = "kv/"
|
|
|
|
|
|
|
|
// Service is the struct that influxdb services are implemented on.
|
|
|
|
type Service struct {
|
2020-02-07 16:01:37 +00:00
|
|
|
kv Store
|
|
|
|
log *zap.Logger
|
|
|
|
clock clock.Clock
|
|
|
|
Config ServiceConfig
|
|
|
|
audit resource.Logger
|
2021-03-30 18:10:02 +00:00
|
|
|
IDGenerator platform.IDGenerator
|
2019-09-07 23:00:26 +00:00
|
|
|
|
2020-03-05 20:36:58 +00:00
|
|
|
// FluxLanguageService is used for parsing flux.
|
|
|
|
// If this is unset, operations that require parsing flux
|
|
|
|
// will fail.
|
2021-04-07 18:42:55 +00:00
|
|
|
FluxLanguageService fluxlang.FluxLanguageService
|
2020-03-05 20:36:58 +00:00
|
|
|
|
2019-02-19 23:47:19 +00:00
|
|
|
TokenGenerator influxdb.TokenGenerator
|
2019-11-07 14:46:30 +00:00
|
|
|
// TODO(desa:ariel): this should not be embedded
|
2019-04-19 19:46:58 +00:00
|
|
|
influxdb.TimeGenerator
|
2019-12-26 04:55:04 +00:00
|
|
|
|
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
|
|
|
orgs influxdb.OrganizationService
|
2020-03-18 12:23:51 +00:00
|
|
|
|
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
|
|
|
variableStore *IndexStore
|
2019-02-19 23:47:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// NewService returns an instance of a Service.
|
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
|
|
|
func NewService(log *zap.Logger, kv Store, orgs influxdb.OrganizationService, configs ...ServiceConfig) *Service {
|
2019-05-15 17:16:47 +00:00
|
|
|
s := &Service{
|
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
|
|
|
log: log,
|
|
|
|
IDGenerator: snowflake.NewIDGenerator(),
|
2019-02-19 23:47:19 +00:00
|
|
|
TokenGenerator: rand.NewTokenGenerator(64),
|
|
|
|
kv: kv,
|
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
|
|
|
orgs: orgs,
|
2020-01-13 14:22:52 +00:00
|
|
|
audit: noop.ResourceLogger{},
|
2019-04-19 19:46:58 +00:00
|
|
|
TimeGenerator: influxdb.RealTimeGenerator{},
|
2019-12-31 03:11:53 +00:00
|
|
|
variableStore: newVariableStore(),
|
2019-02-19 23:47:19 +00:00
|
|
|
}
|
2019-05-15 17:16:47 +00:00
|
|
|
|
|
|
|
if len(configs) > 0 {
|
|
|
|
s.Config = configs[0]
|
2020-03-09 21:07:49 +00:00
|
|
|
}
|
|
|
|
|
2019-12-06 03:55:26 +00:00
|
|
|
s.clock = s.Config.Clock
|
|
|
|
if s.clock == nil {
|
|
|
|
s.clock = clock.New()
|
|
|
|
}
|
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
|
|
|
|
2020-03-05 20:36:58 +00:00
|
|
|
s.FluxLanguageService = s.Config.FluxLanguageService
|
2019-12-06 03:55:26 +00:00
|
|
|
|
2019-05-15 17:16:47 +00:00
|
|
|
return s
|
|
|
|
}
|
|
|
|
|
|
|
|
// ServiceConfig allows us to configure Services
|
|
|
|
type ServiceConfig struct {
|
2020-07-01 11:08:20 +00:00
|
|
|
Clock clock.Clock
|
2021-04-07 18:42:55 +00:00
|
|
|
FluxLanguageService fluxlang.FluxLanguageService
|
2019-02-19 23:47:19 +00:00
|
|
|
}
|
|
|
|
|
2020-01-13 14:22:52 +00:00
|
|
|
// WithResourceLogger sets the resource audit logger for the service.
|
|
|
|
func (s *Service) WithResourceLogger(audit resource.Logger) {
|
|
|
|
s.audit = audit
|
|
|
|
}
|
|
|
|
|
2019-02-19 23:47:19 +00:00
|
|
|
// WithStore sets kv store for the service.
|
|
|
|
// Should only be used in tests for mocking.
|
|
|
|
func (s *Service) WithStore(store Store) {
|
|
|
|
s.kv = store
|
|
|
|
}
|