Skip to content

Commit

Permalink
Added slow span based on region
Browse files Browse the repository at this point in the history
Added a randomly assigned region tag to the spans in get_product_list and then chose one (San Francisco) to become 5 sec long if the scenario is triggered
  • Loading branch information
jdahmen-splunk committed Jan 28, 2025
1 parent 694ccce commit 8a3ed58
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/flagd/demo.flagd.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,15 @@
},
"defaultVariant": "off"
},
"slowRecommendationRegionSpan": {
"description": "Create a slow 5sec span in the recommendation service (get_product_list) for the San Francisco region",
"state": "ENABLED",
"variants": {
"on": true,
"off": false
},
"defaultVariant": "on"
},
"adManualGc": {
"description": "Triggers full manual garbage collections in the ad service",
"state": "ENABLED",
Expand Down
16 changes: 16 additions & 0 deletions src/recommendation/recommendation_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,19 @@ def Watch(self, request, context):


def get_product_list(request_product_ids):

#regions to randomly assign
regions = ["San Francisco", "New York", "London", "Frankfurt", "Mumbai", "Tokyo", "Singapore", "Sydney"]

global first_run
global cached_ids
with tracer.start_as_current_span("get_product_list") as span:
max_responses = 5

#Randomly assign a region tag value
rand_region = regions[random.randint(0, len(regions) - 1)]
span.set_attribute("app.recommendation.region", rand_region)

# Formulate the list of characters to list of strings
request_product_ids_str = ''.join(request_product_ids)
request_product_ids = request_product_ids_str.split(',')
Expand All @@ -84,6 +92,14 @@ def get_product_list(request_product_ids):
else:
span.set_attribute("app.recommendation.slow_span_enabled", False)

#Feature flag Scenario - Slow Region Span
if check_feature_flag("slowRecommendationRegionSpan") and rand_region == "San Francisco":
time.sleep(5)
logger.info("get_product_list: slow region span enabled")
span.set_attribute("app.recommendation.slow_region_span_enabled", True)
else:
span.set_attribute("app.recommendation.slow_region_span_enabled", False)

# Feature flag scenario - Cache Leak
if check_feature_flag("recommendationCacheFailure"):
span.set_attribute("app.recommendation.cache_enabled", True)
Expand Down

0 comments on commit 8a3ed58

Please sign in to comment.