From 49ce57c029de703f965ab6e48cfae31f8112a0c6 Mon Sep 17 00:00:00 2001 From: Sam Arnold Date: Mon, 14 Mar 2022 12:17:43 -0400 Subject: [PATCH] fix: remove telegraf endpoint pagination (#23182) 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 --- telegraf/service/telegraf.go | 27 ++++--------- telegraf/service/testing/testing.go | 59 ----------------------------- 2 files changed, 7 insertions(+), 79 deletions(-) diff --git a/telegraf/service/telegraf.go b/telegraf/service/telegraf.go index 0841541f0d..75f5085e9e 100644 --- a/telegraf/service/telegraf.go +++ b/telegraf/service/telegraf.go @@ -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 { @@ -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 } diff --git a/telegraf/service/testing/testing.go b/telegraf/service/testing/testing.go index 60ea761eab..e33bf72a0c 100644 --- a/telegraf/service/testing/testing.go +++ b/telegraf/service/testing/testing.go @@ -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 {