In the rapidly evolving landscape of software development, teams often prioritize rapid feature deployment through CI/CD pipelines and automated workflows. However, it’s not just about pushing code faster. It’s about maintaining system reliability and catching issues before they impact users.
When mission-critical tests fail or show degraded performance, teams must know about it immediately. That’s where the need for effective alerting and response systems arise, which help maintain high availability and operational awareness. PagerDuty is one such solution for incident management, providing teams with the tools to address and resolve issues quickly.
This tutorial explores how integrating PagerDuty with Testkube can enhance your team's response to critical test failures, ensuring your development cycle remains fast and reliable.
Throughout the evolution of technology, numerous methods have enabled systems to communicate seamlessly. From various protocols to services, the goal has always been to facilitate data transfer across disparate systems efficiently.
Webhooks stand out as a powerful mechanism for system interaction. They serve as digital informants, alerting services to specific events. Essentially, a webhook endpoint acts as a listener for one system, ready to receive data transmitted by another.
In the context of Testkube, Webhooks are instrumental. They empower you to effortlessly inform other services about test-related activities. For example, setting up a Slack webhook with Testkube allows for the automatic dissemination of event notifications, bridging the gap between test execution and team communication.
For additional information on webhook components, please see our Webhook documentation.
By utilizing webhooks within Testkube, you can significantly enhance test observability and automation, making your testing processes more efficient and integrated.
PagerDuty is an incident response management and alerting platform for DevOps teams managing critical operations. It provides real-time alerts and escalates incidents to the appropriate personnel. By automating the incident response workflow, PagerDuty ensures that incidents are addressed promptly and efficiently, reducing downtime and improving overall system reliability.
Being the extensive tool that it is, there are a few components that we must be aware of for the purpose of this tutorial:
Apart from these, PagerDuty has advanced mechanisms that allow teams to send emails, calls, SMS, and push notifications to notify designated personnel about the incident. You can read more about PagerDuty and its features here.
The first and foremost step is to create a service in PagerDuty. Creating a service in PagerDuty is fairly simple, and you can create one in a few minutes.
Once you've created your service, the next step is to create an integration. This integration essentially enables PagerDuty to receive alerts from other services or tools, such as Testkube.
By default, PagerDuty provides support from multiple tools. However, in the case of Testkube, we’ll use their Events API V2 integration, which will allow us to send custom events.
After selecting this, you will be given the configurations to create the webhook in Testkube. It will share details like the integration key and integration URL for change and alert events, along with an example of using the API.
Note that the PagerDuty events API expects JSON input in a specific format when processing alerts. With this, we have configured PagerDuty to receive alerts from Teskube. Now, let's set up a Webhook in Testkube.
Creating a webhook trigger in Testkube is straightforward. You can create Webhooks using the dashboard as well as the CLI. We’ll be using the dashboard to show you how it works.
We’ll set up a webhook for PagerDuty using the dashboard. This webhook will trigger on the test-end-failure event and send the data to the PagerDuty webhook endpoint that we got in the previous step (Integration URL).
To create a Webhook, follow these steps:
Though the webhook is ready, we want to pass on additional details about the test workflow execution to the webhook. We can do that by providing a custom payload.
As mentioned earlier, PagerDuty requires input in a particular format, as shown below:
curl --request 'POST' \
--url 'https://events.pagerduty.com/v2/enqueue' \
--header 'Content-Type: application/json' \
--data '{
"payload": {
"summary": "Test alert",
"severity": "critical",
"source": "Alert source",
“custom_details” {“key”:”value”}
},
"routing_key": "routingkey",
"event_action": "trigger"
}'
Hence, we will add a custom payload. To do that, click your Webhook and navigate to the “Action” section. Here, add the following snippet under the “Custom Payload” section:
{
"payload": {
"summary": "{{ .TestWorkflowExecution.Result.Status }} - {{ .TestWorkflowExecution.Workflow.Name }}" ,
"severity": "critical",
"source": "Testkube",
"custom_details" : {
"testName": "{{ .TestWorkflowExecution.Name }}",
"testStatus": "{{ .TestWorkflowExecution.Result.Status }}",
"testEndtime": "{{ .TestWorkflowExecution.StatusAt }}",
"url": "https://app.testkube.io/organization/{{ index .Envs "TESTKUBE_PRO_ORG_ID" }}/environment/{{ index .Envs "TESTKUBE_PRO_ENV_ID" }}/dashboard/test-workflows/{{ .TestWorkflowExecution.Workflow.Name }}/executions/{{ .TestWorkflowExecution.Id }}"
}
},
"routing_key": "<replace with your routing key>",
"event_action": "trigger"
}
The payload above contains the following details:
Note: Update your routing key from PagerDuty.
Click on “Save” to save the configuration.
Now that we have configured the webhook for PagerDuty, it’s time to test it. To do that, simply run the cURL test workflow.
When the test fails, you’ll see the webhook trigger and send data to PagerDuty. Within PagerDuty, this will be shown as an incident based on the details we shared in the custom_payload.
You can expand the incident for more details and to view the custom payload that we’re sending.
By default, PagerDuty also sets up an email alert triggered when an incident is created.
And that’s how you can configure the Testkube webhook to send alerts to PagerDuty. Based on your team’s specific needs, you can configure both Webhook and Testkube.
If you noticed in the above demo that the webhook is triggered every time the test workflow fails. For a test workflow that runs frequently and fails because of a bug, you don’t want to be swarmed with notifications and become alert fatigued.
Testkube solves this with its state-based alerting through 'becomes' events.
Rather than triggering alerts on every failure, notifications are sent only when a test's status changes—for instance, when a consistently passing test fails for the first time. This intelligent alerting ensures teams stay informed of meaningful changes without being bombarded by redundant notifications for known issues.
To do that, choose from any of the following trigger-events when creating your webhook:
Refer to the complete list of webhook state changes.
Harnessing the synergy between Testkube and PagerDuty through webhooks offers a formidable solution to bolster your incident management strategy. This integration not only simplifies tracking and addressing critical test failures but also fosters improved teamwork.
By utilizing Testkube's automated testing capabilities alongside PagerDuty's robust incident management system, you equip your team with the necessary resources to uphold service excellence and enhance customer satisfaction. The combination of these tools facilitates a shared understanding, streamlined communication, and faster detection among development, QA, and operations teams, all of which are essential for the maintenance of high availability and reliability.
Discover the potential of Testkube and its versatile integrations. Embrace a system where proactive monitoring and seamless alerting transform your operational dynamics.
Connect with our vibrant community on Slack for insights, support, and networking with like-minded developers. Embark on a journey to redefine your approach to quality assurance and incident response, achieving resilience and agility in today’s fast-paced agile environment.
Testkube is a test execution and orchestration framework for Kubernetes that works with any CI/CD system and testing tool you need, empowering teams to deliver on the promise of agile, efficient, and comprehensive testing programs by leveraging all the capabilities of K8s to eliminate CI/CD bottlenecks, perfecting your testing workflow. Get started with Testkube's free trial today!
Related topics: