Skip to content

Commit

Permalink
Merge pull request GoogleCloudPlatform#804 from skarimo/sherz/add-pag…
Browse files Browse the repository at this point in the history
…inated-endpoint-support

Add paginated endpoint support for Datadog monitors resource
  • Loading branch information
sergeylanzman authored Feb 22, 2021
2 parents 0a16e59 + 022ce36 commit e7b506c
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions providers/datadog/monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,24 @@ func (g *MonitorGenerator) InitResources() error {
return nil
}

monitors, _, err := datadogClientV1.MonitorsApi.ListMonitors(authV1).Execute()
if err != nil {
return err
var monitors []datadogV1.Monitor
pageSize := int32(1000)
pageNumber := int64(0)
for {
resp, _, err := datadogClientV1.MonitorsApi.ListMonitors(authV1).PageSize(pageSize).Page(pageNumber).Execute()
if err != nil {
return err
}

if len(resp) == 0 || int32(len(resp)) < pageSize {
monitors = append(monitors, resp...)
break
}

monitors = append(monitors, resp...)
pageNumber++
}

g.Resources = g.createResources(monitors)
return nil
}

0 comments on commit e7b506c

Please sign in to comment.