-
Notifications
You must be signed in to change notification settings - Fork 84
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
android: create persistent SharedPreferences-based KV store #2319
Conversation
Signed-off-by: Mike Schore <mike.schore@gmail.com>
1599479
to
50a886a
Compare
Looks straightforward enough. Should we expose a builder API to enable this? |
@jpsim Setting a KV store is already supported in the Kotlin EngineBuilder, with Swift to follow. :) |
|
||
import io.envoyproxy.envoymobile.KeyValueStore | ||
|
||
class SharedPreferencesStore(sharedPreferences: SharedPreferences) : KeyValueStore { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we have some docs for this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added docstring, and the interface is documented - would be great to generate docs from these.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(Looks like @jpsim has made some great progress here!)
library/kotlin/io/envoyproxy/envoymobile/android/SharedPreferencesStore.kt
Outdated
Show resolved
Hide resolved
|
||
import io.envoyproxy.envoymobile.KeyValueStore | ||
|
||
class SharedPreferencesStore(sharedPreferences: SharedPreferences) : KeyValueStore { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we add some unit tests specific to SharedPreferencesStore
class?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't today have a unit test setup that loads the Android platform APIs, because we don't today have a lot of Android-only or Android-specific code (by design). If/as we add more, we probably do want such a test suite, but this is mostly meant to be a trivial example implementation that guides others in using the API. That said, once we have a place for such tests to live, I agree we should cover this at the unit level for completeness' sake.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see, thank you for the context.
I would argue that we should have a test even for this trivial example since otherwise we cannot really tell whether it works or not the way we expect it to work - as in, I think that we are past the threshold when we can justify having an Android tests suite (if we have a need for Android code we have a need for Android tests).
Could we create a GH issue for this if you do not want to do this as part of this PR? I would love us to start investing in testing more, otherwise it's going to become increasingly hard to continue to move forward without leaving broken stuff behind us.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Roboelectric supports this today, and we use it in quite a few tests: https://github.com/envoyproxy/envoy-mobile/search?q=robolectric
Signed-off-by: Mike Schore <mike.schore@gmail.com>
Sorry I wasn't clear. Right now to use this I think users would have to configure the builder like this: .addKeyValueStore("some name the user has to choose", SharedPreferencesStore(...)) Why do we have to expose the .useDefaultPersistentKeyValueStore(true) And configure |
@jpsim a name for the store is required in the builder API, because more than one key-value store may be registered. The https://developer.android.com/training/data-storage/shared-preferences Anyways, that's the reasoning behind the method signatures. :) |
As an update to my comment above, I misremembered - EM does have access to some derivation of the application context at least at creation, since that's needed to initialize DNS. So we could in theory use that to create our own default So my inclination is to say that I while think this is a good idea, we perhaps ought to opt for simplicity and flexibility at this point until we have a better notion of where and how this gets used. |
I understand that, but we could have a reserved/default name for this persistent store. Noted on the complexity and responsibility creep involved in accessing the application context internally in Envoy Mobile. Requiring this to be wired explicitly is fine with me for now, but ideally we'd improve on this pattern so that Envoy Mobile's default configuration gets this benefit out of the box. Also, having reasonable/good defaults doesn't mean that we shouldn't expose ways to change them in case they want to refine/disable/change it for their use case. |
That would be my preference as well -> make some defaults that work just fine for most users and allow them to override it when they need something custom. System level networking libraries on iOS/Android do not require you to provide any caching configuration to get basic caching up and running. If we want to experiment with this first that's fine but I would argue that the final API needs to have some notions of defaults implemented. |
I think we're all in agreement here? The only thing I'm proposing is we hold off on making assumptions around what a default should be until we understand see a bit better how it's being used (alt-svc caching, http caching, etc.). |
To recap some offline discussions, yes in agreement as a first version, which requires consumers to wire this through the Ideally before merging this would still have the following:
I still think a test using roboelectric to simulate Android's shared preferences would be good to have but understand if that's not something you want to tackle here. |
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>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work
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>
* origin/main: (33 commits) iOS: fix xcframework upload in release workflow (#2366) config: hopefully fixing C++ config default for apple (#2355) Update Envoy (#2364) Bump Lyft Support Rotation (#2365) ci: pin external GitHub Action (#2363) cleanup: fix warning in JNI layer (#2361) cleanup: convert some more uses of NULL to nullptr (#2359) cleanup: consistently use nullptr in cc contexts (#2351) cleanup: remove unused function and resolve warning (#2350) iOS: add configurable gzip and brotli decompression options (#2349) iOS: stop embedding bitcode in releases (#2347) ci: update Android setup (#2354) docs: update the list of clusters (#2344) bazel: update rules_apple (#2346) iOS: add a way to disable network monitoring (#2345) api: adding brotli knobs (#2342) android: create persistent SharedPreferences-based KV store (#2319) ios: add support for registering a platform KV store (#2334) builder: making compressor configurable (#2321) iOS: add SwiftPM example (#2333) ... Signed-off-by: JP Simard <jp@jpsim.com>
* origin/main: (33 commits) iOS: fix xcframework upload in release workflow (#2366) config: hopefully fixing C++ config default for apple (#2355) Update Envoy (#2364) Bump Lyft Support Rotation (#2365) ci: pin external GitHub Action (#2363) cleanup: fix warning in JNI layer (#2361) cleanup: convert some more uses of NULL to nullptr (#2359) cleanup: consistently use nullptr in cc contexts (#2351) cleanup: remove unused function and resolve warning (#2350) iOS: add configurable gzip and brotli decompression options (#2349) iOS: stop embedding bitcode in releases (#2347) ci: update Android setup (#2354) docs: update the list of clusters (#2344) bazel: update rules_apple (#2346) iOS: add a way to disable network monitoring (#2345) api: adding brotli knobs (#2342) android: create persistent SharedPreferences-based KV store (#2319) ios: add support for registering a platform KV store (#2334) builder: making compressor configurable (#2321) iOS: add SwiftPM example (#2333) ... Signed-off-by: JP Simard <jp@jpsim.com>
Description: Updates the exposed KeyValueStore type to be a more traditional implementable interface, and provides a simple persisting implementation based on Android SharedPreferences. Risk: Low Testing: Application Signed-off-by: Mike Schore <mike.schore@gmail.com> Signed-off-by: Rafal Augustyniak <raugustyniak@lyft.com>
Description: Updates the exposed KeyValueStore type to be a more traditional implementable interface, and provides a simple persisting implementation based on Android SharedPreferences.
Risk: Low
Testing: Application
Signed-off-by: Mike Schore mike.schore@gmail.com