Responsive

Empowering Kubernetes Tests with Webhooks

Sep 29, 2023
7 min
read
Bruno Lopes
Product Leader
Testkube
Learn how to take test automation for your apps in Kubernetes to the next level with webhooks. In this tutorial, we'll show you how to set them up for Slack and Grafana Dashboard.
Share on Twitter
Share on LinkedIn
Share on Reddit
Share on HackerNews
Copy URL

Table of Contents

Want to learn more about this topic? Check out our Office Hours sessions!

Get Started with Testkube Pro

Webhooks Intro

The significance of webhooks cannot be overstated. They help bridge the gap between different tools & platforms to enable swift and streamlined communication. Webhooks empower developers and operations teams to seamlessly integrate testing, deployment, and incident response workflows.

Webhooks are automated HTTP callbacks sent from one application to another at specific events or when specific changes occur, enabling real-time information exchange and triggering actions in response to those events. Webhooks play a vital role in automation testing as well as they allow for seamless communication between testing tools, CI framework, and Kubernetes.

In today’s post, we’ll look at Webhooks in Testkube and how they further enhance your testing capability by helping you integrate with other critical systems.

Webhooks in Testkube

Testkube uses webhooks to integrate with external systems, allowing you to effortlessly synchronize your testing workflows with other tools and platforms. These webhooks are designed to carry critical information regarding your tests as HTTP POST payloads. The information can include the execution and real-time status depending on how you configure it

To leverage webhooks, you need to ensure that the platform that you want to send information to has an HTTPS endpoint to receive the events. Testkube also allows you to customize the payloads. 

You can create a webhook from the dashboard, use the CLI, or create it as a custom resource. Before we show how it’s done, let’s understand a few scenarios where Webhooks in Testkube shine:

  • Incident Management & Response: Webhooks can be used to create incidents and alert on-call teams when a critical test fails. This ensures a timely response and avoids any potential disruption due to failures and bugs. With Testkube, you can configure incident management tools like PagerDuty and OpsGenie to receive alerts based on critical events for your tests.
  • Communication and Collaboration: You can configure Webhooks in Testkube to send alerts to your teams in your communication tool. This will notify your team of any critical event that needs attention and attend to it before the issue escalates. Some of the popular communications tools like Slack and MS Teams can be configured to receive alerts from Testkube.
  • Monitoring and Observability: Webhooks can also be used to send alerts and notifications to your monitoring and observability tools like Prometheus and Grafana. This provides visibility into your tests, alerts you, and ensures that timely corrective actions can be taken.

Components of Webhooks

To successfully create and configure a webhook in Testkube, you need to understand how it works and the various components associated with it. These components, comprising events, resources, and destinations collectively form the backbone of webhook functionality. 

  • Events: These are test events that can trigger webhooks. These cover important events in the testing process such as execution, completion, success, and failure. 
  • Resources: These are the objects that trigger an event. With these, Testkube provides you the flexibility to define event triggers aligned with your resource-specific requirements.
  • Destination: These specify where the event data is to be delivered. Testkube allows you to configure webhook endpoints for an array of platforms.

Refer to our Webhook documentation to learn more about the components of webhooks.

Using Webhooks in Testkube

As discussed above, Webhooks are a great way to extend your testing to other platforms. We will now explain how to use webhooks in Testkube. 

To begin, we’ll design a simple cURL test that sends a request to an HTTP endpoint that returns the IP address of our host. We’ll configure webhooks that trigger on success and failure events of tests. We’ll showcase two scenarios: 

  • Incident Management and Response: By configuring test failure events to be sent to a Grafana endpoint.
  • Communication and collaboration: By configuring test successful events to be sent to Slack.

We also have a video for you to follow the steps to create a webhook in Testkube. You can either read through the blog post or watch the video.

Pre-requisites

Below are the prerequisites required to perform/replicate the steps mentioned in the blog post. Feel free to skim through without configuring these if you plan to just read and understand the blog post. 

Create cURL Test

Create a cURL test that sends a request to http://ip.jsontest.com which returns the IP address of the host that was used to send the request. Below is the code snippet:

```js

{
"command": [
  "curl",
   "http://ip.jsontest.com/",
   "-H",
   "'Accept: application/json'"
],
"expected_status": "200",
"expected_body": "{\"ip\": \"120.88.40.166\"}"
  }

```

Configure Destination

We’ll be creating two webhooks, one that sends a notification to a Slack channel when a test passes, the other one sends an update to Grafana’s incident dashboard when the test fails. In this section, we’ll see how to configure Grafana and Slack to receive notifications. 

Setting Up Grafana Integration

We’ll be using Grafana cloud for this blog post; you can also use a self-hosted Grafana instance. The steps would mostly be the same. Create a Grafana Cloud account if you don’t already have one. The free account is all you’ll need for this blog post. 

Once logged in, navigate to Alerts & IRM -> Incidents -> Integrations. Grafana will provide you with a multitude of integration options, choose Incoming Webhooks. Click on the Install Integration button and Grafrana will set the endpoint and provide you with the details. 

Note down the URL for the endpoint. You’ll need this while configuring the webhook in Testkube. 

Setting Up Slack Integration

Testkube provides a Slack integration where you can configure a Testkube bot in your Slack workspace. If your Slack workspace doesn’t allow you to install a bot, you can follow the steps mentioned in this section. 

You can configure Slack to receive notifications either in a channel or via direct message. We’ll configure a private channel for this blog post. You can refer to this article to create a private Slack channel.

Once that is done, we will create a Slack app for a workspace that will receive the incoming events via webhook. To do that, navigate to https://api.slack.com/apps and “Create a New App”. In the modal that opens, choose “From Scratch”, provide the name, and choose the workspace where you want to create this app. 

Create the app and navigate to the “Add Features and Functionality” section and click on “Incoming Webhooks”. By default, this is turned off, so you need to turn it on. 

Click “And New Webhook to Workspace” and choose the private channel that we created earlier on the next screen.

Copy the webhook URL from the next screen and keep it handy, as we’ll need it while creating a webhook in Testkube.

We have now successfully configured Grafana and Slack to receive data at their respective endpoints. Let us now see how to create a webhook in Testkube that will send data to these endpoints. 

Creating a Webhook in Testkube

Testkube allows you to create Webhooks using the dashboard as well as the CLI. We’ll be using both of them to show you how they work.

Using Dashboard

We’ll set up a webhook for Grafana using the dashboard. This webhook will trigger on the `test-end-failure` event and send the data to the Grafana webhook incident that we configured. 

Launch the Testkube dashboard, navigate to the Webhooks section and “Create a new webhook”. Provide a name and choose the “Resource Identifier” as `test-type: curl-test`, which refers to the cURL test. For “Triggered events”, choose `end-test-failed`. 

On the next screen, provide the Grafana endpoint URL that you generated while setting up Grafana integration. Now we have a successfully configured Grafana webhook. 

Let’s perform similar steps to create a webhook for Slack as well. 

Navigate to the Webhooks section and “Create a new webhook”. Provide a name and choose the “Resource Identifier” as `test-type: curl-test` which refers to the cURL test. For “Triggered events”,choose `end-test-success`. 

On the next screen, provide the Slack incoming webhook URL that you generated while setting up Slack integration.

We have successfully configured the Slack webhook and will now receive events in the Slack channel when any event is sent to this endpoint.

Using CLI

We’ll create a webhook for the Slack integration using the Testkube CLI, which is simple. Open a terminal and use the `testkube create webhook` command to create a webhook. 

```sh

$ echo '{"text": "Test succeeded"}' > webhook.tpl && \testkube create webhook --name slack-cli --events end-test-success --selector test-type=curl-test --header Content-Type=application/json --payload-template webhook.tpl --uri  https://hooks.slack.com/services/ABCDEFGHJKL/MNOPQRSTUVW&& \rm webhook.tpl

```

Below are the parameters used in the create webhook command:

  • `name`: Name of the webhook.
  • ‘events’: Events that will trigger the webhook We’ve provided ‘start-test’ and ‘end-test-success’ which means this will trigger every time a test starts and test finishes successfully.
  • ‘selector’: The resource for which the webhook will be configured, in this case, it’s the curl-test that we’ve created.
  • ‘header’: The header parameters for the request, application/json in this case.
  • `payload-template`: The payload that you want to send, We’re creating a `webhook.tpl` file with the content and later deleting it once the webhook is created.
  • ‘uri’: Slack endpoint URL.

The webhook is created after you execute the above command.

At this point, we have three webhooks created. One for Grafana, which we created from the dashboard, and the other for Slack, which we created using CLI and dashboard. We can confirm the same on the dashboard as well.

Testing the Webhook

Now that we have configured the two webhooks, Grafana and Slack, it’s time to test the webhook. In order to do that, simply run the curl-test that we’ve created. 

When the test fails, you’ll see an incident on the Grafana incident dashboard. You can click on the individual incident to get more details, assign it to other members, etc.

When the test passes, you’ll get a notification in the Slack channel with the message “Test succeeded”. 

That’s how easy it is to configure webhooks in Testkube. We learned how to integrate with Grafana and Slack and send event notifications on test failures and successes. You can similarly configure it for other applications and utilize the benefits of webhooks.

Summary

Testkube changes the way you test with webhooks to test more efficiently. Webhooks in Testkube provide you with real-time insights and automation capabilities that streamline your Kubernetes testing workflows. You can keep your applications informed about test status updates, prompting immediate response and swift actions when needed.

Moreover, Webhooks allow you to seamlessly integrate with your preferred incident management and communication tools without the need for complex configuration. This helps streamline collaboration and adds automation to make your testing more efficient and effective. 

Get started with Testkube and Try out Webhooks in Testkube for your use cases to see how they help you integrate with other tools and improve collaboration. You can also join our Slack community for guidance and support.

Tags
No items found.
Bruno Lopes
Product Leader
Testkube
Share on Twitter
Share on LinkedIn
Share on Reddit
Share on HackerNews
Copy URL

Related Content

No items found.
Responsive

Empowering Kubernetes Tests with Webhooks

Sep 29, 2023
7 min
read
Learn how to take test automation for your apps in Kubernetes to the next level with webhooks. In this tutorial, we'll show you how to set them up for Slack and Grafana Dashboard.
Share on Twitter
Share on LinkedIn
Share on Reddit
Share on HackerNews
Copy URL

Table of Contents

Want to learn more about this topic? Check out our Office Hours sessions!

Get Started with Testkube Pro

Webhooks Intro

The significance of webhooks cannot be overstated. They help bridge the gap between different tools & platforms to enable swift and streamlined communication. Webhooks empower developers and operations teams to seamlessly integrate testing, deployment, and incident response workflows.

Webhooks are automated HTTP callbacks sent from one application to another at specific events or when specific changes occur, enabling real-time information exchange and triggering actions in response to those events. Webhooks play a vital role in automation testing as well as they allow for seamless communication between testing tools, CI framework, and Kubernetes.

In today’s post, we’ll look at Webhooks in Testkube and how they further enhance your testing capability by helping you integrate with other critical systems.

Webhooks in Testkube

Testkube uses webhooks to integrate with external systems, allowing you to effortlessly synchronize your testing workflows with other tools and platforms. These webhooks are designed to carry critical information regarding your tests as HTTP POST payloads. The information can include the execution and real-time status depending on how you configure it

To leverage webhooks, you need to ensure that the platform that you want to send information to has an HTTPS endpoint to receive the events. Testkube also allows you to customize the payloads. 

You can create a webhook from the dashboard, use the CLI, or create it as a custom resource. Before we show how it’s done, let’s understand a few scenarios where Webhooks in Testkube shine:

  • Incident Management & Response: Webhooks can be used to create incidents and alert on-call teams when a critical test fails. This ensures a timely response and avoids any potential disruption due to failures and bugs. With Testkube, you can configure incident management tools like PagerDuty and OpsGenie to receive alerts based on critical events for your tests.
  • Communication and Collaboration: You can configure Webhooks in Testkube to send alerts to your teams in your communication tool. This will notify your team of any critical event that needs attention and attend to it before the issue escalates. Some of the popular communications tools like Slack and MS Teams can be configured to receive alerts from Testkube.
  • Monitoring and Observability: Webhooks can also be used to send alerts and notifications to your monitoring and observability tools like Prometheus and Grafana. This provides visibility into your tests, alerts you, and ensures that timely corrective actions can be taken.

Components of Webhooks

To successfully create and configure a webhook in Testkube, you need to understand how it works and the various components associated with it. These components, comprising events, resources, and destinations collectively form the backbone of webhook functionality. 

  • Events: These are test events that can trigger webhooks. These cover important events in the testing process such as execution, completion, success, and failure. 
  • Resources: These are the objects that trigger an event. With these, Testkube provides you the flexibility to define event triggers aligned with your resource-specific requirements.
  • Destination: These specify where the event data is to be delivered. Testkube allows you to configure webhook endpoints for an array of platforms.

Refer to our Webhook documentation to learn more about the components of webhooks.

Using Webhooks in Testkube

As discussed above, Webhooks are a great way to extend your testing to other platforms. We will now explain how to use webhooks in Testkube. 

To begin, we’ll design a simple cURL test that sends a request to an HTTP endpoint that returns the IP address of our host. We’ll configure webhooks that trigger on success and failure events of tests. We’ll showcase two scenarios: 

  • Incident Management and Response: By configuring test failure events to be sent to a Grafana endpoint.
  • Communication and collaboration: By configuring test successful events to be sent to Slack.

We also have a video for you to follow the steps to create a webhook in Testkube. You can either read through the blog post or watch the video.

Pre-requisites

Below are the prerequisites required to perform/replicate the steps mentioned in the blog post. Feel free to skim through without configuring these if you plan to just read and understand the blog post. 

Create cURL Test

Create a cURL test that sends a request to http://ip.jsontest.com which returns the IP address of the host that was used to send the request. Below is the code snippet:

```js

{
"command": [
  "curl",
   "http://ip.jsontest.com/",
   "-H",
   "'Accept: application/json'"
],
"expected_status": "200",
"expected_body": "{\"ip\": \"120.88.40.166\"}"
  }

```

Configure Destination

We’ll be creating two webhooks, one that sends a notification to a Slack channel when a test passes, the other one sends an update to Grafana’s incident dashboard when the test fails. In this section, we’ll see how to configure Grafana and Slack to receive notifications. 

Setting Up Grafana Integration

We’ll be using Grafana cloud for this blog post; you can also use a self-hosted Grafana instance. The steps would mostly be the same. Create a Grafana Cloud account if you don’t already have one. The free account is all you’ll need for this blog post. 

Once logged in, navigate to Alerts & IRM -> Incidents -> Integrations. Grafana will provide you with a multitude of integration options, choose Incoming Webhooks. Click on the Install Integration button and Grafrana will set the endpoint and provide you with the details. 

Note down the URL for the endpoint. You’ll need this while configuring the webhook in Testkube. 

Setting Up Slack Integration

Testkube provides a Slack integration where you can configure a Testkube bot in your Slack workspace. If your Slack workspace doesn’t allow you to install a bot, you can follow the steps mentioned in this section. 

You can configure Slack to receive notifications either in a channel or via direct message. We’ll configure a private channel for this blog post. You can refer to this article to create a private Slack channel.

Once that is done, we will create a Slack app for a workspace that will receive the incoming events via webhook. To do that, navigate to https://api.slack.com/apps and “Create a New App”. In the modal that opens, choose “From Scratch”, provide the name, and choose the workspace where you want to create this app. 

Create the app and navigate to the “Add Features and Functionality” section and click on “Incoming Webhooks”. By default, this is turned off, so you need to turn it on. 

Click “And New Webhook to Workspace” and choose the private channel that we created earlier on the next screen.

Copy the webhook URL from the next screen and keep it handy, as we’ll need it while creating a webhook in Testkube.

We have now successfully configured Grafana and Slack to receive data at their respective endpoints. Let us now see how to create a webhook in Testkube that will send data to these endpoints. 

Creating a Webhook in Testkube

Testkube allows you to create Webhooks using the dashboard as well as the CLI. We’ll be using both of them to show you how they work.

Using Dashboard

We’ll set up a webhook for Grafana using the dashboard. This webhook will trigger on the `test-end-failure` event and send the data to the Grafana webhook incident that we configured. 

Launch the Testkube dashboard, navigate to the Webhooks section and “Create a new webhook”. Provide a name and choose the “Resource Identifier” as `test-type: curl-test`, which refers to the cURL test. For “Triggered events”, choose `end-test-failed`. 

On the next screen, provide the Grafana endpoint URL that you generated while setting up Grafana integration. Now we have a successfully configured Grafana webhook. 

Let’s perform similar steps to create a webhook for Slack as well. 

Navigate to the Webhooks section and “Create a new webhook”. Provide a name and choose the “Resource Identifier” as `test-type: curl-test` which refers to the cURL test. For “Triggered events”,choose `end-test-success`. 

On the next screen, provide the Slack incoming webhook URL that you generated while setting up Slack integration.

We have successfully configured the Slack webhook and will now receive events in the Slack channel when any event is sent to this endpoint.

Using CLI

We’ll create a webhook for the Slack integration using the Testkube CLI, which is simple. Open a terminal and use the `testkube create webhook` command to create a webhook. 

```sh

$ echo '{"text": "Test succeeded"}' > webhook.tpl && \testkube create webhook --name slack-cli --events end-test-success --selector test-type=curl-test --header Content-Type=application/json --payload-template webhook.tpl --uri  https://hooks.slack.com/services/ABCDEFGHJKL/MNOPQRSTUVW&& \rm webhook.tpl

```

Below are the parameters used in the create webhook command:

  • `name`: Name of the webhook.
  • ‘events’: Events that will trigger the webhook We’ve provided ‘start-test’ and ‘end-test-success’ which means this will trigger every time a test starts and test finishes successfully.
  • ‘selector’: The resource for which the webhook will be configured, in this case, it’s the curl-test that we’ve created.
  • ‘header’: The header parameters for the request, application/json in this case.
  • `payload-template`: The payload that you want to send, We’re creating a `webhook.tpl` file with the content and later deleting it once the webhook is created.
  • ‘uri’: Slack endpoint URL.

The webhook is created after you execute the above command.

At this point, we have three webhooks created. One for Grafana, which we created from the dashboard, and the other for Slack, which we created using CLI and dashboard. We can confirm the same on the dashboard as well.

Testing the Webhook

Now that we have configured the two webhooks, Grafana and Slack, it’s time to test the webhook. In order to do that, simply run the curl-test that we’ve created. 

When the test fails, you’ll see an incident on the Grafana incident dashboard. You can click on the individual incident to get more details, assign it to other members, etc.

When the test passes, you’ll get a notification in the Slack channel with the message “Test succeeded”. 

That’s how easy it is to configure webhooks in Testkube. We learned how to integrate with Grafana and Slack and send event notifications on test failures and successes. You can similarly configure it for other applications and utilize the benefits of webhooks.

Summary

Testkube changes the way you test with webhooks to test more efficiently. Webhooks in Testkube provide you with real-time insights and automation capabilities that streamline your Kubernetes testing workflows. You can keep your applications informed about test status updates, prompting immediate response and swift actions when needed.

Moreover, Webhooks allow you to seamlessly integrate with your preferred incident management and communication tools without the need for complex configuration. This helps streamline collaboration and adds automation to make your testing more efficient and effective. 

Get started with Testkube and Try out Webhooks in Testkube for your use cases to see how they help you integrate with other tools and improve collaboration. You can also join our Slack community for guidance and support.