Skip to content

specify StartRecordName, StartRecordType for displaying next page of …#104

Merged
j3ttt merged 3 commits intoantgroup:mainfrom
j3ttt:fix/aws-memory-leak
Jan 26, 2026
Merged

specify StartRecordName, StartRecordType for displaying next page of …#104
j3ttt merged 3 commits intoantgroup:mainfrom
j3ttt:fix/aws-memory-leak

Conversation

@j3ttt
Copy link
Collaborator

@j3ttt j3ttt commented Jan 26, 2026

…ListResourceRecordSets

Thank you for your contribution to CloudRec!

What About:

  • Server (java)
  • Collector (go)
  • Rule (opa)

Description:

fix #103 #102
ref: https://docs.aws.amazon.com/Route53/latest/APIReference/API_ListResourceRecordSets.html

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @j3ttt, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request refines the pagination mechanism within the Go collector for AWS Route53's ListResourceRecordSets API. By incorporating the StartRecordName and StartRecordType fields, the collector can now accurately fetch all resource record sets across multiple pages, resolving previous issues with incomplete data retrieval.

Highlights

  • Route53 Pagination Enhancement: The pagination logic for listing AWS Route53 resource record sets has been improved by correctly passing StartRecordName and StartRecordType parameters in subsequent API calls. This ensures that all records are retrieved when the initial response is truncated.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request correctly fixes a pagination issue in listResourceRecordSets by adding StartRecordName and StartRecordType to the request for subsequent pages. This aligns with the AWS API documentation and ensures all resource record sets are retrieved. My review includes a suggestion to refactor the pagination logic using the AWS SDK's built-in paginator for improved code simplicity and robustness.

Comment on lines +100 to +101
input.StartRecordName = output.NextRecordName
input.StartRecordType = output.NextRecordType
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

While adding these parameters correctly fixes the pagination bug, the manual handling of pagination is complex and error-prone, as this bug demonstrates. The AWS SDK for Go v2 provides paginators that handle this logic automatically.

Consider refactoring the listResourceRecordSets function to use the ListResourceRecordSetsPaginator. This would make the code simpler, more idiomatic, and more robust.

Here's an example of how the entire function could be simplified:

func listResourceRecordSets(ctx context.Context, c *route53.Client, hostZone types.HostedZone) (resourceRecordSets []types.ResourceRecordSet) {
	input := &route53.ListResourceRecordSetsInput{
		HostedZoneId: hostZone.Id,
	}
	paginator := route53.NewListResourceRecordSetsPaginator(c, input)

	for paginator.HasMorePages() {
		output, err := paginator.NextPage(ctx)
		if err != nil {
			log.CtxLogger(ctx).Warn("listResourceRecordSets error", zap.Error(err))
			return nil
		}
		resourceRecordSets = append(resourceRecordSets, output.ResourceRecordSets...)
	}

	return resourceRecordSets
}

This approach would also be beneficial for other functions in the codebase that perform manual pagination, like listHostedZones.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

apply

@j3ttt
Copy link
Collaborator Author

j3ttt commented Jan 26, 2026

/gemini review

@j3ttt
Copy link
Collaborator Author

j3ttt commented Jan 26, 2026

@gemini-code-assist review

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request correctly refactors the listResourceRecordSets function to use the AWS SDK v2 paginator. This is an excellent change that fixes a bug in the previous manual pagination logic and makes the code more idiomatic and robust.

I've added one comment regarding error handling. The current implementation swallows errors, while other functions in the same file propagate them. Aligning the error handling strategy would improve the overall robustness of the collector.

As a potential follow-up, you could consider applying the same paginator pattern to other functions that handle pagination manually, such as listHostedZones in this file and listDomains in collector/aws/collector/route53/domain.go, to further improve consistency.

Comment on lines 95 to 97
if err != nil {
log.CtxLogger(ctx).Warn("listResourceRecordSets error", zap.Error(err))
return nil
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The error is logged, but then nil is returned without propagating the error itself. This prevents the caller from reacting to the failure and can lead to silent data collection issues. Other functions in this file, such as listHostedZones, return an error to the caller, which is a more robust pattern.

For consistency and to avoid silent failures, consider changing the function signature to return an error:

func listResourceRecordSets(ctx context.Context, c *route53.Client, hostZone types.HostedZone) ([]types.ResourceRecordSet, error)

Then you can return nil, err here. This would require updating the call site in describeDomainRRDetails, but it would make the error handling much more robust.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request addresses a bug in the pagination logic for listing Route53 resource record sets. The previous manual implementation was incorrect because it failed to set StartRecordName and StartRecordType for subsequent page requests, which could lead to incomplete data collection.

The change replaces the faulty manual pagination with the AWS SDK v2's ListResourceRecordSetsPaginator. This is an excellent improvement as it leverages the idiomatic way to handle pagination, ensuring correctness and making the code simpler and more robust.

Additionally, the pull request fixes a typo in the filename resourcerecordset.go.go.

Overall, this is a solid contribution that improves both correctness and code quality.

@j3ttt j3ttt merged commit 05f627b into antgroup:main Jan 26, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

aws 的 collector有内存泄漏

1 participant