@@ -95,7 +95,7 @@ func (e *VPCExporter) CollectInRegion(session *session.Session, region *string,
95
95
if err != nil {
96
96
level .Error (e .logger ).Log ("msg" , "Call to DescribeVpcs failed" , "region" , region , "err" , err )
97
97
} else {
98
- for i , _ := range allVpcs .Vpcs {
98
+ for i := range allVpcs .Vpcs {
99
99
e .collectSubnetsPerVpcUsage (allVpcs .Vpcs [i ], ec2Svc , * region )
100
100
e .collectInterfaceVpcEndpointsPerVpcUsage (allVpcs .Vpcs [i ], ec2Svc , * region )
101
101
e .collectRoutesTablesPerVpcUsage (allVpcs .Vpcs [i ], ec2Svc , * region )
@@ -109,7 +109,7 @@ func (e *VPCExporter) CollectInRegion(session *session.Session, region *string,
109
109
if err != nil {
110
110
level .Error (e .logger ).Log ("msg" , "Call to DescribeRouteTables failed" , "region" , region , "err" , err )
111
111
} else {
112
- for i , _ := range allRouteTables .RouteTables {
112
+ for i := range allRouteTables .RouteTables {
113
113
e .collectRoutesPerRouteTableUsage (allRouteTables .RouteTables [i ], ec2Svc , * region )
114
114
}
115
115
}
@@ -120,7 +120,7 @@ func (e *VPCExporter) CollectLoop() {
120
120
121
121
wg := & sync.WaitGroup {}
122
122
wg .Add (len (e .sessions ))
123
- for i , _ := range e .sessions {
123
+ for i := range e .sessions {
124
124
session := e .sessions [i ]
125
125
region := session .Config .Region
126
126
go e .CollectInRegion (session , region , wg )
@@ -167,14 +167,17 @@ func (e *VPCExporter) collectVpcsPerRegionQuota(client *servicequotas.ServiceQuo
167
167
func (e * VPCExporter ) collectVpcsPerRegionUsage (ec2Svc * ec2.EC2 , region string ) {
168
168
ctx , cancelFunc := context .WithTimeout (context .Background (), e .timeout )
169
169
defer cancelFunc ()
170
- describeVpcsOutput , err := ec2Svc .DescribeVpcsWithContext (ctx , & ec2.DescribeVpcsInput {})
170
+ numVpcs := 0
171
+ err := ec2Svc .DescribeVpcsPagesWithContext (ctx , & ec2.DescribeVpcsInput {}, func (page * ec2.DescribeVpcsOutput , lastPage bool ) bool {
172
+ numVpcs += len (page .Vpcs )
173
+ return ! lastPage
174
+ })
171
175
if err != nil {
172
176
level .Error (e .logger ).Log ("msg" , "Call to DescribeVpcs failed" , "region" , region , "err" , err )
173
177
exporterMetrics .IncrementErrors ()
174
178
return
175
179
}
176
- usage := len (describeVpcsOutput .Vpcs )
177
- e .cache .AddMetric (prometheus .MustNewConstMetric (e .VpcsPerRegionUsage , prometheus .GaugeValue , float64 (usage ), region ))
180
+ e .cache .AddMetric (prometheus .MustNewConstMetric (e .VpcsPerRegionUsage , prometheus .GaugeValue , float64 (numVpcs ), region ))
178
181
}
179
182
180
183
func (e * VPCExporter ) collectSubnetsPerVpcQuota (client * servicequotas.ServiceQuotas , region string ) {
@@ -190,19 +193,21 @@ func (e *VPCExporter) collectSubnetsPerVpcQuota(client *servicequotas.ServiceQuo
190
193
func (e * VPCExporter ) collectSubnetsPerVpcUsage (vpc * ec2.Vpc , ec2Svc * ec2.EC2 , region string ) {
191
194
ctx , cancelFunc := context .WithTimeout (context .Background (), e .timeout )
192
195
defer cancelFunc ()
193
- describeSubnetsOutput , err := ec2Svc .DescribeSubnetsWithContext (ctx , & ec2.DescribeSubnetsInput {
194
- Filters : []* ec2.Filter {& ec2.Filter {
196
+ numSubnets := 0
197
+ err := ec2Svc .DescribeSubnetsPagesWithContext (ctx , & ec2.DescribeSubnetsInput {
198
+ Filters : []* ec2.Filter {{
195
199
Name : aws .String ("vpc-id" ),
196
200
Values : []* string {vpc .VpcId },
197
- }},
201
+ }}}, func (page * ec2.DescribeSubnetsOutput , lastPage bool ) bool {
202
+ numSubnets += len (page .Subnets )
203
+ return ! lastPage
198
204
})
199
205
if err != nil {
200
206
level .Error (e .logger ).Log ("msg" , "Call to DescribeSubnets failed" , "region" , region , "err" , err )
201
207
exporterMetrics .IncrementErrors ()
202
208
return
203
209
}
204
- usage := len (describeSubnetsOutput .Subnets )
205
- e .cache .AddMetric (prometheus .MustNewConstMetric (e .SubnetsPerVpcUsage , prometheus .GaugeValue , float64 (usage ), region , * vpc .VpcId ))
210
+ e .cache .AddMetric (prometheus .MustNewConstMetric (e .SubnetsPerVpcUsage , prometheus .GaugeValue , float64 (numSubnets ), region , * vpc .VpcId ))
206
211
}
207
212
208
213
func (e * VPCExporter ) collectRoutesPerRouteTableQuota (client * servicequotas.ServiceQuotas , region string ) {
@@ -221,6 +226,10 @@ func (e *VPCExporter) collectRoutesPerRouteTableUsage(rtb *ec2.RouteTable, ec2Sv
221
226
descRouteTableOutput , err := ec2Svc .DescribeRouteTablesWithContext (ctx , & ec2.DescribeRouteTablesInput {
222
227
RouteTableIds : []* string {rtb .RouteTableId },
223
228
})
229
+ if len (descRouteTableOutput .RouteTables ) != 1 {
230
+ level .Error (e .logger ).Log ("msg" , "Unexpected number of routetables (!= 1) returned from DescribeRouteTables" )
231
+ return
232
+ }
224
233
if err != nil {
225
234
level .Error (e .logger ).Log ("msg" , "Call to DescribeRouteTables failed" , "region" , region , "err" , err )
226
235
exporterMetrics .IncrementErrors ()
@@ -243,19 +252,21 @@ func (e *VPCExporter) collectInterfaceVpcEndpointsPerVpcQuota(client *servicequo
243
252
func (e * VPCExporter ) collectInterfaceVpcEndpointsPerVpcUsage (vpc * ec2.Vpc , ec2Svc * ec2.EC2 , region string ) {
244
253
ctx , cancelFunc := context .WithTimeout (context .Background (), e .timeout )
245
254
defer cancelFunc ()
246
- descVpcEndpoints , err := ec2Svc .DescribeVpcEndpointsWithContext (ctx , & ec2.DescribeVpcEndpointsInput {
247
- Filters : []* ec2.Filter {{
248
- Name : aws .String ("vpc-id" ),
249
- Values : []* string {vpc .VpcId },
250
- }},
255
+
256
+ numEndpoints := 0
257
+ descEndpointsInput := & ec2.DescribeVpcEndpointsInput {
258
+ Filters : []* ec2.Filter {{Name : aws .String ("vpc-id" ), Values : []* string {vpc .VpcId }}},
259
+ }
260
+ err := ec2Svc .DescribeVpcEndpointsPagesWithContext (ctx , descEndpointsInput , func (page * ec2.DescribeVpcEndpointsOutput , lastPage bool ) bool {
261
+ numEndpoints += len (page .VpcEndpoints )
262
+ return ! lastPage
251
263
})
252
264
if err != nil {
253
265
level .Error (e .logger ).Log ("msg" , "Call to DescribeVpcEndpoints failed" , "region" , region , "err" , err )
254
266
exporterMetrics .IncrementErrors ()
255
267
return
256
268
}
257
- quota := len (descVpcEndpoints .VpcEndpoints )
258
- e .cache .AddMetric (prometheus .MustNewConstMetric (e .InterfaceVpcEndpointsPerVpcUsage , prometheus .GaugeValue , float64 (quota ), region , * vpc .VpcId ))
269
+ e .cache .AddMetric (prometheus .MustNewConstMetric (e .InterfaceVpcEndpointsPerVpcUsage , prometheus .GaugeValue , float64 (numEndpoints ), region , * vpc .VpcId ))
259
270
}
260
271
261
272
func (e * VPCExporter ) collectRoutesTablesPerVpcQuota (client * servicequotas.ServiceQuotas , region string ) {
@@ -271,19 +282,22 @@ func (e *VPCExporter) collectRoutesTablesPerVpcQuota(client *servicequotas.Servi
271
282
func (e * VPCExporter ) collectRoutesTablesPerVpcUsage (vpc * ec2.Vpc , ec2Svc * ec2.EC2 , region string ) {
272
283
ctx , cancelFunc := context .WithTimeout (context .Background (), e .timeout )
273
284
defer cancelFunc ()
274
- descRouteTables , err := ec2Svc .DescribeRouteTablesWithContext (ctx , & ec2.DescribeRouteTablesInput {
285
+ var numRouteTables int
286
+ input := & ec2.DescribeRouteTablesInput {
275
287
Filters : []* ec2.Filter {{
276
288
Name : aws .String ("vpc-id" ),
277
289
Values : []* string {vpc .VpcId },
278
- }},
290
+ }}}
291
+ err := ec2Svc .DescribeRouteTablesPagesWithContext (ctx , input , func (page * ec2.DescribeRouteTablesOutput , lastPage bool ) bool {
292
+ numRouteTables += len (page .RouteTables )
293
+ return ! lastPage
279
294
})
280
295
if err != nil {
281
296
level .Error (e .logger ).Log ("msg" , "Call to DescribeRouteTables failed" , "region" , region , "err" , err )
282
297
exporterMetrics .IncrementErrors ()
283
298
return
284
299
}
285
- quota := len (descRouteTables .RouteTables )
286
- e .cache .AddMetric (prometheus .MustNewConstMetric (e .RouteTablesPerVpcUsage , prometheus .GaugeValue , float64 (quota ), region , * vpc .VpcId ))
300
+ e .cache .AddMetric (prometheus .MustNewConstMetric (e .RouteTablesPerVpcUsage , prometheus .GaugeValue , float64 (numRouteTables ), region , * vpc .VpcId ))
287
301
}
288
302
289
303
func (e * VPCExporter ) collectIPv4BlocksPerVpcQuota (client * servicequotas.ServiceQuotas , region string ) {
0 commit comments