-
Notifications
You must be signed in to change notification settings - Fork 375
Fix the batched describe insance method for instance not found case #1260
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -57,6 +57,9 @@ func (b *describeInstanceBatcher) DescribeInstances(ctx context.Context, input * | |
| return nil, fmt.Errorf("expected to receive a single instance only, found %d", len(input.InstanceIds)) | ||
| } | ||
| result := b.batcher.Add(ctx, input) | ||
| if result.Output == nil { | ||
| return nil, result.Err | ||
| } | ||
| return []*ec2types.Instance{result.Output}, result.Err | ||
| } | ||
|
|
||
|
|
@@ -74,7 +77,8 @@ func describeInstanceHasher(ctx context.Context, input *ec2.DescribeInstancesInp | |
| func execDescribeInstanceBatch(ec2api iface.EC2) batcher.BatchExecutor[ec2.DescribeInstancesInput, ec2types.Instance] { | ||
| return func(ctx context.Context, inputs []*ec2.DescribeInstancesInput) []batcher.Result[ec2types.Instance] { | ||
| results := make([]batcher.Result[ec2types.Instance], len(inputs)) | ||
| firstInput := inputs[0] | ||
|
|
||
| firstInput := *inputs[0] | ||
|
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. why did we translate this from a pointer? can potentially cause another panic?
Member
Author
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. if we don't translate we are overriding it in the below for loop as firstInput would just be a pointer to the first item item in slice. inputs should never have nil items for the panic to happen and there should always be atleast 1 item in the inputs.
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. Should we still have a
Member
Author
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. yes, we are guaranteed to not have empty list as this gets called only when we make a describe instance call and there it verifies the instance count. |
||
| // aggregate instanceIDs into 1 input | ||
| for _, input := range inputs[1:] { | ||
| firstInput.InstanceIds = append(firstInput.InstanceIds, input.InstanceIds...) | ||
|
|
@@ -92,7 +96,7 @@ func execDescribeInstanceBatch(ec2api iface.EC2) batcher.BatchExecutor[ec2.Descr | |
| go func(input *ec2.DescribeInstancesInput) { | ||
| defer wg.Done() | ||
| out, err := ec2api.DescribeInstances(ctx, input) | ||
| if err != nil { | ||
| if err != nil || len(out) == 0 { | ||
| results[idx] = batcher.Result[ec2types.Instance]{Output: nil, Err: err} | ||
| return | ||
| } | ||
|
|
@@ -104,7 +108,11 @@ func execDescribeInstanceBatch(ec2api iface.EC2) batcher.BatchExecutor[ec2.Descr | |
| instanceIDToOutputMap := map[string]ec2types.Instance{} | ||
| lo.ForEach(output, func(o ec2types.Instance, _ int) { instanceIDToOutputMap[lo.FromPtr(o.InstanceId)] = o }) | ||
| for idx, input := range inputs { | ||
| o := instanceIDToOutputMap[input.InstanceIds[0]] | ||
| o, ok := instanceIDToOutputMap[input.InstanceIds[0]] | ||
| if !ok { | ||
| results[idx] = batcher.Result[ec2types.Instance]{Output: nil} | ||
| continue | ||
| } | ||
| results[idx] = batcher.Result[ec2types.Instance]{Output: &o} | ||
| } | ||
| } | ||
|
|
||
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.
is
if result.Err != nila better check here? i wonder whether we're actually getting an error e.g. 404 not found wen describing a non-existent instance, it's trickier when e.g. we batch two describe instance IDs where one exists and the other is non-existent, are we getting an error in this case?