This repository has been archived by the owner on Mar 13, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(examples): add generate example
Signed-off-by: Mark Sagi-Kazar <[email protected]>
- Loading branch information
1 parent
e0b286b
commit 6ca9e91
Showing
5 changed files
with
169 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# OpenMeter details | ||
OPENMETER_URL=https://openmeter.cloud | ||
OPENMETER_TOKEN=<insert your token here> | ||
|
||
BATCH_SIZE=20 | ||
BATCH_PERIOD=2s | ||
|
||
# Enable debug logging | ||
DEBUG=false | ||
|
||
# Seeder configuration | ||
# For more details see https://www.benthos.dev/docs/components/inputs/generate | ||
SEEDER_COUNT=0 | ||
SEEDER_INTERVAL=1s | ||
SEEDER_BATCH_SIZE=1 | ||
|
||
SEEDER_LOG=false |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
# Generate | ||
|
||
This example is based on [our earlier blog post](https://openmeter.io/blog/testing-stream-processing) about testing OpenMeter with Benthos. | ||
|
||
The input in this case generates random events (mimicking API calls). | ||
|
||
## Table of Contents <!-- omit from toc --> | ||
|
||
- [Prerequisites](#prerequisites) | ||
- [Launch the example](#launch-the-example) | ||
- [Checking events](#checking-events) | ||
- [Cleanup](#cleanup) | ||
- [Advanced configuration](#advanced-configuration) | ||
- [Production use](#production-use) | ||
|
||
## Prerequisites | ||
|
||
This example uses [Docker](https://docker.com) and [Docker Compose](https://docs.docker.com/compose/), but you are free to run the components in any other way. | ||
|
||
Check out this repository if you want to run the example locally: | ||
|
||
```shell | ||
git clone https://github.com/openmeterio/benthos-openmeter.git | ||
cd benthos-openmeter/examples/generate | ||
``` | ||
|
||
Create a new `.env` file and add the details of your OpenMeter instance: | ||
|
||
```shell | ||
cp .env.dist .env | ||
# edit .env and fill in the details | ||
``` | ||
|
||
> [!TIP] | ||
> Tweak other options in the `.env` file to change the behavior of the example. | ||
Create a meter in OpenMeter with the following details: | ||
|
||
- Event type: `api-calls` | ||
- Aggregation: `SUM` | ||
- Value property: `$.duration_ms` | ||
- Group by (optional): | ||
- `method`: `$.method` | ||
- `path`: `$.path` | ||
- `region`: `$.region` | ||
- `zone`: `$.zone` | ||
|
||
> [!TIP] | ||
> Read more about creating a meter in the general examples [README](../README.md#Create-a-meter). | ||
## Launch the example | ||
|
||
Launch the example: | ||
|
||
```shell | ||
docker compose up -d | ||
``` | ||
|
||
> [!WARNING] | ||
> By default the example generates 1000 events per second. | ||
## Checking events | ||
|
||
Read more in the general examples [README](../README.md#Checking-events-in-OpenMeter). | ||
|
||
## Cleanup | ||
|
||
Stop containers: | ||
|
||
```shell | ||
docker compose down -v | ||
``` | ||
|
||
## Advanced configuration | ||
|
||
Check out the configuration files and the [Benthos documentation](https://www.benthos.dev/docs/about) for more details. | ||
|
||
## Production use | ||
|
||
We are actively working on improving the documentation and the examples. | ||
In the meantime, feel free to contact us [in email](https://us10.list-manage.com/contact-form?u=c7d6a96403a0e5e19032ee885&form_id=fe04a7fc4851f8547cfee56763850e95) or [on Discord](https://discord.gg/nYH3ZQ3Xzq). | ||
|
||
We are more than happy to help you set up OpenMeter in your production environment. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
input: | ||
generate: | ||
count: ${SEEDER_COUNT:0} | ||
interval: "${SEEDER_INTERVAL:1s}" | ||
batch_size: ${SEEDER_BATCH_SIZE:1} | ||
mapping: | | ||
let max_subjects = ${SEEDER_MAX_SUBJECTS:100} | ||
let event_type = "api-calls" | ||
let source = "api-gateway" | ||
let methods = ["GET", "POST"] | ||
let paths = ["/", "/about", "/contact", "/pricing", "/docs"] | ||
let regions = ["us-east-1", "us-west-1", "us-east-2", "us-west-2"] | ||
let zoneSuffixes = ["a", "b", "c", "d"] | ||
let subject = "customer-%d".format(random_int(seed: timestamp_unix_nano()) % $max_subjects) | ||
let time = (now().ts_sub_iso8601("P3D").ts_unix() + random_int(min: 60, max: 60 * 60 * 24 * 3)).ts_format() | ||
let method = $methods.index(random_int(seed: timestamp_unix_nano()) % $methods.length()) | ||
let path = $paths.index(random_int(seed: timestamp_unix_nano()) % $paths.length()) | ||
let region = $regions.index(random_int(seed: timestamp_unix_nano()) % $regions.length()) | ||
let zone = "%s%s".format($region, $zoneSuffixes.index(random_int(seed: timestamp_unix_nano()) % $zoneSuffixes.length())) | ||
let duration = random_int(seed: timestamp_unix_nano(), max: 1000) | ||
root = { | ||
"id": uuid_v4(), | ||
"specversion": "1.0", | ||
"type": $event_type, | ||
"source": $source, | ||
"subject": $subject, | ||
"time": $time, | ||
"data": { | ||
"method": $method, | ||
"path": $path, | ||
"region": $region, | ||
"zone": $zone, | ||
"duration_ms": $duration, | ||
}, | ||
} | ||
output: | ||
switch: | ||
cases: | ||
- check: "" | ||
continue: true | ||
output: | ||
openmeter: | ||
url: "${OPENMETER_URL:https://openmeter.cloud}" | ||
token: "${OPENMETER_TOKEN:}" | ||
batching: | ||
count: ${BATCH_SIZE:20} | ||
period: ${BATCH_PERIOD:} | ||
|
||
- check: '"${SEEDER_LOG:false}" == "true"' | ||
output: | ||
stdout: | ||
codec: lines |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
version: "3.9" | ||
|
||
services: | ||
collector: | ||
image: ghcr.io/openmeterio/benthos-openmeter | ||
pull_policy: always | ||
command: benthos -c /etc/benthos/config.yaml | ||
env_file: | ||
- .env | ||
volumes: | ||
- ./config.yaml:/etc/benthos/config.yaml:ro |