-
Notifications
You must be signed in to change notification settings - Fork 24
baidu resource enrich #111
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
Open
Center-Sun
wants to merge
2
commits into
antgroup:main
Choose a base branch
from
Center-Sun:feat/baidu-resource-enrich
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,18 +16,54 @@ | |
| package blb | ||
|
|
||
| import ( | ||
| "github.com/core-sdk/constant" | ||
| "github.com/core-sdk/log" | ||
| "github.com/core-sdk/schema" | ||
| "context" | ||
| "strconv" | ||
|
|
||
| "github.com/baidubce/bce-sdk-go/bce" | ||
| "github.com/baidubce/bce-sdk-go/services/blb" | ||
| "github.com/cloudrec/baidu/collector" | ||
| "github.com/core-sdk/constant" | ||
| "github.com/core-sdk/log" | ||
| "github.com/core-sdk/schema" | ||
| "go.uber.org/zap" | ||
| ) | ||
|
|
||
| // enrichedBLB embeds blb.BLBModel so all existing JSON paths under $.Blb.* | ||
| // remain unchanged. Fields below are returned by /v1/blb but not modeled by | ||
| // the baidu SDK's BLBModel — captured here so collector content stays a | ||
| // superset of the raw API response. | ||
| type enrichedBLB struct { | ||
| blb.BLBModel | ||
| Type string `json:"type"` | ||
| UnderlayVip string `json:"underlayVip"` | ||
| ExpireTime string `json:"expireTime"` | ||
| BillingMethod string `json:"billingMethod"` | ||
| PaymentTiming string `json:"paymentTiming"` | ||
| PerformanceLevel string `json:"performanceLevel"` | ||
| AllowModify bool `json:"allowModify"` | ||
| ModificationProtectionReason string `json:"modificationProtectionReason"` | ||
| } | ||
|
|
||
| // enrichedBLBListener adds two fields the SDK's AllListenerModel doesn't model. | ||
| type enrichedBLBListener struct { | ||
| blb.AllListenerModel | ||
| BackendPortType string `json:"backendPortType"` | ||
| HealthCheckValid int `json:"healthCheckValid"` | ||
| } | ||
|
|
||
| type enrichedDescribeLoadBalancersResult struct { | ||
| BlbList []enrichedBLB `json:"blbList"` | ||
| blb.DescribeResultMeta | ||
| } | ||
|
|
||
| type enrichedDescribeAllListenersResult struct { | ||
| ListenerList []enrichedBLBListener `json:"listenerList"` | ||
| blb.DescribeResultMeta | ||
| } | ||
|
|
||
| type Detail struct { | ||
| Blb blb.BLBModel | ||
| ListenerList []blb.AllListenerModel | ||
| Blb enrichedBLB | ||
| ListenerList []enrichedBLBListener | ||
| BlbSecurityGroups []blb.BlbSecurityGroupModel | ||
| BlbEnterpriseSecurityGroups []blb.BlbEnterpriseSecurityGroupModel | ||
| BackendServerList []blb.BackendServerModel | ||
|
|
@@ -52,9 +88,9 @@ func GetResource() schema.Resource { | |
| ResourceDetailFunc: func(ctx context.Context, service schema.ServiceInterface, res chan<- any) error { | ||
| client := service.(*collector.Services).BLBClient | ||
|
|
||
| args := &blb.DescribeLoadBalancersArgs{} | ||
| marker := "" | ||
| for { | ||
| response, err := client.DescribeLoadBalancers(args) | ||
| response, err := describeLoadBalancersEnriched(ctx, client, marker) | ||
| if err != nil { | ||
| log.CtxLogger(ctx).Warn("DescribeLoadBalancers error", zap.Error(err)) | ||
| return err | ||
|
|
@@ -72,7 +108,7 @@ func GetResource() schema.Resource { | |
| if response.NextMarker == "" { | ||
| break | ||
| } | ||
| args.Marker = response.NextMarker | ||
| marker = response.NextMarker | ||
| } | ||
|
|
||
| return nil | ||
|
|
@@ -86,25 +122,47 @@ func GetResource() schema.Resource { | |
| } | ||
| } | ||
|
|
||
| func describeAllListeners(ctx context.Context, client *blb.Client, blbId string) (listenerList []blb.AllListenerModel) { | ||
| args := &blb.DescribeListenerArgs{ | ||
| Marker: "", | ||
| MaxKeys: 50, | ||
| // describeLoadBalancersEnriched issues GET /v1/blb and decodes into a struct | ||
| // that captures both the SDK-modeled fields and the SDK-omitted ones. Pagination | ||
| // follows the same NextMarker convention as the SDK. | ||
| func describeLoadBalancersEnriched(ctx context.Context, client *blb.Client, marker string) (*enrichedDescribeLoadBalancersResult, error) { | ||
| result := &enrichedDescribeLoadBalancersResult{} | ||
| rb := bce.NewRequestBuilder(client). | ||
| WithMethod("GET"). | ||
| WithURL("/v1/blb"). | ||
| WithQueryParam("maxKeys", strconv.Itoa(1000)). | ||
| WithResult(result) | ||
| if marker != "" { | ||
| rb = rb.WithQueryParam("marker", marker) | ||
| } | ||
| if err := rb.Do(); err != nil { | ||
| return nil, err | ||
| } | ||
| return result, nil | ||
| } | ||
|
|
||
| func describeAllListeners(ctx context.Context, client *blb.Client, blbId string) (listenerList []enrichedBLBListener) { | ||
| marker := "" | ||
| for { | ||
| response, err := client.DescribeAllListeners(blbId, args) | ||
| if err != nil { | ||
| result := &enrichedDescribeAllListenersResult{} | ||
| rb := bce.NewRequestBuilder(client). | ||
| WithMethod("GET"). | ||
| WithURL("/v1/blb/" + blbId + "/listener"). | ||
| WithQueryParam("maxKeys", strconv.Itoa(50)). | ||
| WithResult(result) | ||
| if marker != "" { | ||
| rb = rb.WithQueryParam("marker", marker) | ||
| } | ||
| if err := rb.Do(); err != nil { | ||
| log.CtxLogger(ctx).Warn("DescribeAllListeners error", zap.Error(err)) | ||
| return | ||
| } | ||
| listenerList = append(listenerList, response.AllListenerList...) | ||
| if response.NextMarker == "" { | ||
| listenerList = append(listenerList, result.ListenerList...) | ||
| if result.NextMarker == "" { | ||
| break | ||
| } | ||
| args.Marker = response.NextMarker | ||
| marker = result.NextMarker | ||
| } | ||
|
|
||
| return listenerList | ||
| } | ||
|
Comment on lines
+144
to
167
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
|
||
|
|
||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -32,4 +32,6 @@ const ( | |
| BLS = "BLS" | ||
| CFW = "CFW" | ||
| CCERBAC = "CCERBAC" | ||
| ENI = "ENI" | ||
| ACL = "ACL" | ||
| ) | ||
Oops, something went wrong.
Oops, something went wrong.
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.
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 function
describeAppAllListeners(and similarlydescribeAppServerGroupat line 207) swallows errors from the API call, returning a potentially empty or partial list without notifying the caller. This can lead to incomplete resource data being collected silently. Consider updating these functions to return an error along with the results, allowing the caller to handle API failures more robustly.