pt-stalk feature: execute external script on event

Bug #1001004 reported by Gavin Towey
14
This bug affects 3 people
Affects Status Importance Assigned to Milestone
Percona Toolkit moved to https://jira.percona.com/projects/PT
Invalid
High
Daniel Nichter

Bug Description

I'm including a patch for a new feature in pt-stalk.

--exec-after-collect

execute a command when a collection is triggered. This lets you do things like invoke pt-kill to handle a query pileup, as well as use stalk to gather info.

--exec-after-sleep

execute a command after collection has been triggered, and the script has sleet for --sleep seconds. This is used in my case to execute a script that creates a tar.gz file from the data, then sends it to a remote server.

Revision history for this message
Gavin Towey (gtowey) wrote :
Revision history for this message
Baron Schwartz (baron-xaprb) wrote :

This looks useful. But I think we might want to do these slightly differently. Rather than providing a command to the tool's option, we could require the user to specify a file to be sourced, which must provide a specific function, similar to the way we source and call a trigger function. The function that's called should be executed in the background with & so that it does not hang the script entirely if the call is long-lived.

Revision history for this message
Daniel Nichter (daniel-nichter) wrote :

Perhaps an option called --plugin which takes a script that can define various hooks like:

after_collect() {
   <my code>
}

after_sleep() {
   <my code>
}

This would allow us to implement as many hooks in as many places as we want with the same option.

The tool would then be like:

after_collect() {
   # Default stub, does nothing
   :
}
...etc...

. "$OPT_PLUGIN"

after_collect ... # call plugin's if defined, else default stub

Revision history for this message
Baron Schwartz (baron-xaprb) wrote :

I think that sounds like a good idea. It will let us add generic plugin hooks for anything we want without increasing the complexity of the tool significantly. We'll just need to document the available hooks.

I rescind my comment about calling things with & to put them in the background. The plugin author can control that; if they do something wrong, then they can cause the tool to hang while the plugin works, but that's OK. If we background the plugin's functions, then we can get out-of-order execution and hard problems like "what if I want this to run only after that other thing is finished," which will be much harder for plugin authors to solve than the potential mistake of not backgrounding a blocking action.

Changed in percona-toolkit:
status: New → Triaged
tags: added: pt-stalk
removed: request
tags: added: percona-23615
Revision history for this message
Baron Schwartz (baron-xaprb) wrote :

I'd find this feature very useful, because I want to set up Rain Gauge from https://github.com/box/RainGauge but I don't want to patch pt-stalk.

Revision history for this message
Daniel Nichter (daniel-nichter) wrote :

Tentatively targeted to 2.1.5.

Changed in percona-toolkit:
milestone: none → 2.1.5
Changed in percona-toolkit:
importance: Undecided → High
assignee: nobody → Daniel Nichter (daniel-nichter)
Revision history for this message
Daniel Nichter (daniel-nichter) wrote :
Changed in percona-toolkit:
status: Triaged → In Progress
status: In Progress → Invalid
milestone: 2.1.5 → none
tags: added: plugin
removed: feature
Revision history for this message
Shahriyar Rzayev (rzayev-sehriyar) wrote :

Percona now uses JIRA for bug reports so this bug report is migrated to: https://jira.percona.com/browse/PT-313

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.