feat: change engine proxy to use flatbuffer implementation over wasm#333
feat: change engine proxy to use flatbuffer implementation over wasm#333
Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR updates the SDK to replace WasmResponse with FlatResponse as part of migrating to a newer engine version (yggdrasil-engine 0.4.3). It also includes dependency updates, infrastructure improvements, and example project enhancements.
- Renamed
WasmResponsetoFlatResponsethroughout the codebase - Updated dependencies including Spring Boot (3.5.7), Gradle (9.1.0), and various libraries
- Added native image example with GraalVM support
- Improved test utilities with new
ResourceReaderclass
Reviewed Changes
Copilot reviewed 25 out of 27 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| src/main/java/io/getunleash/DefaultUnleash.java | Updated to use FlatResponse with Optional handling for null safety |
| src/main/java/io/getunleash/EngineProxyImpl.java | Changed return types from WasmResponse to FlatResponse |
| src/main/java/io/getunleash/repository/*.java | Updated method signatures to use FlatResponse |
| src/test/java/io/getunleash/util/ResourceReader.java | New utility class for reading test resources |
| pom.xml | Updated yggdrasil-engine to 0.4.3, upgraded dependencies, reorganized properties |
| examples/spring-boot-example/* | Updated Spring Boot to 3.5.7, added dev tools, fixed annotation usage |
| examples/native-image-example/* | New example demonstrating GraalVM native image support |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| FlatResponse<Boolean> isEnabled(String toggleName, UnleashContext context); | ||
|
|
||
| WasmResponse<VariantDef> getVariant(String toggleName, UnleashContext context); | ||
| FlatResponse<VariantDef> getVariant(String toggleName, UnleashContext context); |
There was a problem hiding this comment.
.NET is expecting these to not be null I believe
| WasmResponse<VariantDef> response = | ||
| FlatResponse<VariantDef> response = | ||
| this.featureRepository.getVariant(toggleName, enhancedContext); | ||
| Optional<VariantDef> variantDef = Optional.ofNullable(response.value); |
There was a problem hiding this comment.
This can give nullpointer exception, if response is null.
| Optional<VariantDef> variantDef = Optional.ofNullable(response.value); | ||
| Optional<FlatResponse<VariantDef>> response = | ||
| Optional.ofNullable(this.featureRepository.getVariant(toggleName, enhancedContext)); | ||
| Optional<VariantDef> variantDef = response.map(r -> r.value); |
There was a problem hiding this comment.
I think now if we call variantDef.get() you might get null as result, but you actually want isPresent to return false?
I think we want Optional<VariantDef> variantDef = response.flatMap(r -> Optional.ofNullable(r.value));
This is what we do in https://github.com/Unleash/unleash-java-sdk/pull/333/files#diff-5209f3f32d148f4e260e39b0166a5cd032fdc210bd83b0859993c254d4325263R119
There was a problem hiding this comment.
I agree monadically / if java actually did optionals the expected way, but as I just confirmed with jshell, when you map an option, if your option returns null, you get Optional.empty, not an NPE
jshell> Optional<String> my_present = Optional.of("hello");
my_present ==> Optional[hello]
jshell> Optional<String> absent = my_present.map(s -> null)
absent ==> Optional.empty
Pull Request Test Coverage Report for Build 19326878737Details
💛 - Coveralls |
… in isEnabled call
| getOrElse("UNLEASH_API_TOKEN", | ||
| "*:development.25a06b75248528f8ca93ce179dcdd141aedfb632231e0d21fd8ff349")) | ||
| .unleashAPI(getOrElse("UNLEASH_API_URL", "https://app.unleash-hosted.com/demo/api")) |
There was a problem hiding this comment.
Good enough for now I guess, but yeah maybe should've been env arg?
There was a problem hiding this comment.
It is an env arg. we just default to one that used to be able to access demo, but since we wipe demo regularly, I'm not worried.
| getOrElse("UNLEASH_API_TOKEN", | ||
| "*:development.25a06b75248528f8ca93ce179dcdd141aedfb632231e0d21fd8ff349")) |
| url: http://localhost:4242/api | ||
| apiKey: "*:development.da33883b2b2be02c5648ac624a1f50922cbc5893c2e6de5b9f57298d" |
This patches v11, we should probably also look at updating v10. But for now, this PR allows us to create an RC/beta that can run in our infrastructure to allow us to verify memory usage and performance.