From c8d79e0897be1fbf7a96fe62ae5482e9c3665181 Mon Sep 17 00:00:00 2001 From: jdahmenlemur <142763346+jdahmen-splunk@users.noreply.github.com> Date: Mon, 27 Jan 2025 20:46:03 -0800 Subject: [PATCH] Added db timeout error TODO: add api and conn errors --- src/flagd/demo.flagd.json | 11 +++++++++++ src/recommendation/recommendation_server.py | 17 +++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/src/flagd/demo.flagd.json b/src/flagd/demo.flagd.json index 26884a8dfc..a4b744af08 100644 --- a/src/flagd/demo.flagd.json +++ b/src/flagd/demo.flagd.json @@ -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", diff --git a/src/recommendation/recommendation_server.py b/src/recommendation/recommendation_server.py index 0263bb1098..1e4a4c5474 100644 --- a/src/recommendation/recommendation_server.py +++ b/src/recommendation/recommendation_server.py @@ -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