-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
Agent actions token support #23452
Agent actions token support #23452
Conversation
Pinging @elastic/ingest-management (Team:Ingest Management) |
💚 Build Succeeded
Expand to view the summary
Build stats
Test stats 🧪
💚 Flaky test reportTests succeeded. Expand to view the summary
Test stats 🧪
|
Pinging @elastic/agent (Team:Agent) |
@@ -43,11 +44,16 @@ func AgentConfigFile() string { | |||
return filepath.Join(paths.Config(), defaultAgentConfigFile) | |||
} | |||
|
|||
// AgentActionStoreFile is the file that will contains the action that can be replayed after restart. | |||
// AgentActionStoreFile is the file that contains the action that can be replayed after restart. |
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.
Being that we already have an action_store.yml
why not place the action token inside of this file? Why the need to seperate it into its own file?
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 change. was not sure what's the right/established pattern.
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 there any case where the action_store.yml
could get completely overwritten, thus loosing the marker?
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.
i think that would be the correct place
It should only be overwritten on a re-enroll, which is what should happen in the token case. The code paths already handle that, so its the best place for it.
} | ||
|
||
type ackTokenSerializer struct { | ||
AckToken string `yaml:"ack_token"` |
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.
Maybe worth to make the mutex directly part of this struct? Then you could use atsCached.Lock()
which would make the code likely more readable.
@@ -22,6 +22,7 @@ const checkingPath = "/api/fleet/agents/%s/checkin" | |||
// CheckinRequest consists of multiple events reported to fleet ui. | |||
type CheckinRequest struct { | |||
Status string `json:"status"` | |||
AckToken string `json:"ack_token"` |
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.
Should we omit if empty? otherwise we probably need to add the property to Kibana
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.
Sure. Will update.
Discussed with @blakerouse, going to consolidate the |
4321259
to
b857a49
Compare
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.
Looks really good, well tested! Please backport this to 7.x.
* Agent actions token support * Make check happy * Consolidate action store and the ack token store into state.yml store * Make state storage thread safe
What does this PR do?
Implements the actions token exchange.
This includes the stub for the agent actions that just logs the action received (DEBUG log level).
The actions will need need to be wired in further to properly pass them to the apps/beats and receive the result back. @blakerouse let me know if you are going to handle that or if I should dig further.
The flow of the action token exchange is the following.
Screenshot of the app/beat action logged from the stub:
@blakerouse let me know if there is a better place for that, since I'm just getting familiar with the agent code.
action_seq_no
This way the fleet server tracks the latest action received by the agent.
If the ack_token is not present in the check in payload the value that is stored with the agent record is used.
Why is it important?
This is needed to support the new Fleet Server agent actions handling on the agent side. Without this change the new action document in the .fleet-actions will cause the agent to go into a loop of check-ins and receiving the same action over and over, since there will be no indication that the agent action was received.
@blakerouse One question about the persisted ack_token on the agent side. We probably should remove the file every time the agent enrolls, since it creates the new agent record for the fleet. Thoughts?