-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs(examples): Update Kinesis Time Travel Example (#163)
* docs(examples): Update Kinesis Time Travel Example * docs: Add Sample Data * docs: Update Shard Count
- Loading branch information
Showing
10 changed files
with
62 additions
and
122 deletions.
There are no files selected for viewing
6 changes: 4 additions & 2 deletions
6
examples/terraform/aws/kinesis/time_travel/config/const.libsonnet
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 |
---|---|---|
@@ -1,10 +1,12 @@ | ||
local sub = import '../../../../../../build/config/substation.libsonnet'; | ||
|
||
{ | ||
is_process: [ | ||
sub.cnd.str.eq({ obj: { src: 'event.category' }, value: 'process' }), | ||
sub.cnd.str.eq({ obj: { src: 'event.type' }, value: 'start' }), | ||
], | ||
kv_store: sub.kv_store.aws_dynamodb({ | ||
table_name: 'substation', | ||
attributes: { partition_key: 'PK', sort_key: 'SK', ttl: 'TTL', value: 'cache' }, | ||
}), | ||
field: 'context', | ||
field_exists: sub.cnd.num.len.gt({ obj: { src: $.field }, value: 0 }), | ||
} |
12 changes: 5 additions & 7 deletions
12
examples/terraform/aws/kinesis/time_travel/config/enrichment/config.jsonnet
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 |
---|---|---|
@@ -1,18 +1,16 @@ | ||
// Puts process metadata into the KV store. | ||
local sub = import '../../../../../../../build/config/substation.libsonnet'; | ||
local const = import '../const.libsonnet'; | ||
|
||
{ | ||
// The concurrency is set to 1 to ensure that the KV store is not updated in parallel. | ||
concurrency: 1, | ||
transforms: [ | ||
// If the field exists, then put the value into the KV store. If the data stream is | ||
// at risk of write heavy activity, then consider first querying the KV store to see | ||
// if the value already exists and only writing if it does not. | ||
// If the event is a process, then store the process metadata in the KV store | ||
// indexed by the PID. The data is stored in the KV store for 90 days. | ||
sub.pattern.tf.conditional( | ||
condition=sub.cnd.all(const.field_exists), | ||
// The ttl_offset is low for the purposes of this example. It should be set to a | ||
// value that is appropriate for the data stream (usually hours or days). | ||
transform=sub.tf.enrich.kv_store.set({ obj: { src: 'ip', trg: const.field }, ttl_offset: '30s', kv_store: const.kv_store }), | ||
condition=sub.cnd.all(const.is_process), | ||
transform=sub.tf.enrich.kv_store.set({ obj: { src: 'process.pid', trg: 'process' }, prefix: 'process', ttl_offset: std.format('%dh', 24 * 90), kv_store: const.kv_store, close_kv_store: false }), | ||
), | ||
], | ||
} |
16 changes: 0 additions & 16 deletions
16
examples/terraform/aws/kinesis/time_travel/config/subscriber/config.jsonnet
This file was deleted.
Oops, something went wrong.
28 changes: 28 additions & 0 deletions
28
examples/terraform/aws/kinesis/time_travel/config/transform/config.jsonnet
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,28 @@ | ||
// All values in the KV store were put there by the `enrichment` function. | ||
local sub = import '../../../../../../../build/config/substation.libsonnet'; | ||
local const = import '../const.libsonnet'; | ||
|
||
{ | ||
concurrency: 2, | ||
transforms: [ | ||
// process.* | ||
// | ||
// This is only applied to non-process events. | ||
sub.pattern.tf.conditional( | ||
condition=sub.cnd.none(const.is_process), | ||
transform=sub.tf.enrich.kv_store.get({ obj: { src: 'process.pid', trg: 'process' }, prefix: 'process', kv_store: const.kv_store }), | ||
), | ||
// process.parent.* | ||
sub.pattern.tf.conditional( | ||
condition=sub.cnd.num.len.gt({ obj: { src: 'process.parent.pid' }, value: 0 }), | ||
transform=sub.tf.enrich.kv_store.get({ obj: { src: 'process.parent.pid', trg: 'process.parent' }, prefix: 'process', kv_store: const.kv_store }), | ||
), | ||
// process.parent.parent.* | ||
sub.pattern.tf.conditional( | ||
condition=sub.cnd.num.len.gt({ obj: { src: 'process.parent.parent.pid' }, value: 0 }), | ||
transform=sub.tf.enrich.kv_store.get({ obj: { src: 'process.parent.parent.pid', trg: 'process.parent.parent' }, prefix: 'process', kv_store: const.kv_store }), | ||
), | ||
// Print the results. | ||
sub.tf.send.stdout(), | ||
], | ||
} |
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,4 @@ | ||
{"event":{"category":"network","type":"connection"},"process":{"name":"Spotify","pid":"d3a6c0b9d3751559f206e12fb1b8f226"},"server":{"ip":"35.186.224.39","port":443},"@timestamp":"2024-03-29T04:02:38.470000Z"} | ||
{"event":{"category":"process","type":"start"},"process":{"command_line":"/sbin/launchd","name":"launchd","pid":"f23e8b548d2e5e1ef3e122a9c5e08a63","start":"2024-03-13T16:17:45.000000Z","parent":{"pid":"b745f7a7c3a98ac5f087be7420e6e3f9"}}} | ||
{"event":{"category":"process","type":"start"},"process":{"command_line":"/usr/libexec/runningboardd","name":"runningboardd","pid":"8faae8aa27f9b4faff6fd98e60201e3d","start":"2024-03-13T16:17:49.000000Z","parent":{"pid":"f23e8b548d2e5e1ef3e122a9c5e08a63"}}} | ||
{"event":{"category":"process","type":"start"},"process":{"command_line":"/Applications/Spotify.app/Contents/MacOS/Spotify","name":"Spotify","pid":"d3a6c0b9d3751559f206e12fb1b8f226","start":"2024-03-13T16:29:17.000000Z","parent":{"pid":"8faae8aa27f9b4faff6fd98e60201e3d"}}} |
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,2 @@ | ||
sleep 5 | ||
AWS_DEFAULT_REGION=$AWS_REGION python3 ../build/scripts/aws/kinesis/put_records.py substation terraform/aws/kinesis/time_travel/data.jsonl --print-response |
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
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
20 changes: 9 additions & 11 deletions
20
...nesis/time_travel/terraform/subscriber.tf → ...inesis/time_travel/terraform/transform.tf
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 |
---|---|---|
@@ -1,31 +1,29 @@ | ||
module "lambda_subscriber" { | ||
module "lambda_transform" { | ||
source = "../../../../../../build/terraform/aws/lambda" | ||
appconfig = module.appconfig | ||
|
||
config = { | ||
name = "subscriber" | ||
name = "transform" | ||
description = "Substation node that reads from Kinesis with a delay to support enrichment" | ||
image_uri = "${module.ecr.url}:v1.2.0" | ||
image_arm = true | ||
|
||
env = { | ||
"SUBSTATION_CONFIG" : "http://localhost:2772/applications/substation/environments/example/configurations/subscriber" | ||
"SUBSTATION_CONFIG" : "http://localhost:2772/applications/substation/environments/example/configurations/transform" | ||
"SUBSTATION_LAMBDA_HANDLER" : "AWS_KINESIS_DATA_STREAM" | ||
"SUBSTATION_DEBUG" : true | ||
} | ||
} | ||
|
||
depends_on = [ | ||
module.appconfig.name, | ||
module.ecr.url, | ||
] | ||
} | ||
|
||
resource "aws_lambda_event_source_mapping" "lambda_subscriber" { | ||
resource "aws_lambda_event_source_mapping" "lambda_transform" { | ||
event_source_arn = module.kinesis.arn | ||
function_name = module.lambda_subscriber.arn | ||
function_name = module.lambda_transform.arn | ||
maximum_batching_window_in_seconds = 15 | ||
batch_size = 100 | ||
parallelization_factor = 1 | ||
starting_position = "LATEST" | ||
# In this example, we start from the beginning of the stream, | ||
# but in a prod environment, you may want to start from the end | ||
# of the stream to avoid processing old data ("LATEST"). | ||
starting_position = "TRIM_HORIZON" | ||
} |