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: #21407pull/23190/head
parent
36df687aa8
commit
49ce57c029
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Reference in New Issue