diff --git a/CHANGELOG.md b/CHANGELOG.md index bb45909690..7e0b49e479 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -61,6 +61,8 @@ 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 diff --git a/docker-compose.minimal.yml b/docker-compose.minimal.yml index 88408a9434..1a5c211672 100644 --- a/docker-compose.minimal.yml +++ b/docker-compose.minimal.yml @@ -331,9 +331,13 @@ services: - OTEL_RESOURCE_ATTRIBUTES - 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 d36fe64de3..c52c34d37a 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -412,9 +412,13 @@ services: - OTEL_RESOURCE_ATTRIBUTES - 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/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