How to rollback a service with a Cortex Workflow
Step 1: Start creating the Workflow
Follow the steps in the documentation to create a Workflow and configure its basic settings. This Workflow is scoped to the “service” entity type.Step 2: Add blocks to the Workflow
The instructions on this page describe how to create this Workflow in the Cortex UI, but it is also possible to copy the Workflow YAML and add it to your workspace via the Cortex CLI. This allows you to quickly set up the example configuration then iterate on it for your own use case. Expand the tile below to learn more.Workflow YAML instructions
Workflow YAML instructions
To upload the Workflow example YAML into your workspace:
- Save the Workflow example YAML file below:
- Use the Cortex CLI to run this command, using the path to your Workflow YAML file:
cortex workflows create -f <path-to-your-workflow.yaml>
User input
User input
In this example, we add a User Input block to obtain information about an incident.
- Click + in the center of the page. In the block library modal, choose User input.
- In the block configuration side panel, enter a name and unique slug for this block.
- In this example, we use the name
Get Incident infoand the slugget-incident-info.
- In this example, we use the name
- Click +Add user input. Add the following:
- Name: Incident Name
- Key: incident-name
- Type: Text
- Click Add input.
- Click +Add user input. Add the following:
- Name: Incident Severity
- Key: incident-severity
- Type: Select
- Options: Click +Add option to add options for the severity labels. In our example, we use
SEV0,SEV1, andSEV2. - Click Add input.
- Click +Add user input. Add the following:
- Name: Create incident Slack channel?
- Key: create-incident-slack-channel
- Type: Toggle
- Default value: False
- Click Add input.
- At the bottom of the side panel, click Save.
List deployments for entity
List deployments for entity
This block lists the deployments for an entity.
- Click + in the center of the page. In the block library modal, select the Cortex > List deployments for entity block.
- In the side panel, enter a name and unique slug for the block.
- In this example, we use the name
List deployments for entityand the sluglist-deployments-for-entity.
- In this example, we use the name
- Configure the block:
- Page size: In our example, we configured
2.
- Page size: In our example, we configured
- At the bottom of the side panel, click Save.
JavaScript
JavaScript
This block uses JavaScript to format the deployments.
- Click + in the center of the page. In the block library modal, select the JavaScript block.
- In the side panel, enter a name and unique slug for the block.
- In this example, we use the name
Format Deploymentsand the slugjavascript.
- In this example, we use the name
- In the JavaScript text editor box, enter an expression. Our example uses the following:
- Save the block.
User input
User input
This block asks the user for the commit ID to roll back to, pulling the commit IDs from the previous step.
- Click + in the center of the page. In the block library modal, select the User input block.
- In the side panel, enter a name and unique slug for the block.
- In this example we use the name
User inputand the sluguser-input.
- In this example we use the name
- Click +Add user input. Add the following:
- Name: Commit ID to rollback to
- Key: commit-id-to-rollback-to
- Type: Select
- Data source: Manual
- Click Add input.
- Path to override value: Enter
actions.javascript.outputs.result.shasFormatted.
- Save the block.
JavaScript
JavaScript
This block uses JavaScript to extract the SHA that was selected in the previous step.
- Click + in the center of the page. In the block library modal, select the JavaScript block.
- In the side panel, enter a name and unique slug for the block.
- In this example, we use the name
Extract SHAand the slugextract-sha.
- In this example, we use the name
- In the JavaScript text editor box, enter an expression. Our example uses the following:
- Save the block.
Trigger GitHub workflow
Trigger GitHub workflow
This block triggers a GitHub workflow to roll back the deployment.
- Click + in the center of the page. In the block library modal, select the GitHub > Trigger workflow block.
- In the side panel, enter a name and unique slug for the block. In this example, we use the name
Trigger workflowand the slugtrigger-workflow. - Configure the block:
- Repository: Enter your repository name.
- Ref: Enter the Git reference to trigger the workflow on, e.g.
main. - Workflow ID or file name: Enter the ID of the GitHub workflow or the file name of the workflow file.
- In our example, we added
rollback.yaml.
- In our example, we added
- Inputs: Optionally enter key-value pairs to pass to the workflow.
-
In our example, we added:
-
In our example, we added:
- At the bottom of the side panel, click Save.
response output includes workflow_run_id, run_url, and html_url for the triggered GitHub Actions run. You can reference these in later blocks, for example to poll the run’s status or include a link to the run in a Slack message.Branch
Branch
During the first User input step, the user can choose whether or not to create a Slack channel for the incident. Their choice determines which path will be followed during the Branch block.If they chose to create an incident Slack channel:
- Click + in the center of the page. In the block library modal, choose Branch.
- In the block configuration side panel, enter a name and unique slug for this block.
- In this example, we use the name
Branchand the slugbranch.
- In this example, we use the name
- Click +Add path. Configure the conditional path:
- Name: Create incident Slack channel
- Slug: create-incident-slack-channel-path
- Path expression:
actions["get-incident-info"].outputs["create-incident-slack-channel"] == true - Save the path.
- Click +Add path. Configure the conditional path:
- Name: Do not create Slack channel
- Slug: do-not-create-slack-channel
- Path expression:
actions["get-incident-info"].outputs["create-incident-slack-channel"] == false - Save the path.
- Save the block.
Add blocks to the “Create incident Slack channel” path
HTTP requests- Click + under the new path. In the block library modal, choose HTTP request.
- In the block configuration side panel, enter a name and unique slug for this block.
- In this example, we use the name
Create incident Slack channeland the slugcreate-incident-slack-channel.
- In this example, we use the name
- Configure the block:
- HTTP method: POST
- URL:
https://slack.com/api/conversations.create - Headers:
Content-Type: application/jsonAuthorization: Bearer {{context.secrets.apiKey}}
- Payload: In our example, we enter the following:
- Save the block.
- Click + under the path. In the block library modal, choose HTTP request.
- In the block configuration side panel, enter a name and unique slug for this block. In this example, we use the name
Send Slack messageand the slugsend-slack-message. - Configure the block:
- HTTP method: POST
- URL:
https://slack.com/api/conversations.create - Headers:
Content-Type: application/jsonAuthorization: Bearer {{context.secrets.apiKey}}
- Payload: In our example, we enter the following:
- Save the block.
- Click + under the new path. In the block library modal, choose Slack > Send message.
- In the block configuration side panel, enter a name and unique slug for this block.
- In this example, we use the name
Send FYI messageand the slugsend-fyi-message.
- In this example, we use the name
- Configure the block:
- Slack channel name: Select the channel where you want to send a message informing the team that you did not create a separate Slack channel for the incident.
- Message text: In our example, we set this to:
Service {{context.entity.tag}} with incident does not have a separate Slack channel.
- Save the block.
Step 3: Run the Workflow
- At the top of the page, click Run Workflow.
- The Workflow pauses to collect a response from the user during the User Input block. The user enters a name and severity for the incident, and chooses whether to create a Slack channel
- Some incidents require additional team work and collaboration, while others can be easily mitigated and may not require a dedicated channel.
- The “List deployments for entity” block runs, fetching a list of deployments associated with the entity.
- The JavaScript block runs, which formats the deployment data.
- The next User Input block runs, which uses the formatted data from the previous block to provide a commit ID to rollback to.
- The second JavaScript block runs, which extracts the SHA from the output of the previous block.
- The GitHub workflow is triggered to roll back the affected service.
- The Branch block runs:
- If the user selected to create a Slack channel: An HTTP request runs to create an incident Slack channel, and an HTTP block runs to send a Slack message into the channel including the incident name, the service being rolled back, and the commit ID.
- If the user selected to not create a Slack channel: The “Do not create Slack channel” path runs. A Slack block runs, which sends a Slack message to an existing team channel to let them know a separate incident channel was not created.