Skip to content

Commit

Permalink
fix: remove telegraf endpoint pagination (#23182)
Browse files Browse the repository at this point in the history
This matches InfluxDB Cloud. The pagination was not exposed to the API,
but meant that API requests were limited to the default 20 pages.

Closes: #21407
  • Loading branch information
lesam authored Mar 14, 2022
1 parent 36df687 commit 49ce57c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 79 deletions.
27 changes: 7 additions & 20 deletions telegraf/service/telegraf.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,43 +154,30 @@ func (s *Service) findTelegrafConfigByID(ctx context.Context, tx kv.Tx, id platf
}

// FindTelegrafConfigs returns a list of telegraf configs that match filter and the total count of matching telegraf configs.
// Additional options provide pagination & sorting.
// FindOptions are ignored.
func (s *Service) FindTelegrafConfigs(ctx context.Context, filter influxdb.TelegrafConfigFilter, opt ...influxdb.FindOptions) (tcs []*influxdb.TelegrafConfig, n int, err error) {
err = s.kv.View(ctx, func(tx kv.Tx) error {
tcs, n, err = s.findTelegrafConfigs(ctx, tx, filter, opt...)
tcs, n, err = s.findTelegrafConfigs(ctx, tx, filter)
return err
})
return tcs, n, err
}

func (s *Service) findTelegrafConfigs(ctx context.Context, tx kv.Tx, filter influxdb.TelegrafConfigFilter, opt ...influxdb.FindOptions) ([]*influxdb.TelegrafConfig, int, error) {
func (s *Service) findTelegrafConfigs(ctx context.Context, tx kv.Tx, filter influxdb.TelegrafConfigFilter) ([]*influxdb.TelegrafConfig, int, error) {
var (
limit = influxdb.DefaultPageSize
offset int
count int
tcs = make([]*influxdb.TelegrafConfig, 0)
tcs = make([]*influxdb.TelegrafConfig, 0)
)

if len(opt) > 0 {
limit = opt[0].GetLimit()
offset = opt[0].Offset
}

visit := func(k, v []byte) (bool, error) {
var tc influxdb.TelegrafConfig
if err := json.Unmarshal(v, &tc); err != nil {
return false, err
}

// skip until offset reached
if count >= offset {
tcs = append(tcs, &tc)
}

count++
tcs = append(tcs, &tc)

// stop cursing when limit is reached
return len(tcs) < limit, nil
return true, nil
}

if filter.OrgID == nil {
Expand All @@ -207,7 +194,7 @@ func (s *Service) findTelegrafConfigs(ctx context.Context, tx kv.Tx, filter infl
// REMOVE this cursor option if you do any
// other filtering

cursor, err := bucket.ForwardCursor(nil, kv.WithCursorLimit(offset+limit))
cursor, err := bucket.ForwardCursor(nil)
if err != nil {
return nil, 0, err
}
Expand Down
59 changes: 0 additions & 59 deletions telegraf/service/testing/testing.go
Original file line number Diff line number Diff line change
Expand Up @@ -521,65 +521,6 @@ func FindTelegrafConfigs(
telegrafConfigs: []*influxdb.TelegrafConfig{},
},
},
{
name: "find with limit and offset",
fields: TelegrafConfigFields{
IDGenerator: mock.NewIncrementingIDGenerator(oneID),
TelegrafConfigs: []*influxdb.TelegrafConfig{
{
ID: oneID,
OrgID: fourID,
Name: "tc1",
Config: "[[inputs.cpu]]\n",
Metadata: map[string]interface{}{"buckets": []interface{}{}},
},
{
ID: twoID,
OrgID: fourID,
Name: "tc2",
Config: "[[inputs.file]]\n[[inputs.mem]]\n",
Metadata: map[string]interface{}{"buckets": []interface{}{}},
},
{
ID: threeID,
OrgID: oneID,
Name: "tc3",
Config: "[[inputs.cpu]]\n",
Metadata: map[string]interface{}{"buckets": []interface{}{}},
},
{
ID: fourID,
OrgID: oneID,
Name: "tc4",
Config: "[[inputs.cpu]]\n",
Metadata: map[string]interface{}{"buckets": []interface{}{}},
},
},
},
args: args{
opts: []influxdb.FindOptions{
{Limit: 2, Offset: 1},
},
},
wants: wants{
telegrafConfigs: []*influxdb.TelegrafConfig{
{
ID: twoID,
OrgID: fourID,
Name: "tc2",
Config: "[[inputs.file]]\n[[inputs.mem]]\n",
Metadata: map[string]interface{}{"buckets": []interface{}{}},
},
{
ID: threeID,
OrgID: oneID,
Name: "tc3",
Config: "[[inputs.cpu]]\n",
Metadata: map[string]interface{}{"buckets": []interface{}{}},
},
},
},
},
}

for _, tt := range tests {
Expand Down

0 comments on commit 49ce57c

Please sign in to comment.