> For the complete documentation index, see [llms.txt](https://docs.onum.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.onum.com/pipelines/actions/filtering/sampling.md).

# Sampling

{% hint style="info" %}
See the changelog of this Action type [here](/actions-changelog/sampling.md).
{% endhint %}

## Overview

The **Sampling** Action allows only a specific number of allowed events out of every set of n events to go through it.

{% hint style="warning" %}
In order to configure this action, you must first link it to a Listener. Go to [Building a Pipeline ](/pipelines/building-a-pipeline.md)to learn how to link.
{% endhint %}

## Ports <a href="#ports" id="ports"></a>

These are the input and output ports of this Action:

<details>

<summary>Input ports</summary>

* **Default port** - All the events to be processed by this Action enter through this port.

</details>

<details>

<summary>Output ports</summary>

* **Default port** - Events are sent through this port if no error occurs while processing them.
* **Error port** - Events are sent through this port if an error occurs while processing them.

</details>

## Configuration

{% stepper %}
{% step %}
Find **Sampling** in the **Actions** tab (under the **Filtering** group) and drag it onto the canvas. Link it to the required [Listener](https://docs.onum.com/the-workspace/listeners) and [Data sink](https://docs.onum.com/the-workspace/pipelines/data-sinks).
{% endstep %}

{% step %}
To open the configuration, click the Action in the canvas and select **Configuration**.
{% endstep %}

{% step %}
Enter the required parameters:

<table><thead><tr><th width="173">Parameter</th><th>Description</th></tr></thead><tbody><tr><td><strong>Allowed Events</strong></td><td>The number of events to sample. The first n events will be filtered from each set of total events indicated.</td></tr><tr><td><strong>Total Events</strong></td><td>Out of how many total events that are entering the action. When the number of allowed events is filtered, a new set with this number of total events will be taken again.</td></tr></tbody></table>
{% endstep %}

{% step %}
Click **Save** to complete.
{% endstep %}
{% endstepper %}

## Example

Let's say we want to filter the first event out of each set of 3 of our input events. To do it:

{% stepper %}
{% step %}
Add the **Sampling** Action to your Pipeline and link it to your required Listener.
{% endstep %}

{% step %}
Now, double-click the **Sampling** Action to configure it. You need to set the following config:

<table><thead><tr><th width="185">Parameter</th><th>Description</th></tr></thead><tbody><tr><td><strong>Allowed Events</strong></td><td>Enter <em>1</em>.</td></tr><tr><td><strong>Total Events</strong></td><td>Enter <em>3</em>.</td></tr></tbody></table>
{% endstep %}

{% step %}
Now link the *Default* output port of the Action to the input port of your Data sink.
{% endstep %}

{% step %}
Finally, click **Publish** and choose which clusters you want to publish the Pipeline in.
{% endstep %}

{% step %}
Click **Test pipeline** at the top of the area and choose a specific number of events to test if your data is transformed properly. Click **Debug** to proceed.
{% endstep %}
{% endstepper %}

From this set of events:

```
{
  {
    "IP_Address": "192.168.1.1",
    "GET_Count": 2,
    "POST_Count": 1
  },
  {
    "IP_Address": "192.168.1.2",
    "GET_Count": 5,
    "POST_Count": 7
  },
  {
    "IP_Address": "192.168.1.3",
    "GET_Count": 9,
    "POST_Count": 2
  },
  {
    "IP_Address": "192.168.1.4",
    "GET_Count": 29,
    "POST_Count": 6
  },
  {
    "IP_Address": "192.168.1.5",
    "GET_Count": 98,
    "POST_Count": 6
  },
  {
    "IP_Address": "192.168.1.6",
    "GET_Count": 12,
    "POST_Count": 16
  },
  ...
}
```

We will get the following (the first event for each set of 3 events):

```
{
  {
    "IP_Address": "192.168.1.1",
    "GET_Count": 2,
    "POST_Count": 1
  },
  {
    "IP_Address": "192.168.1.4",
    "GET_Count": 29,
    "POST_Count": 6
  },
  ...
}
```
