From c921c1e3095f89d4b1402c254d5c98d69ffe2cf4 Mon Sep 17 00:00:00 2001 From: Michael Beemer Date: Mon, 8 Jul 2024 10:04:36 +0200 Subject: [PATCH] Simplify error scenario logic (#1657) * remove fractional config from rule definition Signed-off-by: Michael Beemer * add random failure logic to ad service Signed-off-by: Michael Beemer * add random failure logic to cart service Signed-off-by: Michael Beemer --------- Signed-off-by: Michael Beemer --- .../src/main/java/oteldemo/AdService.java | 3 +- src/cartservice/src/services/CartService.cs | 5 ++- src/flagd/demo.flagd.json | 32 ++++++++----------- 3 files changed, 19 insertions(+), 21 deletions(-) diff --git a/src/adservice/src/main/java/oteldemo/AdService.java b/src/adservice/src/main/java/oteldemo/AdService.java index 5f03996896..c55b663bf1 100644 --- a/src/adservice/src/main/java/oteldemo/AdService.java +++ b/src/adservice/src/main/java/oteldemo/AdService.java @@ -201,7 +201,8 @@ public void getAds(AdRequest req, StreamObserver responseObserver) { Attributes.of( adRequestTypeKey, adRequestType.name(), adResponseTypeKey, adResponseType.name())); - if (ffClient.getBooleanValue(ADSERVICE_FAILURE, false, evaluationContext)) { + // Throw 1/10 of the time to simulate a failure when the feature flag is enabled + if (ffClient.getBooleanValue(ADSERVICE_FAILURE, false, evaluationContext) && random.nextInt(10) == 0) { throw new StatusRuntimeException(Status.UNAVAILABLE); } diff --git a/src/cartservice/src/services/CartService.cs b/src/cartservice/src/services/CartService.cs index e20bb86d6b..ff0b32153a 100644 --- a/src/cartservice/src/services/CartService.cs +++ b/src/cartservice/src/services/CartService.cs @@ -2,6 +2,7 @@ // SPDX-License-Identifier: Apache-2.0 using System.Diagnostics; using System.Threading.Tasks; +using System; using Grpc.Core; using OpenTelemetry.Trace; using cartservice.cartstore; @@ -13,6 +14,7 @@ namespace cartservice.services; public class CartService : Oteldemo.CartService.CartServiceBase { private static readonly Empty Empty = new(); + private readonly Random random = new Random(); private readonly ICartStore _badCartStore; private readonly ICartStore _cartStore; private readonly IFeatureClient _featureFlagHelper; @@ -60,7 +62,8 @@ public override async Task EmptyCart(EmptyCartRequest request, ServerCall try { - if (await _featureFlagHelper.GetBooleanValue("cartServiceFailure", false)) + // Throw 1/10 of the time to simulate a failure when the feature flag is enabled + if (await _featureFlagHelper.GetBooleanValue("cartServiceFailure", false) && random.Next(10) == 0) { await _badCartStore.EmptyCartAsync(request.UserId); } diff --git a/src/flagd/demo.flagd.json b/src/flagd/demo.flagd.json index 626d02cfcf..2d46891ef2 100644 --- a/src/flagd/demo.flagd.json +++ b/src/flagd/demo.flagd.json @@ -23,19 +23,19 @@ "description": "Triggers full manual garbage collections in the ad service", "state": "ENABLED", "variants": { - "on": true, - "off": false - }, - "defaultVariant": "off" + "on": true, + "off": false + }, + "defaultVariant": "off" }, "adServiceHighCpu": { "description": "Triggers high cpu load in the ad service", "state": "ENABLED", "variants": { - "on": true, - "off": false - }, - "defaultVariant": "off" + "on": true, + "off": false + }, + "defaultVariant": "off" }, "adServiceFailure": { "description": "Fail ad service", @@ -44,22 +44,16 @@ "on": true, "off": false }, - "defaultVariant": "off", - "targeting": { - "fractional": [ - ["on", 10], - ["off", 90] - ] - } + "defaultVariant": "off" }, "kafkaQueueProblems": { "description": "Overloads Kafka queue while simultaneously introducing a consumer side delay leading to a lag spike", "state": "ENABLED", "variants": { - "on": 100, - "off": 0 - }, - "defaultVariant": "off" + "on": 100, + "off": 0 + }, + "defaultVariant": "off" }, "cartServiceFailure": { "description": "Fail cart service",