-
Notifications
You must be signed in to change notification settings - Fork 3.4k
aws/ec2: properly paginate DescribeNetworkInterfaces
results
#37983
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
pchaigno
merged 1 commit into
cilium:main
from
DataDog:ai/ec2-describenetworkinterfaces-pagination
Mar 18, 2025
Merged
aws/ec2: properly paginate DescribeNetworkInterfaces
results
#37983
pchaigno
merged 1 commit into
cilium:main
from
DataDog:ai/ec2-describenetworkinterfaces-pagination
Mar 18, 2025
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Signed-off-by: Anton Ippolitov <anton.ippolitov@datadoghq.com>
/test |
thorn3r
approved these changes
Mar 4, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 👍 thanks for the fix
doniacld
approved these changes
Mar 6, 2025
13 tasks
3 tasks
8 tasks
8 tasks
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
area/eni
Impacts ENI based IPAM.
area/operator
Impacts the cilium-operator component
backport-done/1.17
The backport for Cilium 1.17.x for this PR is done.
ready-to-merge
This PR has passed all tests and received consensus from code owners to merge.
release-note/bug
This PR fixes an issue in a previous release of Cilium.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
Follow-up to #14491
We noticed that
DescribeNetworkInterfaces
API calls are not properly paginated. The code usesec2.NewDescribeNetworkInterfacesPaginator
but:MaxResults
inDescribeNetworkInterfacesInput
,Limit
in the Paginator options:This causes pages to have unlimited size because
MaxResults
ends up not being set: https://github.com/aws/aws-sdk-go-v2/blob/2d43b815f645eae163e7521c9789554dfe60e40c/service/ec2/api_op_DescribeNetworkInterfaces.go#L548-L552This PR fixes the issue by adding
MaxResults
to the API calls in order to actually force pagination.Testing
Before the PR
Test 1
I did some testing in an AWS account which has ~19000 ENIs. I deployed the Operator without
--subnet-tags-filter
and added logging to thedescribeNetworkInterfaces()
function. The log showed that there was only 1 page with ~19000 results.API call duration went through the roof (>10 seconds):

(comparison before vs after I removed
--subnet-tags-filter
)The memory also more than doubled:

Test 2
We also tried deploying the Operator without
--subnet-tags-filter
in a larger account and got the following error from the AWS API:According to AWS docs:
Which is exactly what's happening here: the filters are not specified and pagination is disabled, so we get a 400 error from the API.
After the PR
I confirmed with logging, that the calls are now properly paginated:

Moreover, the duration of API calls dropped:

However, the memory usage stayed the same unfortunately:

This is due to the fact that all results are still all added to the same big slice:
cilium/pkg/aws/ec2/ec2.go
Line 248 in d1e7f3a
However, the pagination is still beneficial, because we do not risk running into 400 errors from the API or be "susceptible to throttling and timeouts"
Notes
DescribeInstanceTypes
,DescribeVpcs
,DescribeSubnets
, andDescribeSecurityGroups
, which aren’t paginated properly either. However, the impact is most noticeable for ENIs, since they’re far more numerous and the fix will have the biggest effect there. We can address the other API calls in a separate PR.describeNetworkInterfacesByInstance()
because the number of returned of results should be very small anyway. I added the change there for the sake of consistency.GetDetachedNetworkInterfaces()
is a bit strange: it actually uses pagination but the number of returned ENIs can exceedmaxResults
passed in the parameters. Mainly, this can happen here if the first page returnsx
results wherex < maxResults
and then the second page returns for example exactlymaxResults
, so the length ofresult
will bemaxResults + x > maxResults
. Thebreak
should happen inside the loop onoutput.NetworkInterfaces
. I think the fix for this problem is out of scope for this PR though.