We are building OpenMeter to help engineers collect and process millions of usage events to power usage-based pricing and product use cases. Working with large volumes of data used for accurate billing requires rigorous development and testing procedures. One significant challenge we faced in our journey was generating and ingesting sample data at a scale that would mimic real-world scenarios. We needed a tool that consistently generates random sample usage, formats it into CloudEvents, and sends it to our HTTP ingestion endpoint.
Our journey led us through several options. From thinking about writing simple scripts to trying out third-party tools. That’s when we stumbled upon Benthos.
Introducing Benthos
Benthos is a robust stream processing tool. Given our involvement in the event processing domain, Benthos felt familiar and synergistic with our goals. At its core, Benthos operates on a simple yet effective concept: it seamlessly ingests data from various inputs, sends it through custom-designed pipelines, and then directs it to one or multiple outputs.
One standout feature of Benthos is
Bloblang (or blobl
for
short). Bloblang is a data mapping language that facilitates a wide range of
transformations on structured data. For example, it can generate random data and
act as a Benthos input,
serving as a data source.
Utilizing Bloblang, we can shape our data into the desired CloudEvents format and randomize elements, ensuring that our testing data remains diverse and representative of real-world usage data.
Example Usage
Let’s look at an example of creating a Benthos configuration capable of generating and ingesting sample data.
First, we need an input that generates data. We use a Benthos input called generate for that and create a CloudEvents compatible structure using Bloblang:
The next step is sending the data to OpenMeter using the http_client output:
Finally, run Benthos (check the Getting started guide for instructions to install Benthos):
The above command will tell Benthos to generate a new event every 50ms and send it to the OpenMeter API.
Check out our the configuration we use for more options on our GitHub.