Skip to content

Commit e4e69bb

Browse files
committed
refactor(telegraf): remove references to kv service telegraf service implementation
1 parent ddcadcb commit e4e69bb

File tree

11 files changed

+157
-1980
lines changed

11 files changed

+157
-1980
lines changed

cmd/influxd/launcher/launcher.go

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ import (
6565
"github.com/influxdata/influxdb/v2/task/backend/executor"
6666
"github.com/influxdata/influxdb/v2/task/backend/middleware"
6767
"github.com/influxdata/influxdb/v2/task/backend/scheduler"
68+
telegrafservice "github.com/influxdata/influxdb/v2/telegraf/service"
6869
"github.com/influxdata/influxdb/v2/telemetry"
6970
"github.com/influxdata/influxdb/v2/tenant"
7071
_ "github.com/influxdata/influxdb/v2/tsdb/engine/tsm1" // needed for tsm1
@@ -768,8 +769,6 @@ func (m *Launcher) run(ctx context.Context) (err error) {
768769
bucketLogSvc platform.BucketOperationLogService = m.kvService
769770
orgLogSvc platform.OrganizationOperationLogService = m.kvService
770771
scraperTargetSvc platform.ScraperTargetStoreService = m.kvService
771-
telegrafSvc platform.TelegrafConfigStore = m.kvService
772-
lookupSvc platform.LookupService = m.kvService
773772
)
774773

775774
tenantStore := tenant.NewStore(m.kvStore)
@@ -1006,6 +1005,11 @@ func (m *Launcher) run(ctx context.Context) (err error) {
10061005
notificationRuleSvc = middleware.NewNotificationRuleStore(notificationRuleSvc, m.kvService, coordinator)
10071006
}
10081007

1008+
var telegrafSvc platform.TelegrafConfigStore
1009+
{
1010+
telegrafSvc = telegrafservice.New(m.kvStore)
1011+
}
1012+
10091013
// NATS streaming server
10101014
natsOpts := nats.NewDefaultServerOptions()
10111015

@@ -1158,11 +1162,11 @@ func (m *Launcher) run(ctx context.Context) (err error) {
11581162
}
11591163
}
11601164

1161-
// orgIDResolver is a deprecated type which combines the lookups
1165+
// resourceResolver is a deprecated type which combines the lookups
11621166
// of multiple resources into one type, used to resolve the resources
1163-
// associated org ID. It is a stop-gap while we move this behaviour
1164-
// off of *kv.Service to aid in reducing the coupling on this type.
1165-
orgIDResolver := &resource.OrgIDResolver{
1167+
// associated org ID or name . It is a stop-gap while we move this
1168+
// behaviour off of *kv.Service to aid in reducing the coupling on this type.
1169+
resourceResolver := &resource.Resolver{
11661170
AuthorizationFinder: authSvc,
11671171
BucketFinder: ts.BucketService,
11681172
OrganizationFinder: ts.OrganizationService,
@@ -1224,9 +1228,9 @@ func (m *Launcher) run(ctx context.Context) (err error) {
12241228
ScraperTargetStoreService: scraperTargetSvc,
12251229
ChronografService: chronografSvc,
12261230
SecretService: secretSvc,
1227-
LookupService: lookupSvc,
1231+
LookupService: resourceResolver,
12281232
DocumentService: m.kvService,
1229-
OrgLookupService: orgIDResolver,
1233+
OrgLookupService: resourceResolver,
12301234
WriteEventRecorder: infprom.NewEventRecorder("write"),
12311235
QueryEventRecorder: infprom.NewEventRecorder("query"),
12321236
Flagger: m.flagger,

http/auth_service.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ func newPermissionsResponse(ctx context.Context, ps []influxdb.Permission, svc i
152152
}
153153

154154
if p.Resource.ID != nil {
155-
name, err := svc.Name(ctx, p.Resource.Type, *p.Resource.ID)
155+
name, err := svc.FindResourceName(ctx, p.Resource.Type, *p.Resource.ID)
156156
if influxdb.ErrorCode(err) == influxdb.ENotFound {
157157
continue
158158
}
@@ -163,7 +163,7 @@ func newPermissionsResponse(ctx context.Context, ps []influxdb.Permission, svc i
163163
}
164164

165165
if p.Resource.OrgID != nil {
166-
name, err := svc.Name(ctx, influxdb.OrgsResourceType, *p.Resource.OrgID)
166+
name, err := svc.FindResourceName(ctx, influxdb.OrgsResourceType, *p.Resource.OrgID)
167167
if influxdb.ErrorCode(err) == influxdb.ENotFound {
168168
continue
169169
}

internal/resource/org_id.go renamed to internal/resource/resolve.go

Lines changed: 137 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ import (
77
"github.com/influxdata/influxdb/v2"
88
)
99

10-
// OrgIDResolver is a type which combines multiple resource services
10+
// Resolver is a type which combines multiple resource services
1111
// in order to resolve the resources associated org ID.
1212
// Ideally you do not need to use this type, it is mostly a stop-gap
1313
// while we migrate responsibilities off of *kv.Service.
1414
// Consider it deprecated.
15-
type OrgIDResolver struct {
15+
type Resolver struct {
1616
AuthorizationFinder interface {
1717
FindAuthorizationByID(context.Context, influxdb.ID) (*influxdb.Authorization, error)
1818
}
@@ -52,7 +52,7 @@ type OrgIDResolver struct {
5252
}
5353

5454
// FindResourceOrganizationID is used to find the organization that a resource belongs to five the id of a resource and a resource type.
55-
func (o *OrgIDResolver) FindResourceOrganizationID(ctx context.Context, rt influxdb.ResourceType, id influxdb.ID) (influxdb.ID, error) {
55+
func (o *Resolver) FindResourceOrganizationID(ctx context.Context, rt influxdb.ResourceType, id influxdb.ID) (influxdb.ID, error) {
5656
switch rt {
5757
case influxdb.AuthorizationsResourceType:
5858
if o.AuthorizationFinder == nil {
@@ -192,3 +192,137 @@ func (o *OrgIDResolver) FindResourceOrganizationID(ctx context.Context, rt influ
192192
Msg: fmt.Sprintf("unsupported resource type %s", rt),
193193
}
194194
}
195+
196+
// FindResourceName is used to find the name of the resource associated with the provided type and id.
197+
func (o *Resolver) FindResourceName(ctx context.Context, rt influxdb.ResourceType, id influxdb.ID) (string, error) {
198+
switch rt {
199+
case influxdb.AuthorizationsResourceType:
200+
// keeping this consistent with the original kv implementation
201+
return "", nil
202+
case influxdb.BucketsResourceType:
203+
if o.BucketFinder == nil {
204+
break
205+
}
206+
207+
r, err := o.BucketFinder.FindBucketByID(ctx, id)
208+
if err != nil {
209+
return "", err
210+
}
211+
212+
return r.Name, nil
213+
case influxdb.OrgsResourceType:
214+
if o.OrganizationFinder == nil {
215+
break
216+
}
217+
218+
r, err := o.OrganizationFinder.FindOrganizationByID(ctx, id)
219+
if err != nil {
220+
return "", err
221+
}
222+
223+
return r.Name, nil
224+
case influxdb.DashboardsResourceType:
225+
if o.DashboardFinder == nil {
226+
break
227+
}
228+
229+
r, err := o.DashboardFinder.FindDashboardByID(ctx, id)
230+
if err != nil {
231+
return "", err
232+
}
233+
234+
return r.Name, nil
235+
case influxdb.SourcesResourceType:
236+
if o.SourceFinder == nil {
237+
break
238+
}
239+
240+
r, err := o.SourceFinder.FindSourceByID(ctx, id)
241+
if err != nil {
242+
return "", err
243+
}
244+
245+
return r.Name, nil
246+
case influxdb.TasksResourceType:
247+
if o.TaskFinder == nil {
248+
break
249+
}
250+
251+
r, err := o.TaskFinder.FindTaskByID(ctx, id)
252+
if err != nil {
253+
return "", err
254+
}
255+
256+
return r.Name, nil
257+
case influxdb.TelegrafsResourceType:
258+
if o.TelegrafConfigFinder == nil {
259+
break
260+
}
261+
262+
r, err := o.TelegrafConfigFinder.FindTelegrafConfigByID(ctx, id)
263+
if err != nil {
264+
return "", err
265+
}
266+
267+
return r.Name, nil
268+
case influxdb.VariablesResourceType:
269+
if o.VariableFinder == nil {
270+
break
271+
}
272+
273+
r, err := o.VariableFinder.FindVariableByID(ctx, id)
274+
if err != nil {
275+
return "", nil
276+
}
277+
278+
return r.Name, nil
279+
case influxdb.ScraperResourceType:
280+
if o.TargetFinder == nil {
281+
break
282+
}
283+
284+
r, err := o.TargetFinder.GetTargetByID(ctx, id)
285+
if err != nil {
286+
return "", err
287+
}
288+
289+
return r.Name, nil
290+
case influxdb.ChecksResourceType:
291+
if o.CheckFinder == nil {
292+
break
293+
}
294+
295+
r, err := o.CheckFinder.FindCheckByID(ctx, id)
296+
if err != nil {
297+
return "", err
298+
}
299+
300+
return r.GetName(), nil
301+
case influxdb.NotificationEndpointResourceType:
302+
if o.NotificationEndpointFinder == nil {
303+
break
304+
}
305+
306+
r, err := o.NotificationEndpointFinder.FindNotificationEndpointByID(ctx, id)
307+
if err != nil {
308+
return "", err
309+
}
310+
311+
return r.GetName(), nil
312+
case influxdb.NotificationRuleResourceType:
313+
if o.NotificationRuleFinder == nil {
314+
break
315+
}
316+
317+
r, err := o.NotificationRuleFinder.FindNotificationRuleByID(ctx, id)
318+
if err != nil {
319+
return "", err
320+
}
321+
322+
return r.GetName(), nil
323+
}
324+
325+
// default behaviour (in-line with original implementation) is to just return
326+
// an empty name
327+
return "", nil
328+
}

kv/initial_migration.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,8 @@ func (m InitialMigration) Up(ctx context.Context, store SchemaStore) error {
4343
userpasswordBucket,
4444
scrapersBucket,
4545
secretBucket,
46-
telegrafBucket,
47-
telegrafPluginsBucket,
46+
[]byte("telegrafv1"),
47+
[]byte("telegrafPluginsv1"),
4848
urmBucket,
4949
[]byte("notificationRulev1"),
5050
userBucket,

kv/lookup_service.go

Lines changed: 0 additions & 63 deletions
This file was deleted.

0 commit comments

Comments
 (0)