Tracking Activity with OpenWhisk Shell

Previously, I introduced the OpenWhisk Shell, a new tool for creating and monitoring your serverless functions. In this article, I will show how to track activations, using the visualizations and commands provided by the Shell. Let’s start with a quick video, then I’ll walk through the flow.

A walkthrough of invocations and the tree command.

First, I quickly create an action and sequences with lightweight commands. These two commands create and then invoke an echo action:

let demo = x => x
invoke -p name openwhisk

Notice how, for simple functions, such as schema aligners and field projection functions, you needn’t create a temporary file to house the file prior to deployment. Once the action has been deployed, you can invoke it, without having to name the action. The Shell will use the current selection, if an entity is required but not provided.

The Nerdy Details: The CLI displays the current context in the prompt. For example, if the prompt reads[/wsk/actions demo], then the current selection is the entity named demo. The first part of the prompt /wsk/actions indicates the current command context. Any ambiguous command executions will resolve to the commands in the closest context. I’ll expand on this topic in future videos.

Asynchronous Invocations with async-await

The invoke command will perform a blocking invocation. The CLI will wait, and you will see a spinner until the activation completes. If you wish to invoke the action asynchronously, use the async command and its matching await. Using this pair will cause the CLI to block (with spinner) until the activation completes.

If you execute await without arguments, the CLI will wait for completion of the last invocation emanating from the Shell, rather than the last invocation in your current namespace. In this way, you can develop and debug actions in parallel with other background activity — for example, an async followed by await will never wait for activations caused by OpenWhisk rules.

To list your action invocations (called activations in OpenWhisk), you can either use the terminology of the wsk CLI, or a more succinct shortcut provided by the Shell. The long form, wsk activation list, works, but personally I find the constant repetition of wsk activation every time I wish to list my activations to be tedious. The Shell provides a synonym for activation: the dollar sign $ can be used in its place; ls is also a synonym for list. Thus $ ls will list your activations.

In the resulting list, as with any list result from the Shell, you can click on the list elements to view the details of that element.

Creating and viewing sequences, and sequence activations, is also easy with the OpenWhisk Shell. To create a sequence, you can use the wsk syntax, if that’s what you are comfortable with. Alternatively, the Shell provides an arrow notation, which I feel makes the sequence creation process easier to read, and generally offers a more lucid way to convey your intent:

let seq = demo -> x=>x
invoke -p name openwhiskers

In the above pair of commands, I first create a two-action sequence. The first element of the sequence is the demo action from earlier. This sequence feeds the output of demo to an echo action. With the let command I can fluidly mix and match actions specified in a variety of ways. In this case, I sequence an existing action with a new one, specified as an inline function.

The Nerdy Details: The let plugin also understands local files; e.g. though not shown in the above video, I could have also written let seq = demo -> ~/echo.js, if the second action were stored on my local filesystem, in a file called echo.js in my home directory.

As with actions, sequences can be invoked with an implicit entity. Thus, I can invoke my newly created sequence with a simple invoke.

When viewing sequence activations, it is often helpful to inspect the tree structure of the invocations. For example, for invocations of my seq example, I would like to know how the overall execution time breaks down: how much time is spent in the first and second actions, and how much time is due to scheduling overheads imposed by the OpenWhisk runtime?

To help with this task, the OpenWhisk Shell includes a tree command. Here, you can see the output of the tree command for the second sequence from the video: let seq2 = seq -> x=>x, i.e. a sequence with a nested sequence.

Finally, let’s return to the CLI side. When using $ ls to list your activations, you may soon discover that the list is messy, especially in the case of sequences; and even more so with nested sequences. Picking out the top-most sequences (e.g. seq2 in my above example) can grow tiring, as the list view will include four low-level activations for every seq2 invocation (count up the nodes in the tree in the above screenshot!).

To help with navigating your activations, the Shell provides an activation roots command. The shorthand for this is $$, which will list only the recent root-most activations. If you want to see only the root-most activations with errors, you can use the shorthand $$!, or use the full command activation roots!.