Skip to content

Commit

Permalink
changed feature flag to int value for more configurability
Browse files Browse the repository at this point in the history
also adjusted the resource limit for the frauddetection service since it kept dying
  • Loading branch information
EislM0203 committed Apr 15, 2024
1 parent 3bd36b5 commit 38ec15e
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 11 deletions.
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ services:
deploy:
resources:
limits:
memory: 200M
memory: 300M
restart: unless-stopped
environment:
- FLAGD_HOST
Expand Down
23 changes: 19 additions & 4 deletions src/checkoutservice/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -507,16 +507,16 @@ func (cs *checkoutService) sendToPostProcessor(ctx context.Context, result *pb.O
successMsg := <-cs.KafkaProducerClient.Successes()
log.Infof("Successful to write message. offset: %v", successMsg.Offset)

if cs.isFeatureFlagEnabled(ctx, "kafakQueueProblems") {
ffValue := cs.getIntFeatureFlag(ctx, "kafakQueueProblems")
if ffValue > 0 {
log.Infof("Warning: FeatureFlag 'kafakQueueProblems' is activated, overloading queue now.")
messageCount := 100
for i := 0; i < messageCount; i++ {
for i := 0; i < ffValue; i++ {
go func(i int) {
cs.KafkaProducerClient.Input() <- &msg
_ = <-cs.KafkaProducerClient.Successes()
}(i)
}
log.Infof("Done with #%d messages for overload simulation.", messageCount)
log.Infof("Done with #%d messages for overload simulation.", ffValue)
}
}

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

return featureEnabled
}

func (cs *checkoutService) getIntFeatureFlag(ctx context.Context, featureFlagName string) int {
openfeature.AddHooks(otelhooks.NewTracesHook())
client := openfeature.NewClient("checkout")

// Default value is set to 0, but you could also make this a parameter.
featureFlagValue, _ := client.IntValue(
ctx,
featureFlagName,
0,
openfeature.EvaluationContext{},
)

return int(featureFlagValue)
}
4 changes: 2 additions & 2 deletions src/flagd/demo.flagd.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@
"description": "Overloads Kafka queue while simultaneously introducing a consumer side delay leading to a lag spike",
"state": "ENABLED",
"variants": {
"on": true,
"off": false
"on": 100,
"off": 0
},
"defaultVariant": "off"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ fun main() {
val newCount = accumulator + 1
val orders = OrderResult.parseFrom(record.value())
logger.info("Consumed record with orderId: ${orders.orderId}, and updated total count to: $newCount")
if (getFeatureFlagEnabled("kafakQueueProblems")) {
if (getFeatureFlagValue("kafakQueueProblems") > 0) {
logger.info("FeatureFlag 'kafakQueueProblems' is enabled, sleeping 1 second")
Thread.sleep(1000)
}
Expand All @@ -74,11 +74,11 @@ fun main() {
* @param ff The name of the feature flag to retrieve.
* @return `true` if the feature flag is enabled, `false` otherwise or in case of errors.
*/
fun getFeatureFlagEnabled(ff: String): Boolean {
fun getFeatureFlagValue(ff: String): Int {
val client = OpenFeatureAPI.getInstance().client
// TODO: Plumb the actual session ID from the frontend via baggage?
val uuid = UUID.randomUUID()
client.evaluationContext = MutableContext().add("session", uuid.toString())
val booleanValue = client.getBooleanValue(ff, false)
return booleanValue
val intValue = client.getIntegerValue(ff, 0)
return intValue
}

0 comments on commit 38ec15e

Please sign in to comment.