-
Notifications
You must be signed in to change notification settings - Fork 21
fix:tencent clb add sg detail fields #89
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
Conversation
Reviewer's GuideEnhances the Tencent CLB collector by integrating VPC policy retrieval: adds a new SecurityGroupDetail field, refactors client usage to include VPC, implements a helper to fetch security group policies, and initializes the VPC client in the service setup. Sequence diagram for CLB resource listing with security group detail retrievalsequenceDiagram
participant Service as "Services"
participant CLB as "CLB Client"
participant VPC as "VPC Client"
participant LBDetail as "LBDetail"
Service->>CLB: DescribeLoadBalancers
CLB-->>Service: LoadBalancerSet
loop for each LoadBalancer
Service->>CLB: describeTargets(LoadBalancerId)
CLB-->>Service: Listeners
Service->>VPC: describeSecurityGroups(SecureGroups)
VPC-->>Service: SecurityGroupPolicySet[]
Service->>LBDetail: Construct LBDetail with SecurityGroupDetail
end
Class diagram for updated LBDetail and Services structuresclassDiagram
class LBDetail {
clb.LoadBalancer LoadBalancer
clb.ListenerBackend[] Listeners
string[] SecureGroups
vpc.SecurityGroupPolicySet[] SecurityGroupDetail
}
class Services {
CLB
VPC
// ... other clients
}
LBDetail -- clb.LoadBalancer
LBDetail -- clb.ListenerBackend
LBDetail -- vpc.SecurityGroupPolicySet
Services -- CLB
Services -- VPC
Class diagram for describeSecurityGroups helper functionclassDiagram
class describeSecurityGroups {
+describeSecurityGroups(ctx, cli, securityGroupIds) vpc.SecurityGroupPolicySet[]
}
describeSecurityGroups -- vpc.Client
describeSecurityGroups -- vpc.SecurityGroupPolicySet
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Summary of ChangesHello @Lyc-heng, 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 significantly improves the data collection capabilities for Tencent Cloud Load Balancers by integrating detailed security group policy information. The change addresses a gap where only security group IDs were available, preventing proper inspection of security rules. By introducing a new field and leveraging the Tencent Cloud VPC API, the system can now collect and store comprehensive security group policies associated with CLBs. Highlights
Using Gemini Code AssistThe 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
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 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
|
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.
Hey there - I've reviewed your changes - here's some feedback:
- Initializing the VPC client logs errors but doesn’t stop execution—if VPC client fails to initialize you’ll get panics later; consider returning an error or skipping CLB calls that need it.
- describeSecurityGroups returns nil and stops on the first API error, losing previously fetched details—either propagate errors or collect partial results and continue.
- Calling DescribeSecurityGroupPolicies one ID at a time can be slow; if the API supports batching multiple security group IDs, consider fetching them in bulk.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Initializing the VPC client logs errors but doesn’t stop execution—if VPC client fails to initialize you’ll get panics later; consider returning an error or skipping CLB calls that need it.
- describeSecurityGroups returns nil and stops on the first API error, losing previously fetched details—either propagate errors or collect partial results and continue.
- Calling DescribeSecurityGroupPolicies one ID at a time can be slow; if the API supports batching multiple security group IDs, consider fetching them in bulk.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
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.
Code Review
This pull request correctly adds the functionality to fetch detailed security group information for Tencent Cloud Load Balancers. The changes are logical and well-structured. I've pointed out two high-severity issues: one related to error handling in clb.go where partial data could be lost, and another in services.go concerning the overwriting of an error variable which could mask initialization failures. Please see the detailed comments for suggestions on how to fix these.
| if err != nil { | ||
| log.CtxLogger(ctx).Warn("Describe SecurityGroupPolicies error", zap.Error(err)) | ||
| return nil | ||
| } |
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.
Returning nil on error will cause the loss of all security group information that might have been successfully fetched before the error occurred. It's better to log the error and continue the loop to collect as much data as possible. I've also added the security group ID to the log message for better context during debugging.
| if err != nil { | |
| log.CtxLogger(ctx).Warn("Describe SecurityGroupPolicies error", zap.Error(err)) | |
| return nil | |
| } | |
| if err != nil { | |
| log.CtxLogger(ctx).Warn("Describe SecurityGroupPolicies error", zap.Error(err), zap.Stringp("securityGroupId", securityGroupId)) | |
| continue | |
| } |
| s.VPC, err = createVPCClient(param.Region, s.Credential) | ||
| if err != nil { | ||
| log.GetWLogger().Error(fmt.Sprintf("failed to initialize VPC client in region:%s, err:%s", param.Region, err.Error())) | ||
| } |
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.
The error variable err is being reused here. If createCLBClient on line 110 returned an error, it would be overwritten by the result of createVPCClient, potentially masking the original error if createVPCClient succeeds. It's better to use a separate variable for the error from createVPCClient to avoid this.
| s.VPC, err = createVPCClient(param.Region, s.Credential) | |
| if err != nil { | |
| log.GetWLogger().Error(fmt.Sprintf("failed to initialize VPC client in region:%s, err:%s", param.Region, err.Error())) | |
| } | |
| var vpcErr error | |
| s.VPC, vpcErr = createVPCClient(param.Region, s.Credential) | |
| if vpcErr != nil { | |
| log.GetWLogger().Error(fmt.Sprintf("failed to initialize VPC client in region:%s, err:%s", param.Region, vpcErr.Error())) | |
| } |
Thank you for your contribution to CloudRec!
What About:
java)go)opa)Description:
Tencent Cloud CLB adds
SecurityGroupDetailfield for security groups, as the existingSecureGroupsfield cannot support the inspection of security group rules.Summary by Sourcery
Add detailed security group policy retrieval to Tencent CLB collector and include it in load balancer resources
New Features:
Enhancements: