Skip to content

Commit

Permalink
Simplify error scenario logic (open-telemetry#1657)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
beeme1mr authored and ahealy-newr committed Jul 24, 2024
1 parent ecaf3d9 commit 7523233
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 21 deletions.
3 changes: 2 additions & 1 deletion src/adservice/src/main/java/oteldemo/AdService.java
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,8 @@ public void getAds(AdRequest req, StreamObserver<AdResponse> 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);
}

Expand Down
5 changes: 4 additions & 1 deletion src/cartservice/src/services/CartService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -60,7 +62,8 @@ public override async Task<Empty> 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);
}
Expand Down
32 changes: 13 additions & 19 deletions src/flagd/demo.flagd.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down

0 comments on commit 7523233

Please sign in to comment.