android: add support for registering a platform KV store#2134
Conversation
Signed-off-by: Mike Schore <mike.schore@gmail.com>
bd5669e to
a5c1612
Compare
Signed-off-by: Mike Schore <mike.schore@gmail.com>
Signed-off-by: Mike Schore <mike.schore@gmail.com>
Signed-off-by: Mike Schore <mike.schore@gmail.com>
Signed-off-by: Mike Schore <mike.schore@gmail.com>
Signed-off-by: Mike Schore <mike.schore@gmail.com>
Signed-off-by: Mike Schore <mike.schore@gmail.com>
Signed-off-by: Mike Schore <mike.schore@gmail.com>
Signed-off-by: Mike Schore <mike.schore@gmail.com>
Signed-off-by: Mike Schore <mike.schore@gmail.com>
Signed-off-by: Mike Schore <mike.schore@gmail.com>
Signed-off-by: Mike Schore <mike.schore@gmail.com>
Signed-off-by: Mike Schore <mike.schore@gmail.com>
Signed-off-by: Mike Schore <mike.schore@gmail.com>
Signed-off-by: Mike Schore <mike.schore@gmail.com>
Signed-off-by: Mike Schore <mike.schore@gmail.com>
RyanTheOptimist
left a comment
There was a problem hiding this comment.
Nice! A few small comments. I think it would also be nice to flesh out the PR description to explain a bit more the details of what's going on.
| namespace Envoy { | ||
| namespace Extensions { | ||
| namespace HttpFilters { | ||
| namespace TestKeyValueStore { |
There was a problem hiding this comment.
I would have expected the name of this to be something like PlatformKeyValueStore. Is this filter intended to be used in production? Maybe it's just test-only?
There was a problem hiding this comment.
Your presumption is correct - this is a test-only filter that exist alongside some other test-only filters in an entirely unintuitive location. Ideally, these should be moved elsewhere. I can certainly add a clarifying comment.
| * Remove a value from the key value store implementation. | ||
| * | ||
| * @param key, key identifying the value to be removed. | ||
| * @return String, value mapped to the key, or null if not present. |
There was a problem hiding this comment.
nit: Looks like this returns void?
| * Save a value to the key value store implementation. | ||
| * | ||
| * @param key, key identifying the value to be saved. | ||
| * @param value, the value to be saved. |
There was a problem hiding this comment.
nit: Looks like this returns void?
There was a problem hiding this comment.
I think this it still outstanding.
There was a problem hiding this comment.
Sorry I may be being dense - what's the fix here? I fixed the @return for remove, but this method doesn't have one.
There was a problem hiding this comment.
Oh, shoot. You're right. I somehow totally misread this. :(
There was a problem hiding this comment.
All good - thanks for all the comments. :)
|
|
||
| using TestKeyValueStoreFilterConfigSharedPtr = std::shared_ptr<TestKeyValueStoreFilterConfig>; | ||
|
|
||
| class TestKeyValueStoreFilter final : public ::Envoy::Http::PassThroughFilter { |
There was a problem hiding this comment.
nit: Please add a comment which describes what this filter does.
| envoy_data bridged_value = Data::Utility::copyToBridgeData(contents); | ||
| bridged_store_.save(bridged_key, bridged_value, bridged_store_.context); | ||
| } | ||
|
|
There was a problem hiding this comment.
I would have expected a remove() method. Is that not required?
There was a problem hiding this comment.
@alyssawilk shared that you all didn't have a use case for it right now (which I sort of found surprising, but then again, if you supply the KV store implementation, you can always remove stuff from it elsewhere). I went ahead and wired remove at the other layers anyways, simply because I do expect we will have a use for it.
| jobject j_context = static_cast<jobject>(const_cast<void*>(context)); | ||
|
|
||
| jclass jcls_JvmKeyValueStoreContext = env->GetObjectClass(j_context); | ||
| jmethodID jmid_read = env->GetMethodID(jcls_JvmKeyValueStoreContext, "read", "([B)[B"); |
There was a problem hiding this comment.
It's too bad there is no magic for auto-generating these method signature strings, but c'est la vie.
There was a problem hiding this comment.
In fact, there is! ...but I never figured out how it might work with Bazel. But javac itself has support for generating jni headers based on native method signatures in class definitions in java.
There was a problem hiding this comment.
Yeah, this is bound to bite us at some point. cxx.rs automatically generates these which helps avoid typos. If we start introducing Rust at this layer it would be worth considering using it for JNI codegen.
👍 |
Signed-off-by: Mike Schore <mike.schore@gmail.com>
Signed-off-by: Mike Schore <mike.schore@gmail.com>
Signed-off-by: Mike Schore <mike.schore@gmail.com>
RyanTheOptimist
left a comment
There was a problem hiding this comment.
LGTM, modulo one nit.
| * Save a value to the key value store implementation. | ||
| * | ||
| * @param key, key identifying the value to be saved. | ||
| * @param value, the value to be saved. |
There was a problem hiding this comment.
I think this it still outstanding.
| /** | ||
| * Function signature for reading value from implementation. | ||
| */ | ||
| typedef envoy_data (*envoy_kv_store_read_f)(envoy_data key, const void* context); |
There was a problem hiding this comment.
Is there a reason you went with a synchronous approach here? Is the idea that consumers would take care of moving this to a separate thread if they don't want to block on reading/writing?
There was a problem hiding this comment.
Well, for read asynchronous would introduce a whole new calling paradigm ("onRead"?). Honestly, I'd think an implementation should probably do caching/pre-caching/memoization if read performance is likely to be a bottleneck somewhere. For write/remove , yes, I think that's also better off as a feature of the actual provided platform implementation.
There was a problem hiding this comment.
ok. Another thing to consider is whether or not errors should be propagated between the platform and native layers.
| /** | ||
| * Function signature for saving value to implementation. | ||
| */ | ||
| typedef void (*envoy_kv_store_save_f)(envoy_data key, envoy_data value, const void* context); |
There was a problem hiding this comment.
Can this document what's expected as the context pointer?
There was a problem hiding this comment.
I added a more general description to the root c_types.h, since we use these everywhere.
library/common/jni/jni_interface.cc
Outdated
| } | ||
|
|
||
| static void jvm_kv_store_remove(envoy_data key, const void* context) { | ||
| jni_log("[Envoy]", "jvm_store_remove"); |
There was a problem hiding this comment.
Nit:
| jni_log("[Envoy]", "jvm_store_remove"); | |
| jni_log("[Envoy]", "jvm_kv_store_remove"); |
| <methods>; | ||
| } | ||
|
|
||
| -keep, includedescriptorclasses class io.envoyproxy.envoymobile.engine.JvmKeyValueStoreContext { |
There was a problem hiding this comment.
How is this file updated? Asking so I know when/how to do this next time I touch the Java implementation.
There was a problem hiding this comment.
Manually, when a new JNI-facing class is added.
Signed-off-by: Mike Schore <mike.schore@gmail.com>
|
Can you please add a changelog entry for the user-facing change? |
Signed-off-by: Mike Schore <mike.schore@gmail.com>
Signed-off-by: Mike Schore <mike.schore@gmail.com>
| // NOLINT(namespace-envoy) | ||
|
|
||
| /** | ||
| * Throughout this file one may note that most callbacks take a void* context parameter, and most |
jpsim
left a comment
There was a problem hiding this comment.
Nice work. Looking forward to seeing the default persistent kv store too.
…atcher-again * main: envoy: update to d88f31b (#2279) api: disallow setting 'host' header directly (#2275) android: add support for registering a platform KV store (#2134) Bump Lyft Support Rotation (#2278) tools: Enable the VSCode completion db to use bazelisk if available (#2277) Signed-off-by: JP Simard <jp@jpsim.com>
* origin/main: (97 commits) docs: update python packages to work with Python 3.10 (#2286) test: adding a cancel test, cleaning up copy-paste code (#2283) envoy: update to d88f31b (#2279) api: disallow setting 'host' header directly (#2275) android: add support for registering a platform KV store (#2134) Bump Lyft Support Rotation (#2278) tools: Enable the VSCode completion db to use bazelisk if available (#2277) Release v0.4.6.20220513-4 Fix android_release_deploy Release v0.4.6.20220513-3 Release v0.4.6.20220513-2 net: enable happy eyeballs by default (#2272) git: avoid merge conflicts when adding changelog entries (#2273) docs: fix sphinx reference mismatch warning (#2274) tests: add -Xcheck:jni to kotlin integration tests by default (#2269) configuration: enable h2 ping by default (#2270) Add version history entries for user-facing changes (#2271) configuration: filter unroutable addresses on Android by default (#2267) Integrate rules_xcodeproj (#2263) Add assert when failing to get_env (#2253) ... Signed-off-by: JP Simard <jp@jpsim.com>
Description: This PR allows platform implementations of a generic (and potentially persistent) key-value store to be registered with the Engine. Internal components can look up these implementations by name. The internal implementation and wiring in this PR is platform agnostic, but this PR adds a public API for Java/Kotlin only, initially. iOS and other public APIs to follow in upcoming PRs.
Part of #2077.
Risk Level: Low
Testing: New Unit + Integration Coverage
Signed-off-by: Mike Schore mike.schore@gmail.com