-
Notifications
You must be signed in to change notification settings - Fork 54
Add Template output format to EventBridge Reaction #344
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Co-authored-by: ruokun-niu <[email protected]>
|
@copilot there should be distinct templates per query per change type (added/updated/deleted). Please see the Http reaction docs for reference: https://drasi.io/how-to-guides/configure-reactions/configure-http-reaction/ |
Co-authored-by: danielgerlag <[email protected]>
Updated to use per-query templates. Each query can now define its own addedTemplate, updatedTemplate, and deletedTemplate in the query configuration section, matching the HTTP reaction pattern. See commit 81e1cde. |
|
@copilot add some integration tests under e2e-tests under the main root folder. Inspect the existing tests to understand how they work, they spin up a local kind cluster as an environment to execute the tests. Use localstack to emulate the AWS services, this can be added as kubernetes yaml and run as a container in the kind cluster, like we currently do with postgres. |
Co-authored-by: danielgerlag <[email protected]>
Added e2e integration tests in |
| properties: | ||
| eventBusName: default | ||
| format: handlebars | ||
| serviceUrl: http://localstack.default.svc.cluster.local:4566 |
Check warning
Code scanning / devskim
An HTTP-based URL without TLS was detected. Warning
|
|
||
| let dbClient = new pg.Client({ | ||
| database: "test-db", | ||
| host: "127.0.0.1", |
Check notice
Code scanning / devskim
Accessing localhost could indicate debug code, or could hinder scaling. Note
| secretAccessKey: test | ||
| region: us-east-1 | ||
| queries: | ||
| product-query: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@copilot this is a yaml string that should be here, so it needs to be "product-query: |"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed. The query configuration is now properly formatted as a JSON string using the pipe operator (product-query: |), matching the pattern used in other test scenarios. Also updated the readme examples to use the same format. See commit 94d0bcb.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@copilot no, it should look more like this:
queries:
product-query: |
added: |
{
"eventType": "ProductAdded",
"productId": {{after.product_id}},
"name": "{{after.name}}",
"description": "{{after.description}}",
"price": {{after.price}}
}
updated: |
{
"eventType": "ProductUpdated",
"productId": {{after.product_id}},
"name": "{{after.name}}",
"description": "{{after.description}}",
"price": {{after.price}},
"previousPrice": {{before.price}}
}
deleted: |
{
"eventType": "ProductDeleted",
"productId": {{before.product_id}},
"name": "{{before.name}}"
}There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated the YAML format to use added:, updated:, deleted: sections with template: and metadata: properties as shown in your example. See commit 53ec10f.
Co-authored-by: danielgerlag <[email protected]>
|
@copilot No, there should not be raw json in that field, it should be yaml! |
Co-authored-by: danielgerlag <[email protected]>
Fixed. Changed from JSON to YAML format for query configuration. Updated Program.cs to use |
| secretAccessKey: test | ||
| region: us-east-1 | ||
| queries: | ||
| product-query: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@copilot no, it should look more like this:
queries:
product-query: |
added: |
{
"eventType": "ProductAdded",
"productId": {{after.product_id}},
"name": "{{after.name}}",
"description": "{{after.description}}",
"price": {{after.price}}
}
updated: |
{
"eventType": "ProductUpdated",
"productId": {{after.product_id}},
"name": "{{after.name}}",
"description": "{{after.description}}",
"price": {{after.price}},
"previousPrice": {{before.price}}
}
deleted: |
{
"eventType": "ProductDeleted",
"productId": {{before.product_id}},
"name": "{{before.name}}"
}|
|
||
| namespace Drasi.Reactions.EventBridge.Models; | ||
|
|
||
| public class QueryConfig |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's rename these to "added", "updated" and "deleted", and instead of just the template string, let's make it an object, with 2 fields:
- template (the actual template string)
- metadata (an object the represents the metadata key value pairs for the cloud event)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Renamed the properties to added, updated, and deleted. Each is now an object with template (the Handlebars template string) and metadata (optional key-value pairs for the cloud event). See commit 53ec10f.
…tadata objects Co-authored-by: danielgerlag <[email protected]>
| List<PutEventsRequestEntry> handlebarsRequestEntries = new List<PutEventsRequestEntry>(); | ||
| foreach (var result in handlebarsResults) | ||
| { | ||
| var handlebarsCloudEvent = new CloudEvent |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@copilot why are we not longer creating a CloudEvent?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch - that was an oversight. I've restored the CloudEvent wrapper to be consistent with the Packed and Unpacked formats. See commit 91f1a7f.
Co-authored-by: danielgerlag <[email protected]>
| } | ||
|
|
||
| break; | ||
| case OutputFormat.Handlebars: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@copilot please call this new format "template" instead of "handlebars"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Renamed the format from "handlebars" to "template" in the OutputFormat enum, ChangeHandler, ControlSignalHandler, YAML configuration, and documentation. See commit e2d15f3.
| var handlebarsCloudEvent = new CloudEvent | ||
| { | ||
| Id = Guid.NewGuid().ToString(), | ||
| Type = $"Drasi.ChangeEvent.{result.Op}", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Coilot the type should just be "Drasi.ChangeEvent"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed. The CloudEvent type is now set to "Drasi.ChangeEvent" for the template format. See commit e2d15f3.
| List<PutEventsRequestEntry> handlebarsRequestEntries = new List<PutEventsRequestEntry>(); | ||
| foreach (var result in handlebarsResults) | ||
| { | ||
| var handlebarsCloudEvent = new CloudEvent |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@copilot where do we add the metadata?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added metadata support to CloudEvent. The CloudEvent class now has a Metadata property that uses [JsonExtensionData] to serialize metadata as extension attributes in the JSON output. In the ChangeHandler, metadata from the template config is applied to the CloudEvent before serialization. See commit e2d15f3.
|
|
||
| namespace Drasi.Reactions.EventBridge.Services | ||
| { | ||
| public class HandlebarsChangeFormatter |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
…adata support Co-authored-by: danielgerlag <[email protected]>
|
@copilot update the default reaction provider that gets installed by the CLI with the new variant of the enum. Also, update the e2e test infrastructure to also load the docker image for the eventbridge reaction |
Co-authored-by: danielgerlag <[email protected]>
Added EventBridge reaction provider to |
Description
This PR adds support for template-based output formatting to EventBridge Reaction, enabling custom event transformation similar to HTTP reaction with per-query template configuration using Handlebars templates.
Changes Made
added,updated,deletedsections, each containing:template: The Handlebars template string for formatting outputmetadata: Optional key-value pairs for CloudEvent extension attributesTemplateas a third format optiondefault-reaction-providers.yamlwith format enum values: "packed", "unpacked", "template"drasi-project/reaction-eventbridgeto the images loaded into Kind clusterE2E Test Infrastructure
09-eventbridge-handlebars-scenariotest suite@aws-sdk/client-eventbridgedependency for test assertionsKey Features
added,updated,deletedsectionstemplateproperty for the Handlebars template and optionalmetadatafor CloudEvent extension attributesserviceUrlproperty{{after}}for added,{{before}}and{{after}}for updated,{{before}}for deletedExample Configuration
Security Summary
Type of change
Fixes: #issue_number
Original prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.