Skip to main content

learn

Profiler

Commentary​

Evolving feature: subject to change

Many times when you need to create synthetic data, you're working backwards from a hypothesis. For example, you may want to demonstrate what happens in your project when it encounters some critical trait or edge case in your data, so you carefully configure ShadowTraffic with a particular schema, data range, and the like.

But other times, you might want to simulate an existing data source—one you may not know much about, or is so large and complex that it would be tedious to simulate by hand.

To that end, ShadowTraffic Profiler is a built-in tool that connects to existing data sources and automatically generates a matching ShadowTraffic simulation. It statistically models your schema and data, determining a representative simulation that retains its essential properties without compromising privacy of the original data.

Motivation​

Some examples that motivate where you'd use this:

  1. You have an existing data source and want a zero-configuration way to make more data like it.
  2. You want to simulate hundreds or thousands of tables/topics.
  3. Your schemas are complex, with many columns and deep nesting.
  4. The properties of your data aren't obvious or easily discoverable, like the distribution of numeric values.
  5. The relationships (foreign keys) between your data sources aren't obvious.
  6. Your data contains outliers and schema violations, and you want to simulate those in similar proportion.

How it works​

Configuring the profiler​

Like all other features of ShadowTraffic, the Profiler launches with the help of a few command line arguments. In this case, the Profiler needs to know only one thing: where are your existing data sources? --config supplies that information:

docker run --env-file license.env \
-v $(pwd)/your-config.json:/home/config.json \
shadowtraffic/shadowtraffic:latest \
--action profile \
--config /home/config.json

The content of config.json largely mirrors a standard ShadowTraffic configuration file, except you're only required to supply a connections block. By default, the Profiler will read at most 1,000,000 events from each collection in each source, though that can be overridden as seen below. Putting it all together in an example that profiles data from Kafka, a basic config.json may look like:

{
"profiler": {
"sampleCount": 50000
},
"connections": {
"prod-kafka": {
"kind": "kafka",
"consumerConfigs": {
"bootstrap.servers": "broker:9092",
"schema.registry.url": "http://schema-registry:8081",
"key.deserializer": "org.apache.kafka.common.serialization.StringDeserializer",
"value.deserializer": "io.confluent.kafka.serializers.KafkaAvroDeserializer"
},
"topics": [
{
"topic": "orders"
}
]
}
}
}

With that, the Profiler will boot up and use everything it can to learn what the corresponding complete ShadowTraffic file should look like. In this case, it might output something like:

Example output
{
"generators": [
{
"connection": "prod-kafka",
"topic": "orders",
"value": {
"order_id": {
"_gen": "uuid"
},
"status": {
"_gen": "weightedOneOf",
"choices": [
{
"weight": 204,
"value": "PENDING"
},
{
"weight": 257,
"value": "SHIPPED"
},
// ...and more
]
},
"amount": {
"_gen": "weightedOneOf",
"choices": [
{
"weight": 3,
"value": {
"_gen": "uniformDistribution",
"bounds": [
159.09,
162.27
]
}
},
{
"weight": 1,
"value": {
"_gen": "uniformDistribution",
"bounds": [
13.65,
13.93
]
}
},
// ...and more
]
},
"placed_at": {
"_gen": "uniformDistribution",
"bounds": [
1795022330543,
1795022331103
],
"decimals": 0
},
"shipped_at": {
"_gen": "weightedOneOf",
"choices": [
{
"weight": 386,
"value": null
},
{
"weight": 614,
"value": {
"_gen": "uniformDistribution",
"bounds": [
1795022330543,
1795022331103
],
"decimals": 0
}
}
]
},
"customer": {
"name": {
"_gen": "characterString",
"n": {
"_gen": "weightedOneOf",
"choices": [
{
"weight": 131,
"value": {
"_gen": "uniformDistribution",
"bounds": [
14.78,
15.07
]
}
},
{
"weight": 93,
"value": {
"_gen": "uniformDistribution",
"bounds": [
16.0,
16.32
]
}
},
// ...and more
]
},
"case": "mixed"
},
"tier": {
"_gen": "characterString",
"n": {
"_gen": "weightedOneOf",
"choices": [
{
"weight": 701,
"value": {
"_gen": "uniformDistribution",
"bounds": [
5.94,
6
]
}
},
{
"weight": 299,
"value": {
"_gen": "uniformDistribution",
"bounds": [
4,
4.08
]
}
}
]
},
"case": "lower"
}
},
"tags": {
"_gen": "repeatedly",
"n": {
"_gen": "weightedOneOf",
"choices": [
{
"weight": 332,
"value": {
"_gen": "constant",
"x": 0
}
},
{
"weight": 332,
"value": {
"_gen": "uniformDistribution",
"bounds": [
1.99,
2
]
}
},
// ...and more
],
"decimals": 0
},
"target": {
"_gen": "characterString",
"n": {
"_gen": "weightedOneOf",
"choices": [
{
"weight": 516,
"value": {
"_gen": "uniformDistribution",
"bounds": [
4,
4.08
]
}
},
{
"weight": 484,
"value": {
"_gen": "uniformDistribution",
"bounds": [
6.96,
7
]
}
}
]
},
"case": "lower"
}
},
"note": {
"_gen": "weightedOneOf",
"choices": [
{
"weight": 804,
"value": null
},
{
"weight": 196,
"value": {
"_gen": "characterString",
"n": {
"_gen": "weightedOneOf",
"choices": [
{
"weight": 1,
"value": {
"_gen": "uniformDistribution",
"bounds": [
14.78,
15.07
]
}
},
{
"weight": 6,
"value": {
"_gen": "uniformDistribution",
"bounds": [
18.74,
19.12
]
}
},
// ...and more
]
},
"case": "mixed"
}
}
]
}
},
"producerConfigs": {
"value.serializer": "io.confluent.kafka.serializers.KafkaAvroSerializer"
},
"key": null
}
],
"connections": {
"prod-kafka": {
"kind": "kafka",
"producerConfigs": {
"bootstrap.servers": "broker:9092",
"schema.registry.url": "http://schema-registry:8081",
"key.serializer": "org.apache.kafka.common.serialization.StringSerializer",
"value.serializer": "org.apache.kafka.common.serialization.StringSerializer"
}
}
}
}

Profiling is currently only supported for certain connections. For programmatic usage, it's recommended to invoke profiling with the --quiet flag to elide ShadowTraffic's logging output.

Supported parameters​

The top-level profiler block takes the following parameters:

  • sampleCount: the maximum amount of events to be profiled
  • sampleMs: the window of time for events to be profiled (only supported by certain systems)
  • sampleDirection: whether to sample from the oldest or newest messages available. Defaults to oldest.

All of these parameters may be overridden on a case-by-case basis for each connection. See below for each connection type.

Additionally, when both sampleCount and sampleMs are provided, profiling will terminate when either condition is met.

Examples​

Profiling Kafka​

Currently, ShadowTraffic will only profile topics that are:

  1. Serialized with Avro through Schema Registry
  2. Serialized with JSON Schema, also through Schema Registry
  3. Serialized with plain JSON

To profile those topics, you need only two required parameters:

  1. consumerConfigs: your broker endpoint, and optionally your Schema Registry endpoint
  2. topics: an array of topics to simulate

For topics linked to Schema Registry, the Profiler assumes a default TopicNameStrategy naming convention, though both the key and value subjects can be overridden. Additionally, deserializers for topics linked to Schema Registry will be automatically discovered, so there's no need to supply them in the consumerConfigs block.

You can also override the maximum number of events or window of time that will be sampled in each topic. The default sample direction is oldest (earlier offsets), as opposed to newest (latest offsets).

Lastly, each element of the topics array can take an optional consumerConfigs, which will override any parameters in the parent attribute above. This is useful when ShadowTraffic can't automatically discover the deserializers needed to read your data (as in the case of plain JSON).

An example config.json file demonstrating all that looks like:

{
"connections": {
"prod-kafka": {
"kind": "kafka",
"consumerConfigs": {
"bootstrap.servers": "broker:9092",
"schema.registry.url": "http://schema-registry:8081"
},
"topics": [
{
"topic": "topic-a"
},
{
"topic": "topic-b",
"keySubjectName": "specialKeySubject",
"valueSubjectName": "nonstandardValueSubject",
"sampleCount": 25000
},
{
"topic": "topic-c",
"sampleDirection": "newest",
"sampleMs": 3600000,
"consumerConfigs": {
"key.deserializer": "io.shadowtraffic.kafka.serdes.JsonDeserializer",
"value.deserializer": "io.shadowtraffic.kafka.serdes.JsonDeserializer"
}
}
]
}
}
}