Skip to content

Commit

Permalink
Added db timeout error
Browse files Browse the repository at this point in the history
TODO: add api and conn errors
  • Loading branch information
jdahmen-splunk committed Jan 28, 2025
1 parent 8a3ed58 commit c8d79e0
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/flagd/demo.flagd.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,17 @@
},
"defaultVariant": "off"
},
"recommendationErrors": {
"description": "Introduce different types of errors in the recommendation service 20% of the time",
"state": "ENABLED",
"variants": {
"Database timeout": "db_timeout",
"Database Unable to connect": "db_conn_err",
"API fetch error": "api_err",
"off": "off"
},
"defaultVariant": "Database timeout"
},
"slowRecommendationRegionSpan": {
"description": "Create a slow 5sec span in the recommendation service (get_product_list) for the San Francisco region",
"state": "ENABLED",
Expand Down
17 changes: 17 additions & 0 deletions src/recommendation/recommendation_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,23 @@ def get_product_list(request_product_ids):
cat_response = product_catalog_stub.ListProducts(demo_pb2.Empty())
product_ids = [x.id for x in cat_response.products]

#Feature flag scenario - recommendationErrors
errs_enabled_value = api.get_client().get_string_value("recommendationErrors", "not found")
span.set_attribute("app.recommendation.recommendation_errs_enabled", errs_enabled_value)
random_value = random.random()
if errs_enabled_value is not "off" and random_value < 0.2:
if errs_enabled_value == "db_timeout":
time.sleep(10)
raise TimeoutError("Request to the database timed out")
elif errs_enabled_value == "db_conn_err":
pass
elif errs_enabled_value == "api_err":
pass
else:
pass



span.set_attribute("app.products.count", len(product_ids))

# Create a filtered list of products excluding the products received as input
Expand Down

0 comments on commit c8d79e0

Please sign in to comment.