-
Notifications
You must be signed in to change notification settings - Fork 618
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
Adding EBS watcher implementation #3866
Conversation
5266fda
to
2e9d9cd
Compare
agent/ebs/watcher.go
Outdated
wg.Add(1) | ||
w.mailbox <- func() { | ||
defer wg.Done() | ||
empty := len(w.agentState.GetAllPendingEBSAttachments()) == 0 |
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.
can we rename empty
to something more specific?
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.
Good call out, I renamed it to wasEmpty
as well as added some comments to better explain the use case. Thanks!
agent/vendor/github.com/aws/amazon-ecs-agent/ecs-agent/api/resource/ebs_discovery.go
Outdated
Show resolved
Hide resolved
b80b2c6
to
bab80b4
Compare
* Added the implementation for EBS volume discovery on Windows * incorporated the review comments. Also fixed the name of the timeout variable. * incorporated the review comments. Also fixed the name of the timeout variable.
agent/vendor/github.com/aws/amazon-ecs-agent/ecs-agent/api/resource/ebs_discovery.go
Show resolved
Hide resolved
agent/vendor/github.com/aws/amazon-ecs-agent/ecs-agent/api/resource/ebs_discovery.go
Outdated
Show resolved
Hide resolved
|
||
// TestHandleExpiredEBSAttachment tests acknowledging an expired resource attachment of type Elastic Block Stores | ||
// The resource attachment object should not be saved to the agent state since the expiration date is in the past. | ||
func TestHandleExpiredEBSAttachment(t *testing.T) { |
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.
Nice to see you catch this in your tests!
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.
Thanks for making this change! One question: since Xen and Nitro are both amazon internal instance types, is this feature specifically for ec2 ecosystem, how are we planning to prevent ecsanywhere instances running this as it is embedded into agent state?
508c67d
to
d88e6cb
Compare
) | ||
|
||
const ( | ||
ebsVolumeDiscoveryTimeout = 5 * time.Second |
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.
Where did this timeout come from? Based on our data, 5 seconds is not enough to always give EBS time to handle the attachment.
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.
Updated!
|
||
// parseLsblkOutput will parse the `lsblk` output and search for a EBS volume with a specific device name. | ||
// Once found we return the volume ID, otherwise we return an empty string along with an error | ||
// The output of the "lsblk -o NAME,SERIAL -J" command looks like the following: |
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.
thank you overall for the thorough code comments!!
Summary
This PR will introduce the implementation for the EBS watcher which is responsible for detecting and validating that an EBS volume is attached onto the host.
Implementation details
The general workflow is upon agent start up, the EBS watcher gets initialized and will start to periodically check whether we have any pending EBS attachments to find on the host. If there is then it'll scan for all pending EBS volumes within the agent state and try to find if they're attached via
lsblk
. Otherwise it's a noop. The watcher will always be running and will stop whenever agent stops.EBS volumes are added to the agent state whenever we receive and handle an attachment message.
watcher.go
intoagent/ebs
NewWatcher
: Create a new instance of a EBSWatcher structStart
: Start the periodic scanning process of the EBSWatcher for all pending EBS attachments saved to the agent stateStop
: Stop the EBSWatcherHandleResourceAttachment
: Handle a new ResourceAttachment object from the Attachment Message Responder/Handler and save it into the agent state if it does not exists.notifyFoundEBS
: Mark the pending ResourceAttachment as no longer pending as well as stops the ACK timerRemoveAttachment
: Removes a ResourceAttachment object from the list of attachments within the agent statescanEBSVolumes
: Iterates through the list of pending ResourceAttachment objects within the agent state and checks if it's attached within the host viaConfirmEBSVolumeIsAttached
addEBSAttachmentToState
: Starts the ACK timer of a ResourceAttachment object as well as add it to the list of attachments within the agent statehandleEBSAckTimer
: Handles the when a ResourceAttachment object once its ACK timer expiresecs-agent/api/resource/resource_attachment.go
to safely read ResourceAttachment objects within logsEBSDiscovery
inecs-agent/api/resource/interfaces.go
EBSDiscoveryClient
inecs-agent/api/resource/ebs_discovery.go
which implements theEBSDiscovery
interfaceebs_discovery_linux.go
ConfirmEBSVolumeIsAttached
: Calls uponlsblk -o NAME,SERIAL -J
to obtain all attached volumes on the host and validates whether the given device name and volume ID is within the output.parseLsblkOutput
: Parses the output oflsblk
and then returns the volume ID of a specific device name from the outputebs_discovery_windows.go
ConfirmEBSVolumeIsAttached
: The windows version to find and validate whether a EBS volume is attached on the hostecs-agent/api/resource/generate_mocks.go
: Generate new mocks for theEBSDiscovery
interface for testingNote: There will be a follow up PR for the ACS Attachment message handler/responder that'll also include additional changes to the EBS watcher.
This PR will also include changes made in the following PR mye956#49.
Testing
New tests cover the changes: yes
Unit tests
Description for the changelog
Adding implementation for EBS watcher and EBS volume discovery.
Licensing
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.