Skip to content

Commit 14e7f8f

Browse files
authored
Simplify error scenario logic (#1657)
* remove fractional config from rule definition Signed-off-by: Michael Beemer <beeme1mr@users.noreply.github.com> * add random failure logic to ad service Signed-off-by: Michael Beemer <beeme1mr@users.noreply.github.com> * add random failure logic to cart service Signed-off-by: Michael Beemer <beeme1mr@users.noreply.github.com> --------- Signed-off-by: Michael Beemer <beeme1mr@users.noreply.github.com>
1 parent 9dad087 commit 14e7f8f

File tree

3 files changed

+19
-21
lines changed

3 files changed

+19
-21
lines changed

src/adservice/src/main/java/oteldemo/AdService.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,8 @@ public void getAds(AdRequest req, StreamObserver<AdResponse> responseObserver) {
201201
Attributes.of(
202202
adRequestTypeKey, adRequestType.name(), adResponseTypeKey, adResponseType.name()));
203203

204-
if (ffClient.getBooleanValue(ADSERVICE_FAILURE, false, evaluationContext)) {
204+
// Throw 1/10 of the time to simulate a failure when the feature flag is enabled
205+
if (ffClient.getBooleanValue(ADSERVICE_FAILURE, false, evaluationContext) && random.nextInt(10) == 0) {
205206
throw new StatusRuntimeException(Status.UNAVAILABLE);
206207
}
207208

src/cartservice/src/services/CartService.cs

+4-1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// SPDX-License-Identifier: Apache-2.0
33
using System.Diagnostics;
44
using System.Threading.Tasks;
5+
using System;
56
using Grpc.Core;
67
using OpenTelemetry.Trace;
78
using cartservice.cartstore;
@@ -13,6 +14,7 @@ namespace cartservice.services;
1314
public class CartService : Oteldemo.CartService.CartServiceBase
1415
{
1516
private static readonly Empty Empty = new();
17+
private readonly Random random = new Random();
1618
private readonly ICartStore _badCartStore;
1719
private readonly ICartStore _cartStore;
1820
private readonly IFeatureClient _featureFlagHelper;
@@ -60,7 +62,8 @@ public override async Task<Empty> EmptyCart(EmptyCartRequest request, ServerCall
6062

6163
try
6264
{
63-
if (await _featureFlagHelper.GetBooleanValue("cartServiceFailure", false))
65+
// Throw 1/10 of the time to simulate a failure when the feature flag is enabled
66+
if (await _featureFlagHelper.GetBooleanValue("cartServiceFailure", false) && random.Next(10) == 0)
6467
{
6568
await _badCartStore.EmptyCartAsync(request.UserId);
6669
}

src/flagd/demo.flagd.json

+13-19
Original file line numberDiff line numberDiff line change
@@ -23,19 +23,19 @@
2323
"description": "Triggers full manual garbage collections in the ad service",
2424
"state": "ENABLED",
2525
"variants": {
26-
"on": true,
27-
"off": false
28-
},
29-
"defaultVariant": "off"
26+
"on": true,
27+
"off": false
28+
},
29+
"defaultVariant": "off"
3030
},
3131
"adServiceHighCpu": {
3232
"description": "Triggers high cpu load in the ad service",
3333
"state": "ENABLED",
3434
"variants": {
35-
"on": true,
36-
"off": false
37-
},
38-
"defaultVariant": "off"
35+
"on": true,
36+
"off": false
37+
},
38+
"defaultVariant": "off"
3939
},
4040
"adServiceFailure": {
4141
"description": "Fail ad service",
@@ -44,22 +44,16 @@
4444
"on": true,
4545
"off": false
4646
},
47-
"defaultVariant": "off",
48-
"targeting": {
49-
"fractional": [
50-
["on", 10],
51-
["off", 90]
52-
]
53-
}
47+
"defaultVariant": "off"
5448
},
5549
"kafkaQueueProblems": {
5650
"description": "Overloads Kafka queue while simultaneously introducing a consumer side delay leading to a lag spike",
5751
"state": "ENABLED",
5852
"variants": {
59-
"on": 100,
60-
"off": 0
61-
},
62-
"defaultVariant": "off"
53+
"on": 100,
54+
"off": 0
55+
},
56+
"defaultVariant": "off"
6357
},
6458
"cartServiceFailure": {
6559
"description": "Fail cart service",

0 commit comments

Comments
 (0)