Skip to content

Commit cf5c1dc

Browse files
committed
changed feature flag to int value for more configurability
also adjusted the resource limit for the frauddetection service since it kept dying
1 parent 82f5f8e commit cf5c1dc

File tree

4 files changed

+29
-14
lines changed

4 files changed

+29
-14
lines changed

docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ services:
247247
deploy:
248248
resources:
249249
limits:
250-
memory: 200M
250+
memory: 300M
251251
restart: unless-stopped
252252
environment:
253253
- FLAGD_HOST

src/checkoutservice/main.go

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -507,16 +507,16 @@ func (cs *checkoutService) sendToPostProcessor(ctx context.Context, result *pb.O
507507
successMsg := <-cs.KafkaProducerClient.Successes()
508508
log.Infof("Successful to write message. offset: %v", successMsg.Offset)
509509

510-
if cs.isFeatureFlagEnabled(ctx, "kafakQueueProblems") {
511-
log.Infof("Warning: FeatureFlag 'kafakQueueProblems' is activated, overloading queue now.")
512-
messageCount := 100
513-
for i := 0; i < messageCount; i++ {
510+
ffValue := cs.getIntFeatureFlag(ctx, "kafkaQueueProblems")
511+
if ffValue > 0 {
512+
log.Infof("Warning: FeatureFlag 'kafkaQueueProblems' is activated, overloading queue now.")
513+
for i := 0; i < ffValue; i++ {
514514
go func(i int) {
515515
cs.KafkaProducerClient.Input() <- &msg
516516
_ = <-cs.KafkaProducerClient.Successes()
517517
}(i)
518518
}
519-
log.Infof("Done with #%d messages for overload simulation.", messageCount)
519+
log.Infof("Done with #%d messages for overload simulation.", ffValue)
520520
}
521521
}
522522

@@ -560,3 +560,18 @@ func (cs *checkoutService) isFeatureFlagEnabled(ctx context.Context, featureFlag
560560

561561
return featureEnabled
562562
}
563+
564+
func (cs *checkoutService) getIntFeatureFlag(ctx context.Context, featureFlagName string) int {
565+
openfeature.AddHooks(otelhooks.NewTracesHook())
566+
client := openfeature.NewClient("checkout")
567+
568+
// Default value is set to 0, but you could also make this a parameter.
569+
featureFlagValue, _ := client.IntValue(
570+
ctx,
571+
featureFlagName,
572+
0,
573+
openfeature.EvaluationContext{},
574+
)
575+
576+
return int(featureFlagValue)
577+
}

src/flagd/demo.flagd.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,12 @@
6161
]
6262
}
6363
},
64-
"kafakQueueProblems": {
64+
"kafkaQueueProblems": {
6565
"description": "Overloads Kafka queue while simultaneously introducing a consumer side delay leading to a lag spike",
6666
"state": "ENABLED",
6767
"variants": {
68-
"on": true,
69-
"off": false
68+
"on": 100,
69+
"off": 0
7070
},
7171
"defaultVariant": "off"
7272
},

src/frauddetectionservice/src/main/kotlin/frauddetectionservice/main.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ fun main() {
5858
val newCount = accumulator + 1
5959
val orders = OrderResult.parseFrom(record.value())
6060
logger.info("Consumed record with orderId: ${orders.orderId}, and updated total count to: $newCount")
61-
if (getFeatureFlagEnabled("kafakQueueProblems")) {
62-
logger.info("FeatureFlag 'kafakQueueProblems' is enabled, sleeping 1 second")
61+
if (getFeatureFlagValue("kafkaQueueProblems") > 0) {
62+
logger.info("FeatureFlag 'kafkaQueueProblems' is enabled, sleeping 1 second")
6363
Thread.sleep(1000)
6464
}
6565
newCount
@@ -74,11 +74,11 @@ fun main() {
7474
* @param ff The name of the feature flag to retrieve.
7575
* @return `true` if the feature flag is enabled, `false` otherwise or in case of errors.
7676
*/
77-
fun getFeatureFlagEnabled(ff: String): Boolean {
77+
fun getFeatureFlagValue(ff: String): Int {
7878
val client = OpenFeatureAPI.getInstance().client
7979
// TODO: Plumb the actual session ID from the frontend via baggage?
8080
val uuid = UUID.randomUUID()
8181
client.evaluationContext = MutableContext().add("session", uuid.toString())
82-
val booleanValue = client.getBooleanValue(ff, false)
83-
return booleanValue
82+
val intValue = client.getIntegerValue(ff, 0)
83+
return intValue
8484
}

0 commit comments

Comments
 (0)