StackStorm / st2

StackStorm (aka "IFTTT for Ops") is event-driven automation for auto-remediation, incident responses, troubleshooting, deployments, and more for DevOps and SREs. Includes rules engine, workflow, 160 integration packs with 6000+ actions (see https://exchange.stackstorm.org) and ChatOps. Installer at https://docs.stackstorm.com/install/index.html
https://stackstorm.com/
Apache License 2.0
6.05k stars 745 forks source link

Attach custom Task Metadata in Orchesta workflows #4498

Open trstruth opened 5 years ago

trstruth commented 5 years ago
SUMMARY

I want to be able to attach some metadata to tasks in an orquesta workflow.

something like

  start:
    action: core.echo message="automation started"
    metadata: # some object/string here
    next:
      - when: <% succeeded() %>
        do: task2

Today, action definitions have the ability to define some metadata but it'd be nice to be able to do this at the task level, and access the metadata via the executions api endpoint. Does this sound reasonable for PR/ any alternatives you can think of?

ISSUE TYPE
LindsayHill commented 5 years ago

Might be helpful if you could flesh out an example - e.g. show the sorts of metadata you'd like to attach, and how you would use it.

Will help implementers to understand the problem you're trying to solve, so they have something to match potential designs against

trstruth commented 5 years ago

Good point. The stackstorm docs describe action tags as

An array with tags for this actions for the purpose of providing supplemental information

Similarly, I want to do something similar at the task level.

For example: Consider an action that handles device interaction. The action takes a command parameter, examples of such commands might be show version or update config. Show version is a simple read command, but update config requires the device to be temporarily unavailable while it updates. We can see that the severity or sensitivity of one command is higher than the other. However since the command is task specific as opposed to action specific, it doesn't make sense to use the action metadata to denote this information. This is the motivation for the task metadata.

How I might use it:

First, if there were a metadata key allowed in a task definition, in a workflow snippet I could write

version_task:
  action: mypack.device_interaction cmd="show version"
  metadata:
    severity: "low"
    output_format: "string"
  next:
    - when: <% succeeded() %>
      do: another_task

as well as

config_update_task:
  action: mypack.device_interaction cmd="update config"
  metadata:
    severity: "medium"
    output_format: "table"
  next:
    - when: <% succeeded() %>
      do: another_task

In this example I've also included a output_format metadata item, which describes how I want the output to be rendered by some service that consumes the output of this execution.

Now, if I get the execution data from api/v1/executions/<execution_id> it'd be nice to see

    "liveaction": {
        "metadata":{
          "severity": "medium"
          "output_format": "table"
        }
        "runner_info": {
            "hostname": "a576301ad35d",
            "pid": 105
        },
        "parameters": {
            "message": "Automation completed."
        },
        "action_is_workflow": false,
        "callback": {},
        "action": "mypack.device_interaction",
        "id": <execution_id>
    },

which I could then go on to use in some of the ways I described above.