@@ -153,14 +153,17 @@ func (c *VPCCollector) collectVpcsPerRegionQuota(ch chan<- prometheus.Metric) {
153153func (c * VPCCollector ) collectVpcsPerRegionUsage (ch chan <- prometheus.Metric ) {
154154 ctx , cancelFunc := context .WithTimeout (context .Background (), c .e .timeout )
155155 defer cancelFunc ()
156- describeVpcsOutput , err := c .ec2 .DescribeVpcsWithContext (ctx , & ec2.DescribeVpcsInput {})
156+ numVpcs := 0
157+ err := c .ec2 .DescribeVpcsPagesWithContext (ctx , & ec2.DescribeVpcsInput {}, func (page * ec2.DescribeVpcsOutput , lastPage bool ) bool {
158+ numVpcs += len (page .Vpcs )
159+ return ! lastPage
160+ })
157161 if err != nil {
158162 level .Error (c .e .logger ).Log ("msg" , "Call to DescribeVpcs failed" , "region" , c .region , "err" , err )
159163 exporterMetrics .IncrementErrors ()
160164 return
161165 }
162- usage := len (describeVpcsOutput .Vpcs )
163- ch <- prometheus .MustNewConstMetric (c .e .VpcsPerRegionUsage , prometheus .GaugeValue , float64 (usage ), * c .region )
166+ ch <- prometheus .MustNewConstMetric (c .e .VpcsPerRegionUsage , prometheus .GaugeValue , float64 (numVpcs ), * c .region )
164167}
165168
166169func (c * VPCCollector ) collectSubnetsPerVpcQuota (ch chan <- prometheus.Metric ) {
@@ -176,19 +179,21 @@ func (c *VPCCollector) collectSubnetsPerVpcQuota(ch chan<- prometheus.Metric) {
176179func (c * VPCCollector ) collectSubnetsPerVpcUsage (ch chan <- prometheus.Metric , vpc * ec2.Vpc ) {
177180 ctx , cancelFunc := context .WithTimeout (context .Background (), c .e .timeout )
178181 defer cancelFunc ()
179- describeSubnetsOutput , err := c .ec2 .DescribeSubnetsWithContext (ctx , & ec2.DescribeSubnetsInput {
180- Filters : []* ec2.Filter {& ec2.Filter {
182+ numSubnets := 0
183+ err := c .ec2 .DescribeSubnetsPagesWithContext (ctx , & ec2.DescribeSubnetsInput {
184+ Filters : []* ec2.Filter {{
181185 Name : aws .String ("vpc-id" ),
182186 Values : []* string {vpc .VpcId },
183- }},
187+ }}}, func (page * ec2.DescribeSubnetsOutput , lastPage bool ) bool {
188+ numSubnets += len (page .Subnets )
189+ return ! lastPage
184190 })
185191 if err != nil {
186192 level .Error (c .e .logger ).Log ("msg" , "Call to DescribeSubnets failed" , "region" , c .region , "err" , err )
187193 exporterMetrics .IncrementErrors ()
188194 return
189195 }
190- usage := len (describeSubnetsOutput .Subnets )
191- ch <- prometheus .MustNewConstMetric (c .e .SubnetsPerVpcUsage , prometheus .GaugeValue , float64 (usage ), * c .region , * vpc .VpcId )
196+ ch <- prometheus .MustNewConstMetric (c .e .SubnetsPerVpcUsage , prometheus .GaugeValue , float64 (numSubnets ), * c .region , * vpc .VpcId )
192197}
193198
194199func (c * VPCCollector ) collectRoutesPerRouteTableQuota (ch chan <- prometheus.Metric ) {
@@ -204,15 +209,19 @@ func (c *VPCCollector) collectRoutesPerRouteTableQuota(ch chan<- prometheus.Metr
204209func (c * VPCCollector ) collectRoutesPerRouteTableUsage (ch chan <- prometheus.Metric , rtb * ec2.RouteTable ) {
205210 ctx , cancelFunc := context .WithTimeout (context .Background (), c .e .timeout )
206211 defer cancelFunc ()
207- descRouteTableOutput , err := c .ec2 .DescribeRouteTablesWithContext (ctx , & ec2.DescribeRouteTablesInput {
212+ output , err := c .ec2 .DescribeRouteTablesWithContext (ctx , & ec2.DescribeRouteTablesInput {
208213 RouteTableIds : []* string {rtb .RouteTableId },
209214 })
215+ if len (output .RouteTables ) != 1 {
216+ level .Error (c .e .logger ).Log ("msg" , "Unexpected number of routetables (!= 1) returned from DescribeRouteTables" )
217+ return
218+ }
210219 if err != nil {
211220 level .Error (c .e .logger ).Log ("msg" , "Call to DescribeRouteTables failed" , "region" , c .region , "err" , err )
212221 exporterMetrics .IncrementErrors ()
213222 return
214223 }
215- quota := len (descRouteTableOutput .RouteTables )
224+ quota := len (output .RouteTables [ 0 ]. Routes )
216225 ch <- prometheus .MustNewConstMetric (c .e .RoutesPerRouteTableUsage , prometheus .GaugeValue , float64 (quota ), * c .region , * rtb .VpcId , * rtb .RouteTableId )
217226}
218227
@@ -229,19 +238,22 @@ func (c *VPCCollector) collectInterfaceVpcEndpointsPerVpcQuota(ch chan<- prometh
229238func (c * VPCCollector ) collectInterfaceVpcEndpointsPerVpcUsage (ch chan <- prometheus.Metric , vpc * ec2.Vpc ) {
230239 ctx , cancelFunc := context .WithTimeout (context .Background (), c .e .timeout )
231240 defer cancelFunc ()
232- descVpcEndpoints , err := c .ec2 .DescribeVpcEndpointsWithContext (ctx , & ec2.DescribeVpcEndpointsInput {
233- Filters : []* ec2.Filter {{
234- Name : aws .String ("vpc-id" ),
235- Values : []* string {vpc .VpcId },
236- }},
241+
242+ numEndpoints := 0
243+ descEndpointsInput := & ec2.DescribeVpcEndpointsInput {
244+ Filters : []* ec2.Filter {{Name : aws .String ("vpc-id" ), Values : []* string {vpc .VpcId }}},
245+ }
246+ err := c .ec2 .DescribeVpcEndpointsPagesWithContext (ctx , descEndpointsInput , func (page * ec2.DescribeVpcEndpointsOutput , lastPage bool ) bool {
247+ numEndpoints += len (page .VpcEndpoints )
248+ return ! lastPage
237249 })
238250 if err != nil {
239251 level .Error (c .e .logger ).Log ("msg" , "Call to DescribeVpcEndpoints failed" , "region" , c .region , "err" , err )
240252 exporterMetrics .IncrementErrors ()
241253 return
242254 }
243- quota := len ( descVpcEndpoints . VpcEndpoints )
244- ch <- prometheus .MustNewConstMetric (c .e .InterfaceVpcEndpointsPerVpcUsage , prometheus .GaugeValue , float64 (quota ), * c .region , * vpc .VpcId )
255+
256+ ch <- prometheus .MustNewConstMetric (c .e .InterfaceVpcEndpointsPerVpcUsage , prometheus .GaugeValue , float64 (numEndpoints ), * c .region , * vpc .VpcId )
245257}
246258
247259func (c * VPCCollector ) collectRoutesTablesPerVpcQuota (ch chan <- prometheus.Metric ) {
@@ -257,19 +269,22 @@ func (c *VPCCollector) collectRoutesTablesPerVpcQuota(ch chan<- prometheus.Metri
257269func (c * VPCCollector ) collectRoutesTablesPerVpcUsage (ch chan <- prometheus.Metric , vpc * ec2.Vpc ) {
258270 ctx , cancelFunc := context .WithTimeout (context .Background (), c .e .timeout )
259271 defer cancelFunc ()
260- descRouteTables , err := c .ec2 .DescribeRouteTablesWithContext (ctx , & ec2.DescribeRouteTablesInput {
272+ var numRouteTables int
273+ input := & ec2.DescribeRouteTablesInput {
261274 Filters : []* ec2.Filter {{
262275 Name : aws .String ("vpc-id" ),
263276 Values : []* string {vpc .VpcId },
264- }},
277+ }}}
278+ err := c .ec2 .DescribeRouteTablesPagesWithContext (ctx , input , func (page * ec2.DescribeRouteTablesOutput , lastPage bool ) bool {
279+ numRouteTables += len (page .RouteTables )
280+ return ! lastPage
265281 })
266282 if err != nil {
267283 level .Error (c .e .logger ).Log ("msg" , "Call to DescribeRouteTables failed" , "region" , c .region , "err" , err )
268284 exporterMetrics .IncrementErrors ()
269285 return
270286 }
271- quota := len (descRouteTables .RouteTables )
272- ch <- prometheus .MustNewConstMetric (c .e .RouteTablesPerVpcUsage , prometheus .GaugeValue , float64 (quota ), * c .region , * vpc .VpcId )
287+ ch <- prometheus .MustNewConstMetric (c .e .RouteTablesPerVpcUsage , prometheus .GaugeValue , float64 (numRouteTables ), * c .region , * vpc .VpcId )
273288}
274289
275290func (c * VPCCollector ) collectIPv4BlocksPerVpcQuota (ch chan <- prometheus.Metric ) {
@@ -285,18 +300,19 @@ func (c *VPCCollector) collectIPv4BlocksPerVpcQuota(ch chan<- prometheus.Metric)
285300func (c * VPCCollector ) collectIPv4BlocksPerVpcUsage (ch chan <- prometheus.Metric , vpc * ec2.Vpc ) {
286301 ctx , cancelFunc := context .WithTimeout (context .Background (), c .e .timeout )
287302 defer cancelFunc ()
288- descVpcs , err := c . ec2 . DescribeVpcsWithContext ( ctx , & ec2.DescribeVpcsInput {
303+ input := & ec2.DescribeVpcsInput {
289304 VpcIds : []* string {vpc .VpcId },
290- })
305+ }
306+ output , err := c .ec2 .DescribeVpcsWithContext (ctx , input )
291307 if err != nil {
292308 level .Error (c .e .logger ).Log ("msg" , "Call to DescribeVpcs failed" , "region" , c .region , "err" , err )
293309 exporterMetrics .IncrementErrors ()
294310 return
295311 }
296- if len (descVpcs .Vpcs ) != 1 {
312+ if len (output .Vpcs ) != 1 {
297313 level .Error (c .e .logger ).Log ("msg" , "Unexpected numbers of VPCs (!= 1) returned" , "region" , c .region , "vpcId" , vpc .VpcId )
298314 }
299- quota := len (descVpcs .Vpcs [0 ].CidrBlockAssociationSet )
315+ quota := len (output .Vpcs [0 ].CidrBlockAssociationSet )
300316 ch <- prometheus .MustNewConstMetric (c .e .IPv4BlocksPerVpcUsage , prometheus .GaugeValue , float64 (quota ), * c .region , * vpc .VpcId )
301317}
302318
0 commit comments