Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Simplify error scenario logic #1657

Merged
merged 3 commits into from
Jul 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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) {
julianocosta89 marked this conversation as resolved.
Show resolved Hide resolved
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
Loading