-
-
Notifications
You must be signed in to change notification settings - Fork 146
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Added kinesis exporter and respective tests. (#2575)
* Kinesis exporter basic implementation * This fixes issue #2557 Kinesis exporter implementation with tests * Added example how to export data from kinesis * Kinesis exporter page * Added relay configuration Changed partition key field to be calculatable value based on event data with default lambda resolving into value 'default' Fixed tests improved docs * Improved kinesisexporter package code test coverage to 84.5% Added workaround to skip sending empty dataset * comment fix * Revert "comment fix" This reverts commit cb8faea. * only test
- Loading branch information
Showing
15 changed files
with
775 additions
and
4 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,4 +42,7 @@ go-feature-flag-relay-proxy/ | |
node_modules/ | ||
oryxBuildBinary | ||
|
||
./.sonarlint | ||
./.sonarlint | ||
|
||
# Localstack cache | ||
volume |
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
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 |
---|---|---|
@@ -0,0 +1,47 @@ | ||
# Kafka exporter example | ||
|
||
This example contains everything you need to export the usage of your flag to **`AWS Kinesis`**. | ||
|
||
## How to setup the example | ||
_All commands should be run in the root level of the repository._ | ||
|
||
1. Start a kafka server by running: | ||
|
||
```shell | ||
docker-compose -f examples/data_export_kinesis/docker-compose.yml up | ||
``` | ||
|
||
2. Create python virtualenv & Install awslocal | ||
```shell | ||
mkvirtualenv go-features-flag-kinesis | ||
# or activate existent | ||
workon go-features-flag-kinesis | ||
pip install awscli awscli-local | ||
``` | ||
|
||
2. Create a topic in Kinesis: | ||
|
||
```shell | ||
awslocal kinesis create-stream --stream-name test-stream --region us-east-1 | ||
``` | ||
|
||
3. Update dependencies: | ||
|
||
```shell | ||
make vendor | ||
``` | ||
|
||
4. Run the example application: | ||
|
||
```shell | ||
go run ./examples/data_export_kinesis/main.go | ||
``` | ||
_If you check the logs, you should see the events being sent 1 by 1 to kinesis._ | ||
|
||
5. Read the items in the topic: | ||
|
||
```shell | ||
SHARD_ITERATOR=$(awslocal kinesis get-shard-iterator --shard-id shardId-000000000000 --shard-iterator-type TRIM_HORIZON --stream-name test-stream --query 'ShardIterator' --region us-east-1) | ||
|
||
awslocal kinesis get-records --shard-iterator $SHARD_ITERATOR --region us-east-1 | ||
``` |
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 @@ | ||
version: '2' | ||
services: | ||
localstack: | ||
container_name: "${LOCALSTACK_DOCKER_NAME:-localstack-main}" | ||
image: localstack/localstack | ||
ports: | ||
- "127.0.0.1:4566:4566" # LocalStack Gateway | ||
- "127.0.0.1:4510-4559:4510-4559" # external services port range | ||
environment: | ||
- DEBUG=${DEBUG:-0} | ||
volumes: | ||
- "${LOCALSTACK_VOLUME_DIR:-./volume}:/var/lib/localstack" | ||
- "/var/run/docker.sock:/var/run/docker.sock" |
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,22 @@ | ||
new-admin-access: | ||
variations: | ||
default_var: false | ||
false_var: false | ||
true_var: true | ||
defaultRule: | ||
percentage: | ||
false_var: 70 | ||
true_var: 30 | ||
|
||
flag-only-for-admin: | ||
variations: | ||
default_var: false | ||
false_var: false | ||
true_var: true | ||
targeting: | ||
- query: admin eq true | ||
percentage: | ||
false_var: 0 | ||
true_var: 100 | ||
defaultRule: | ||
variation: default_var |
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,82 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"log" | ||
"log/slog" | ||
"time" | ||
|
||
"github.com/aws/aws-sdk-go-v2/config" | ||
"github.com/aws/aws-sdk-go-v2/credentials" | ||
|
||
kex "github.com/thomaspoignant/go-feature-flag/exporter/kinesisexporter" | ||
|
||
ffclient "github.com/thomaspoignant/go-feature-flag" | ||
"github.com/thomaspoignant/go-feature-flag/ffcontext" | ||
"github.com/thomaspoignant/go-feature-flag/retriever/fileretriever" | ||
) | ||
|
||
func main() { | ||
/* | ||
1. Start a kinesis server by running `docker-compose -f examples/data_export_kinesis/docker-compose.yml up` | ||
2. Create a stream: docker exec $(docker ps | grep cp-kinesis | awk '{print $1}') kafka-topics --create --topic go-feature-flag-events --bootstrap-server localhost:9092 | ||
3. Run this example | ||
-> if you check the logs, you should see the events being sent 1 by 1 to kafka. | ||
4. Read the items in the topic: docker exec $(docker ps | grep cp-kafka | awk '{print $1}') kafka-console-consumer --bootstrap-server localhost:9092 --topic go-feature-flag-events --from-beginning | ||
*/ | ||
|
||
config, err := config.LoadDefaultConfig( | ||
context.Background(), | ||
config.WithCredentialsProvider( | ||
credentials.NewStaticCredentialsProvider("test", "test", ""), | ||
), | ||
config.WithRegion("us-east-1"), | ||
config.WithBaseEndpoint("http://localhost:4566"), | ||
) | ||
|
||
if err != nil { | ||
panic("Can't instantiate localstack connection credentials") | ||
} | ||
|
||
err = ffclient.Init(ffclient.Config{ | ||
PollingInterval: 10 * time.Second, | ||
LeveledLogger: slog.Default(), | ||
Context: context.Background(), | ||
Retriever: &fileretriever.Retriever{ | ||
Path: "examples/data_export_kinesis/flags.goff.yaml", | ||
}, | ||
DataExporter: ffclient.DataExporter{ | ||
FlushInterval: 1 * time.Second, | ||
MaxEventInMemory: 100, | ||
Exporter: &kex.Exporter{ | ||
Settings: kex.NewSettings( | ||
kex.WithStreamName("test-stream"), | ||
kex.WithExplicitHashKey("0"), | ||
), | ||
AwsConfig: &config, | ||
}, | ||
}, | ||
}) | ||
|
||
// Check init errors. | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
// defer closing ffclient | ||
defer ffclient.Close() | ||
|
||
// create users | ||
user1 := ffcontext. | ||
NewEvaluationContextBuilder("aea2fdc1-b9a0-417a-b707-0c9083de68e3"). | ||
AddCustom("anonymous", true). | ||
Build() | ||
user2 := ffcontext.NewEvaluationContext("332460b9-a8aa-4f7a-bc5d-9cc33632df9a") | ||
|
||
_, _ = ffclient.BoolVariation("new-admin-access", user1, false) | ||
_, _ = ffclient.BoolVariation("new-admin-access", user2, false) | ||
_, _ = ffclient.StringVariation("unknown-flag", user1, "defaultValue") | ||
_, _ = ffclient.JSONVariation("unknown-flag-2", user1, map[string]interface{}{"test": "toto"}) | ||
_, _ = ffclient.BoolVariation("new-admin-access", user1, false) | ||
_, _ = ffclient.BoolVariation("new-admin-access", user2, false) | ||
|
||
} |
Oops, something went wrong.