Skip to content

Commit

Permalink
[loadgenerator] added loadgeneratorFloodHomepage flagd (open-telemetr…
Browse files Browse the repository at this point in the history
…y#1486)

* [loadgenerator] added loadgeneratorFloodHomepage flagd

* CHANGELOG

* Added FLAGD_PORT and depends on the dockercompose
  • Loading branch information
bornav authored and AlexPSplunk committed Jul 10, 2024
1 parent 1310c46 commit 99841bf
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 4 additions & 0 deletions docker-compose.minimal.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions src/flagd/demo.flagd.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
}
}
18 changes: 18 additions & 0 deletions src/loadgenerator/locustfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 3 additions & 1 deletion src/loadgenerator/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 99841bf

Please sign in to comment.