Skip to content

Commit e8a45a6

Browse files
authored
Merge pull request #2685 from port-labs/PORTN-3437-add-action-run-catalog-guide-clarify-run-payload
Added a note about .run and tracking actions
2 parents 6e6d0c7 + 62426bd commit e8a45a6

File tree

4 files changed

+195
-2
lines changed

4 files changed

+195
-2
lines changed

docs/actions-and-automations/create-self-service-experiences/create-self-service-experiences.md

Lines changed: 186 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,4 +165,189 @@ The basic structure of a self-service action looks like this (see key descriptio
165165

166166
## Examples
167167

168-
For complete examples of self-service actions using GitHub as the backend, check out the [guides section](/guides?tags=GitHub&tags=Actions).
168+
For complete examples of self-service actions using GitHub as the backend, check out the [guides section](/guides?tags=GitHub&tags=Actions).
169+
170+
## Track self-service actions
171+
172+
To gain visibility into how your self-service actions are being used and their performance, you can set up tracking for action runs. This allows you to monitor execution patterns, track success rates, and maintain audit trails to follow what actions were executed and when.
173+
174+
The following tracking system works by creating a dedicated blueprint for action runs and setting up an automation that captures execution details whenever a specific self-service action is triggered as well as an automation that updates the action run's status.
175+
176+
<h3>Set up data model</h3>
177+
178+
Create a blueprint for `Action run`:
179+
180+
1. Go to the [Data model](https://app.getport.io/settings/data-model) page of your portal.
181+
182+
2. Click on `+ Blueprint`.
183+
184+
3. Click on the `{...} Edit JSON` button in the top right corner.
185+
186+
4. Copy and paste the following JSON schema, then click `Save`.
187+
188+
<details>
189+
<summary><b>Action run blueprint (click to expand)</b></summary>
190+
191+
``` json
192+
{
193+
"identifier": "action_run",
194+
"title": "Action run",
195+
"icon": "Microservice",
196+
"schema": {
197+
"properties": {
198+
"status": {
199+
"icon": "DefaultProperty",
200+
"title": "Status",
201+
"type": "string",
202+
"enum": [
203+
"SUCCESS",
204+
"FAILURE",
205+
"IN_PROGRESS",
206+
"WAITING_FOR_APPROVAL",
207+
"DECLINED"
208+
],
209+
"enumColors": {
210+
"SUCCESS": "green",
211+
"FAILURE": "red",
212+
"IN_PROGRESS": "lightGray",
213+
"WAITING_FOR_APPROVAL": "yellow",
214+
"DECLINED": "red"
215+
}
216+
},
217+
"created_at": {
218+
"type": "string",
219+
"title": "Created At",
220+
"format": "date-time"
221+
},
222+
"run_id": {
223+
"type": "string",
224+
"title": "Run ID"
225+
},
226+
"run_url": {
227+
"type": "string",
228+
"title": "Run URL",
229+
"format": "url"
230+
},
231+
"updated_at": {
232+
"type": "string",
233+
"title": "Updated At",
234+
"format": "date-time"
235+
},
236+
"action": {
237+
"type": "string",
238+
"title": "Action"
239+
}
240+
},
241+
"required": []
242+
},
243+
"mirrorProperties": {},
244+
"calculationProperties": {},
245+
"aggregationProperties": {},
246+
"relations": {}
247+
}
248+
```
249+
</details>
250+
251+
252+
<h3>Define the automation</h3>
253+
254+
The following automation updates the `Action run` entity with information regarding this run.
255+
To add it, follow these steps:
256+
257+
1. Go to the [Automations](https://app.getport.io/settings/automations) page of your portal.
258+
259+
2. Click on the `+ Automation` button.
260+
261+
3. Click on the `{...} Edit JSON` button in the top right corner.
262+
263+
4. Copy and paste the following JSON configuration into the editor, then click `Save`.
264+
265+
<details>
266+
<summary><b>Update `Action run` automation definition (click to expand)</b></summary>
267+
268+
``` json
269+
{
270+
"identifier": "update_action_run",
271+
"title": "Update Action Run",
272+
"description": "",
273+
"trigger": {
274+
"type": "automation",
275+
"event": {
276+
"type": "ANY_RUN_CHANGE",
277+
"actionIdentifier": "<THE_ACTION_IDENTIFIER>"
278+
},
279+
"condition": {
280+
"type": "JQ",
281+
"expressions": [],
282+
"combinator": "and"
283+
}
284+
},
285+
"invocationMethod": {
286+
"type": "UPSERT_ENTITY",
287+
"blueprintIdentifier": "action_run",
288+
"mapping": {
289+
"identifier": "{{.event.diff.after.id}}",
290+
"title": "{{.event.diff.after.id}}",
291+
"properties": {
292+
"run_id": "{{.event.diff.after.id}}",
293+
"run_url": "https://app.port.io/organization/run?runId={{.event.diff.after.id}}",
294+
"status": "{{.event.diff.after.status}}",
295+
"created_at": "{{.event.diff.after.createdAt}}",
296+
"updated_at": "{{.event.diff.after.updatedAt}}",
297+
"action": "{{.event.diff.after.action.title}}"
298+
},
299+
"relations": {}
300+
}
301+
},
302+
"publish": true
303+
}
304+
```
305+
</details>
306+
307+
Once implemented, you can track your self-service action runs and see how they are progressing.
308+
309+
For example, you can create the following widget to vizualize how `Action runs` are distributed by status for a specific `Action` over the past month:
310+
311+
1. Click **`+ Widget`** and select **Pie chart**.
312+
313+
2. Give the widget a `title` and a `description`.
314+
315+
3. Choose the `Action run` blueprint.
316+
317+
4. Under `Breakdown by property`, select the **status** property.
318+
319+
5. Under `Additional filters` you can choose to filter by:
320+
- `Action runs` that were created in the past month.
321+
- `Action runs` of a specific self-service action.
322+
323+
Click on `filters`, then on `{...} Edit JSON`, and add the following snippet with your action title and relevant time frame.
324+
Below is a JSON example for `Create s3 bucket` self-service action in the past month:
325+
326+
<details>
327+
<summary><b>filters JSON example (click to expand)</b></summary>
328+
``` json showLineNumbers
329+
{
330+
"combinator": "and",
331+
"rules": [
332+
{
333+
"property": "created_at",
334+
"operator": "between",
335+
"value": {
336+
"preset": "lastMonth"
337+
}
338+
},
339+
{
340+
"property": "action",
341+
"operator": "=",
342+
"value": "Create s3 bucket" // Change the value to your action name
343+
}
344+
]
345+
}
346+
```
347+
</details>
348+
349+
6. Click `Save`.
350+
351+
This will result in a widget similar to the following:
352+
353+
<img src='/img/self-service-actions/actionRunsPieChartExample.png' width='70%' border='1px' />

docs/actions-and-automations/create-self-service-experiences/setup-the-backend/setup-the-backend.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ For example, say we have an action with one user input that is the user's name.
5757
}
5858
```
5959

60+
:::info `.run` available values
61+
When the action is triggered, the `.run` object includes only the run `id`.
62+
:::
63+
6064
You may have noticed that the example above also sends `{{ .run.id }}`. This is a unique identifier for each execution of the action, and can be used to interact with the action run in Port from your backend.
6165

6266
Now you might be thinking - *how do I know what data is available to me when constructing the payload?*

docs/actions-and-automations/define-automations/setup-action.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,11 @@ Here is an example for an automation payload:
4646
}
4747
```
4848

49-
You may have noticed that the example above also sends `{{ .run.id }}`. This is a unique identifier for each execution of the automation, and can be used to interact with the autmation run in Port from your backend.
49+
:::info `.run` available values
50+
When the automation is triggered, the `.run` object includes only the run `id`.
51+
:::
52+
53+
You may have noticed that the example above also sends `{{ .run.id }}`. This is a unique identifier for each execution of the automation, and can be used to interact with the automation run in Port from your backend.
5054

5155
Now you might be thinking - *how do I know what data is available to me when constructing the payload?*
5256
Enter `trigger data`.
76.6 KB
Loading

0 commit comments

Comments
 (0)