From cf72b62e69743229de5819c942c6afdd1f06b838 Mon Sep 17 00:00:00 2001 From: Borna Vincek Date: Mon, 18 Mar 2024 13:48:40 +0100 Subject: [PATCH 1/3] [loadgenerator] added loadgeneratorFloodHomepage flagd --- docker-compose.minimal.yml | 1 + docker-compose.yml | 1 + src/flagd/demo.flagd.json | 9 +++++++++ src/loadgenerator/locustfile.py | 18 ++++++++++++++++++ src/loadgenerator/requirements.txt | 4 +++- 5 files changed, 32 insertions(+), 1 deletion(-) diff --git a/docker-compose.minimal.yml b/docker-compose.minimal.yml index 88408a9434..36a60666ba 100644 --- a/docker-compose.minimal.yml +++ b/docker-compose.minimal.yml @@ -331,6 +331,7 @@ services: - OTEL_RESOURCE_ATTRIBUTES - OTEL_SERVICE_NAME=loadgenerator - PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=python + - FLAGD_HOST depends_on: frontend: condition: service_started diff --git a/docker-compose.yml b/docker-compose.yml index d36fe64de3..9e21adaa02 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -412,6 +412,7 @@ services: - OTEL_RESOURCE_ATTRIBUTES - OTEL_SERVICE_NAME=loadgenerator - PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=python + - FLAGD_HOST depends_on: frontend: condition: service_started diff --git a/src/flagd/demo.flagd.json b/src/flagd/demo.flagd.json index 26c2c71b94..6d2dac0d83 100644 --- a/src/flagd/demo.flagd.json +++ b/src/flagd/demo.flagd.json @@ -78,6 +78,15 @@ "off": false }, "defaultVariant": "off" + }, + "loadgeneratorFloodHomepage": { + "description": "Flood the frontend with a large amount of requests.", + "state": "ENABLED", + "variants": { + "on": 100, + "off": 0 + }, + "defaultVariant": "off" } } } diff --git a/src/loadgenerator/locustfile.py b/src/loadgenerator/locustfile.py index 9375df2d00..77c33796c8 100644 --- a/src/loadgenerator/locustfile.py +++ b/src/loadgenerator/locustfile.py @@ -33,6 +33,11 @@ from opentelemetry.sdk._logs import LoggerProvider, LoggingHandler from opentelemetry.sdk._logs.export import BatchLogRecordProcessor from opentelemetry.sdk.resources import Resource + +from openfeature import api +from openfeature.contrib.provider.flagd import FlagdProvider +from openfeature.exception import OpenFeatureError + from playwright.async_api import Route, Request logger_provider = LoggerProvider(resource=Resource.create( @@ -64,6 +69,14 @@ URLLib3Instrumentor().instrument() logging.info("Instrumentation complete") +# Initialize Flagd provider +api.set_provider(FlagdProvider(host=os.environ.get('FLAGD_HOST', 'flagd'), port=os.environ.get('FLAGD_PORT', 8013))) + +def get_flagd_value(FlagName): + # Initialize OpenFeature + client = api.get_client() + return client.get_integer_value(FlagName, 0) + categories = [ "binoculars", "telescopes", @@ -153,6 +166,11 @@ def checkout_multi(self): checkout_person["userId"] = user self.client.post("/api/checkout", json=checkout_person) + @task(5) + def flood_home(self): + for _ in range(0, get_flagd_value("loadgeneratorFloodHomepage")): + self.client.get("/") + def on_start(self): ctx = baggage.set_baggage("synthetic_request", "true") context.attach(ctx) diff --git a/src/loadgenerator/requirements.txt b/src/loadgenerator/requirements.txt index 88aba3fdc3..2c7f3601e1 100644 --- a/src/loadgenerator/requirements.txt +++ b/src/loadgenerator/requirements.txt @@ -30,7 +30,9 @@ opentelemetry-proto==1.23.0 opentelemetry-sdk==1.23.0 opentelemetry-semantic-conventions==0.44b0 opentelemetry-util-http==0.44b0 -protobuf==4.25.0 +openfeature-sdk==0.5.0 +openfeature-provider-flagd==0.1.3 +protobuf==4.25.2 psutil==5.9.6 pyzmq==25.1.1 requests==2.31.0 From 8a3bbfdd71f4d27db74004d79ea6c46478929a9f Mon Sep 17 00:00:00 2001 From: Borna Vincek Date: Wed, 27 Mar 2024 12:57:09 +0100 Subject: [PATCH 2/3] CHANGELOG --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index bb45909690..829eec4125 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -61,6 +61,9 @@ the release. ([#1473](https://github.com/open-telemetry/opentelemetry-demo/pull/1473)) * [Imageprovider] Create Nginx service to host images, add instrumentation to it ([#1462](https://github.com/open-telemetry/opentelemetry-demo/pull/1462)) +* [loadgenerator] added loadgeneratorFloodHomepage flagd + ([#1486](https://github.com/open-telemetry/opentelemetry-demo/pull/1486)) + ## 1.8.0 From 7126e96b83f236689fc72aa3fa03a22030e6d59a Mon Sep 17 00:00:00 2001 From: Borna Vincek Date: Mon, 8 Apr 2024 14:44:48 +0200 Subject: [PATCH 3/3] Added FLAGD_PORT and depends on the dockercompose --- CHANGELOG.md | 1 - docker-compose.minimal.yml | 3 +++ docker-compose.yml | 3 +++ 3 files changed, 6 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 829eec4125..7e0b49e479 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -64,7 +64,6 @@ the release. * [loadgenerator] added loadgeneratorFloodHomepage flagd ([#1486](https://github.com/open-telemetry/opentelemetry-demo/pull/1486)) - ## 1.8.0 * [grafana] update grafana to 10.2.3 diff --git a/docker-compose.minimal.yml b/docker-compose.minimal.yml index 36a60666ba..1a5c211672 100644 --- a/docker-compose.minimal.yml +++ b/docker-compose.minimal.yml @@ -332,9 +332,12 @@ services: - OTEL_SERVICE_NAME=loadgenerator - PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=python - FLAGD_HOST + - FLAGD_PORT depends_on: frontend: condition: service_started + flagd: + condition: service_started logging: *logging # Payment service diff --git a/docker-compose.yml b/docker-compose.yml index 9e21adaa02..c52c34d37a 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -413,9 +413,12 @@ services: - OTEL_SERVICE_NAME=loadgenerator - PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=python - FLAGD_HOST + - FLAGD_PORT depends_on: frontend: condition: service_started + flagd: + condition: service_started logging: *logging # Payment service