-
Notifications
You must be signed in to change notification settings - Fork 51
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
Snowbridge v3 #1068
Open
colmsnowplow
wants to merge
23
commits into
main
Choose a base branch
from
snowbridge-v3
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Snowbridge v3 #1068
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
14bf4e1
Remove config file workaround from testing guide
colmsnowplow a267214
Add a page for jqFilter
colmsnowplow 077a6fb
Add a page for jq transformation
colmsnowplow 72c56a5
Update gtm ss Preview transformation
colmsnowplow 872def5
patch typo in GTM SS transformation
colmsnowplow fef548e
JQ filter - specify behaviour on non-boolean result
colmsnowplow 329bc73
Add reusable jq helpers blocks
colmsnowplow 0013837
Move helpers block so the examples make sense
colmsnowplow afd53fa
wip update http docs
colmsnowplow 75957cb
Add retry configuration section
colmsnowplow b69d5e4
Add http retry information
colmsnowplow 75634ce
Update failure model concepts section
colmsnowplow 5b1a225
Make configuration section headings more consistent
colmsnowplow f8336c4
Patch broken config links
colmsnowplow c1109ca
component version bump
colmsnowplow 2b3bb2a
Update docs/destinations/forwarding-events/snowbridge/concepts/failur…
colmsnowplow 43a5d67
More accurate description of msg failed metric
colmsnowplow 780159c
Remove inaccurate sentence
colmsnowplow 190b383
Remove copypaste error
colmsnowplow 9ced96f
Tweak metric explanation for accuracy
colmsnowplow 4480122
ADd jq playground, and make jq description a reusable block
colmsnowplow 083e1ca
Patch error
colmsnowplow d56eb16
Tweaks for clarity
colmsnowplow File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
26 changes: 26 additions & 0 deletions
26
docs/destinations/forwarding-events/snowbridge/configuration/retries/index.md
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,26 @@ | ||
--- | ||
title: "Retries (beta)" | ||
description: "Configure retry behaviour." | ||
--- | ||
|
||
:::note | ||
This feature was added in version 3.0.0 | ||
|
||
This feature is in beta status because we may make breaking changes in future versions. | ||
::: | ||
|
||
This feature allows you to configure the retry behaviour when the target encounters a failure in sending the data. There are two types of failure you can define: | ||
|
||
A transient failure is a failure which we expect to succeed again on retry. For example some temporary network error, or when we encounter throttling. Typically you would configure a short backoff for this type of failure. When we encounter a transient failure, we keep processing the rest of the data as normal, under the expectation that everyhting is operating as normal. The failed data is retried after a backoff. | ||
|
||
A setup failure is one which we don't expect to be immediately resolved, for example an incorrect address, or an invalid API Key. Typically you would configue a long backoff for this type of failure, under the assumption that the issue needs to be fixed with either a configuration change or a change to the target itself (eg. permissions need to be granted). Setup errors will be retried 5 times, before the app crashes. | ||
|
||
As of v3.0.0, only the http target can be configured to return setup errors, via the response rules feature - configuration details for response rules can be found in [the http target configuration section](/docs/destinations/forwarding-events/snowbridge/configuration/targets/http/index.md). For all other targets, all errors returned will be considered transient, and behaviour can be configured using the `tranisent` block of the retry configuration. | ||
|
||
Retries will be attempted on an exponential backoff - in other words, on each subsequent failure, the backoff time will double. You can configure transient failures to retry indefinitely by setting `max_attempts` to 0. | ||
|
||
## Configuration options | ||
|
||
```hcl reference | ||
https://github.com/snowplow/snowbridge/blob/master/assets/docs/configuration/retry-example.hcl | ||
``` |
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 | ||||
---|---|---|---|---|---|---|
|
@@ -17,6 +17,98 @@ Snowbridge supports sending authorized requests to OAuth2 - compliant HTTP targe | |||||
|
||||||
Like in the case of basic authentication, we recommend using environment variables for sensitive values. | ||||||
|
||||||
## Dynamic Headers | ||||||
|
||||||
:::note | ||||||
This feature was added in version 2.3.0 | ||||||
::: | ||||||
|
||||||
When enabled, the dynamic headers attaches a header to the data according to what your transformation provides in the `HTTPHeaders` field of `engineProtocol`. Data is batched according to the dynamic header value before requests are sent. | ||||||
|
||||||
## Request templating | ||||||
|
||||||
:::note | ||||||
This feature was added in version 3.0.0 | ||||||
::: | ||||||
|
||||||
This feature allows you to provide a [Golang text template](https://pkg.go.dev/text/template) to construct a request body from a batch of data. This feature should be useful in constructing requests to send to an API, for example. | ||||||
|
||||||
Input data must be valid JSON, any message whose that fails to be marshaled to JSON will be treated as invalid and sent to the failure target. Equally, if an attempt to template a batch of data results in an error, then all messages in the batch will be considred invalid and sent to the failuret target. | ||||||
|
||||||
Where the dynamic headers feature is enabled, data is split into batches according to the provided header value, and the templater will operate on each batch separately. | ||||||
|
||||||
### Helper functions | ||||||
|
||||||
In addition to all base functions available in the Go text/template package, the following custom functions are available for convenience: | ||||||
|
||||||
`prettyPrint` - Because the input to the templater is a Go data structure, simply providing a reference to an object field won't produce a JSON object in the output of the template. `prettyPrint` converts the data to prettified JSON (by unmarshaling to json). Use it wherever you expect a JSON object in the output. This is compatible with any data type, but it shouldn't be necessary if the data is not an object. | ||||||
|
||||||
`env` - Allows you to set and refer to an env var in your template. Use it when your request body must contain sensitive data, for example an API key. | ||||||
|
||||||
### Template example | ||||||
|
||||||
The following example provides an API key via environment variable, and iterates the batch to provide JSON-formatted data one by one into a new key, inserting a comma before all but the first event. | ||||||
|
||||||
```hcl reference | ||||||
https://github.com/snowplow/snowbridge/blob/master/assets/docs/configuration/targets/http-template-full-example.file | ||||||
``` | ||||||
|
||||||
### Default behaviour, and breaking changes in v3 | ||||||
|
||||||
Where no template is configured, the POST request body will contain an array of JSON containing the data for the whole batch. Data must be valid JSON or it will be considered invalid and sent to the failure target. | ||||||
|
||||||
Note that this is a breaking change to the pre-v3 default behaviour, in two ways: | ||||||
|
||||||
1. Previously to v3, we sent data one request per message | ||||||
|
||||||
This means that where no template is provided, request bodies will be arrays of JSON rather than individual JSON objects. | ||||||
|
||||||
For example, pre-v3, a request body might look like this: | ||||||
|
||||||
``` | ||||||
{"foo": "bar"} | ||||||
``` | ||||||
|
||||||
But it will now look like this: | ||||||
|
||||||
``` | ||||||
[{"foo": "bar"}] | ||||||
``` | ||||||
|
||||||
If you need to preserve the previous behaviour (as long as your data is valid JSON), you can set `request_max_messages` to 1, and provide this template: | ||||||
|
||||||
```go reference | ||||||
https://github.com/snowplow/snowbridge/blob/master/assets/docs/configuration/targets/http-template-unwrap-example.file | ||||||
``` | ||||||
|
||||||
2. Non-JSON data is not supported | ||||||
|
||||||
While the intention was never to support non-JSON data, previously to v3 the request body was simply populated with whatever bytes were found in the message data, regardless of whether it is valid JSON. | ||||||
|
||||||
From v3 on, only valid JSON will work, otherwise the message will be considered invalid and sent to the failure target. | ||||||
|
||||||
## Response rules (beta) | ||||||
|
||||||
:::note | ||||||
This feature was added in version 3.0.0 | ||||||
|
||||||
This feature is in beta status because we may make breaking changes in future versions. | ||||||
::: | ||||||
|
||||||
Response rules allow you to configure how the app deals with failures in sending the data. You can configure a response code and an optional string match on the response body to determine how a failure response is handled. Response codes between 200 and 299 are considered successful, and are not handled by this feature. | ||||||
|
||||||
There are three categories of failure: | ||||||
|
||||||
`invalid` means that the data is considered incompatible with the target for some reason. For example, you may have defined a mapping for a given API, but the event being processed happens to have null data for a field that is required by the API. In this instance, retrying the data won't fix the issue, so you would configure an invalid response rule, which identifies responses which indicate this scenario. | ||||||
|
||||||
Data that matches an invalid response rule is sent to the failure target. | ||||||
|
||||||
`setup` means that this error is not retryable, but is something which can only be resolved by a change in configuration or a change to the target. An example of this is an authentication failure - retrying will fix the issue, the resolution is to grant the appropriate permissions, or provide the correct API key. | ||||||
|
||||||
Data that matches a setup response rule is handled by a retey as determined in the `setup` configuration block of [retry configuration](/docs/destinations/forwarding-events/snowbridge/configuration/retries/index.md). | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
|
||||||
`transient` errors are everything else - we assume that the issue is temporary and retrying will resolve the problem. An example of this is being throttled by an API because too much data is being sent at once. There is no explicit configuration for transient - rather, anything that is not configured as one of the other types is considered transient. | ||||||
|
||||||
## Configuration options | ||||||
|
||||||
Here is an example of the minimum required configuration: | ||||||
|
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
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
41 changes: 41 additions & 0 deletions
41
...ations/forwarding-events/snowbridge/configuration/transformations/builtin/jq.md
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,41 @@ | ||
# jq | ||
|
||
:::note | ||
This transformation was added in version 3.0.0 | ||
::: | ||
|
||
```mdx-code-block | ||
import JQDescriptionSharedBlock from "./reusable/_jqDescription.md" | ||
|
||
<JQDescriptionSharedBlock/> | ||
``` | ||
|
||
`jq` runs a jq command on the message data, and outputs the result of the command. While jq supports multi-element results, commands must output only a single element - this single element can be an array data type. | ||
|
||
If the provided jq command results in an error, the message will be considred invalid, and will be sent to the failure target. | ||
|
||
The minimal example here returns the input data as a single element array, and the full example maps the data to a new data structure. | ||
|
||
The jq transformation will remove any keys with null values from the data. | ||
|
||
## Configuration options | ||
|
||
Minimal configuration: | ||
|
||
```hcl reference | ||
https://github.com/snowplow/snowbridge/blob/master/assets/docs/configuration/transformations/builtin/jq-minimal-example.hcl | ||
``` | ||
|
||
Every configuration option: | ||
|
||
```hcl reference | ||
https://github.com/snowplow/snowbridge/blob/master/assets/docs/configuration/transformations/builtin/jq-full-example.hcl | ||
``` | ||
|
||
## Helper functions | ||
|
||
```mdx-code-block | ||
import JQHelpersSharedBlock from "./reusable/_jqHelpers.md" | ||
|
||
<JQHelpersSharedBlock/> | ||
``` |
39 changes: 39 additions & 0 deletions
39
.../forwarding-events/snowbridge/configuration/transformations/builtin/jqFilter.md
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,39 @@ | ||
# jqFilter | ||
|
||
:::note | ||
This transformation was added in version 3.0.0 | ||
::: | ||
|
||
```mdx-code-block | ||
import JQDescriptionSharedBlock from "./reusable/_jqDescription.md" | ||
|
||
<JQDescriptionSharedBlock/> | ||
``` | ||
|
||
`jqFilter` filters messages based on the output of a jq command which is run against the data. The provided command must return a boolean result. `false` filters the message out, `true` keeps it. | ||
|
||
If the provided jq command returns a non-boolean value error, or results in an error, then the message will be considred invalid, and will be sent to the failure target. | ||
|
||
This example filters out all data that doesn't have an `app_id` key. | ||
|
||
## Configuration options | ||
|
||
Minimal configuration: | ||
|
||
```hcl reference | ||
https://github.com/snowplow/snowbridge/blob/master/assets/docs/configuration/transformations/builtin/jqFilter-minimal-example.hcl | ||
``` | ||
|
||
Every configuration option: | ||
|
||
```hcl reference | ||
https://github.com/snowplow/snowbridge/blob/master/assets/docs/configuration/transformations/builtin/jqFilter-full-example.hcl | ||
``` | ||
|
||
## Helper Functions | ||
|
||
```mdx-code-block | ||
import JQHelpersSharedBlock from "./reusable/_jqHelpers.md" | ||
|
||
<JQHelpersSharedBlock/> | ||
``` |
5 changes: 5 additions & 0 deletions
5
...nts/snowbridge/configuration/transformations/builtin/reusable/_jqDescription.md
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,5 @@ | ||
[jq](https://github.com/jqlang/jq) is a lightweight and flexible command-line JSON processor akin to sed,awk,grep, and friends for JSON data. Snowbridge's jq features utilise the [gojq](https://github.com/itchyny/gojq) package, which is a pure go implementation of jq. jq is Turing complete, so these features allow you to configure arbitrary logic upon json data structures. | ||
|
||
jq supports formatting values, mathematical operations, boolean comparisons, regex matches, and many more useful features. To get started with jq command, see the [tutorial](https://jqlang.github.io/jq/tutorial/), and [full reference manual](https://jqlang.github.io/jq/manual/). [This open-source jq playground tool](https://jqplay.org/) may also be helpful. | ||
|
||
For most use cases, you are unlikely to meaningfully encounter them, but note that there are [some small differences](https://github.com/itchyny/gojq?tab=readme-ov-file#difference-to-jq) between jq and gojq. |
13 changes: 13 additions & 0 deletions
13
...-events/snowbridge/configuration/transformations/builtin/reusable/_jqHelpers.md
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,13 @@ | ||
In addition to the native functions available in the jq language, the following helper functions are available for use in a jq query: | ||
|
||
`epoch` - converts a time.Time to an epoch in seconds, as integer type. jq's native timestamp based functions expect integer input, but the Snowplow Analytics SDK provides base level timestamps as time.Time. This function can be chained with jq native functions to get past this limitation. For example: | ||
|
||
``` | ||
{ foo: .collector_tstamp | epoch | todateiso8601 } | ||
``` | ||
|
||
`epochMillis` - converts a time.Time to an epoch in milliseconds, as unsigned integer type. Because of how integers are handled in Go, unsigned integers aren't compatible with jq's native timestamp functions, so the `epoch` function truncates to seconds, and the `epochMillis` function exists in case milliseconds are needed. This function cannot be chained with native jq functions, but where milliseconds matter for a value, use this function. | ||
|
||
``` | ||
{ foo: .collector_tstamp | epochMillis } | ||
``` |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.