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 82f5f8e commit cf5c1dc
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 14 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
25 changes: 20 additions & 5 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") {
log.Infof("Warning: FeatureFlag 'kafakQueueProblems' is activated, overloading queue now.")
messageCount := 100
for i := 0; i < messageCount; i++ {
ffValue := cs.getIntFeatureFlag(ctx, "kafkaQueueProblems")
if ffValue > 0 {
log.Infof("Warning: FeatureFlag 'kafkaQueueProblems' is activated, overloading queue now.")
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)
}
6 changes: 3 additions & 3 deletions src/flagd/demo.flagd.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,12 @@
]
}
},
"kafakQueueProblems": {
"kafkaQueueProblems": {
"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,8 +58,8 @@ 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")) {
logger.info("FeatureFlag 'kafakQueueProblems' is enabled, sleeping 1 second")
if (getFeatureFlagValue("kafkaQueueProblems") > 0) {
logger.info("FeatureFlag 'kafkaQueueProblems' is enabled, sleeping 1 second")
Thread.sleep(1000)
}
newCount
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 cf5c1dc

Please sign in to comment.