# Sampling

{% hint style="info" %}
See the changelog of this Action type [here](/actions/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.

<figure><picture><source srcset="/files/cg8HoTxaSktBMXx9SVZk" media="(prefers-color-scheme: dark)"><img src="/files/nSOoP9rK1nhAEZMwM70D" alt=""></picture><figcaption></figcaption></figure>

{% hint style="warning" %}
In order to configure this action, you must first link it to a Listener. Go to [Building a Pipeline ](/the-workspace/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><mark style="color:red;"><strong>*</strong></mark></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><mark style="color:red;"><strong>*</strong></mark></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
  },
  ...
}
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.onum.com/the-workspace/pipelines/actions/filtering/sampling.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
