Skip to content

key_value: structure for prefs based key value store#2120

Merged
alyssawilk merged 6 commits intoenvoyproxy:mainfrom
alyssawilk:kv
Mar 30, 2022
Merged

key_value: structure for prefs based key value store#2120
alyssawilk merged 6 commits intoenvoyproxy:mainfrom
alyssawilk:kv

Conversation

@alyssawilk
Copy link
Contributor

Part of #2077

Signed-off-by: Alyssa Wilk <alyssar@chromium.org>
Signed-off-by: Alyssa Wilk <alyssar@chromium.org>
Signed-off-by: Alyssa Wilk <alyssar@chromium.org>
@goaway
Copy link
Contributor

goaway commented Mar 22, 2022

Thanks for creating this @alyssawilk. Instead of callling it "PrefsBased", I'd suggest the name "PlatformKeyValueStore" - this is what we've named other components that have a platform-level implementation that they delegate to.

This will need a configurable string identifier for the platform API - this is how we discover platform APIs at runtime.

Signed-off-by: Alyssa Wilk <alyssar@chromium.org>
@alyssawilk
Copy link
Contributor Author

renamed. can you tell me a bit more about the string identifier, or point to examples?

@alyssawilk
Copy link
Contributor Author

ping!

@goaway
Copy link
Contributor

goaway commented Mar 29, 2022

PlatformBridgeFilters are maybe the best (if also somewhat complicated) example of this.

See:

Api::External::retrieveApi(proto_config.platform_filter_name()))) {}

An C API that represents the implementation is defined and and the actual delegating calls are registered (as part of engine initialization) in a global map called the Api::Registry. Lookup of the implementing calls occurs using a unique name for the filter implementation (there are obviously some runtime shortcomings here, but this can all be improved).

Filters are complicated, because a platform-level object actually gets instantiated each time the Envoy filter chain does. For a durable store, this is probably unnecessary and the same implementation can be re-used for all calls.

@goaway
Copy link
Contributor

goaway commented Mar 29, 2022

At the end of the day, the important thing is a token that can be specified in config, which can then be used both to register the API during runtime initialization, and to look up the API in compiled extension code.

Having thought about it more, I suppose we could use a single static token for this, but the parallel that struck me with filters is that you might actually have or want multiple implementations of this (e.g. preferences vs. secure storage).

@alyssawilk
Copy link
Contributor Author

IMO it'd be really helpful to have a single static token for now, since the factory that creates the k-v store doesn't have access to the hooks for up calls. or we could add that string to the prefs proto, if folks want to customize. I think that'd be part of your part of the implementation though?

@goaway
Copy link
Contributor

goaway commented Mar 29, 2022

@alyssawilk All it would need though is a single string field in its config proto though, right?

class PlatformInterface {
public:
virtual ~PlatformInterface() {}
virtual void flush(const std::string& key, const std::string& contents) PURE;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: I would suggest one of store, save, write or put as opposed to flush probably.

envoymobile::extensions::key_value::platform::PlatformKeyValueStoreConfig>(
typed_config.config().typed_config(), validation_visitor);
auto milliseconds =
std::chrono::milliseconds(DurationUtil::durationToMilliseconds(file_config.flush_interval()));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While I understand the value in supporting periodic flushes, would it make sense for the base case to be synchronous/immediate?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we want to for any of the current use cases - flushing on every dns resolution or every response headers seems expensive. @RyanTheOptimist for thoughts

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah for a per-request or per-DNS resolution store, immediate sync would be too expensive. Chrome's analogous system uses periodic writes, fwiw. I could imagine that we might have other use cases for the key-value store for which immediate write might be desirable so maybe there is value in having that as an option. But for the uses we currently have, periodic flushes make sense to me.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay that's fine - you all are the primary users of this right now anyways. I just thought it might make for easier testing and/or open up other simple use cases that aren't as perf sensitive.

Signed-off-by: Alyssa Wilk <alyssar@chromium.org>
Copy link
Contributor

@goaway goaway left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @alyssawilk!

Signed-off-by: Alyssa Wilk <alyssar@chromium.org>
@alyssawilk alyssawilk merged commit e3f3617 into envoyproxy:main Mar 30, 2022
jpsim added a commit that referenced this pull request Mar 31, 2022
* origin/main:
  key_value: structure for prefs based key value store (#2120)
  build: add flatbuffers (#2133)
  Bump Lyft Support Rotation (#2131)

Signed-off-by: JP Simard <jp@jpsim.com>
jpsim added a commit that referenced this pull request Apr 12, 2022
* main: (59 commits)
  Bump Lyft Support Rotation (#2156)
  add specifying more maven deps (#2151)
  update envoy@e4eaf1b97 (#2146)
  bazel: create symbol mapping file (#2126)
  Bump Lyft Support Rotation (#2148)
  bazel: remove sandbox disable
  build: export flatbuffer jvm dep (#2147)
  Bump Lyft Support Rotation (#2143)
  bazel: Add flatbuffers Swift hack
  key_value: structure for prefs based key value store (#2120)
  build: add flatbuffers (#2133)
  Bump Lyft Support Rotation (#2131)
  envoy: bump upstream Envoy to 419e237 (#2132)
  stats: enable more metrics (#2130)
  Use the right type (envoy_network_t) (#2125)
  Bump Lyft Support Rotation (#2118)
  Update CONTRIBUTING.md to include updating subrepos (#2023)
  ci: create baseline and experimental test app pipelines (#2075)
  config: temporarily hardcode h2 max concurrent streams to 100 (#2124)
  ...

Signed-off-by: JP Simard <jp@jpsim.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants