-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
dns: configuring a basic key value store to persist to disk #17745
Changes from 9 commits
7c3e296
ade78e0
253dbae
7104f0f
ca9e396
1c37b93
d2b4fb0
ab188c0
f229567
30eb561
a94bc2a
5dd50d7
51063a8
2810696
7b2b206
e9fd018
a431763
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# DO NOT EDIT. This file is generated by tools/proto_format/proto_sync.py. | ||
|
||
load("@envoy_api//bazel:api_build_system.bzl", "api_proto_package") | ||
|
||
licenses(["notice"]) # Apache 2 | ||
|
||
api_proto_package( | ||
deps = [ | ||
"//envoy/config/core/v3:pkg", | ||
"@com_github_cncf_udpa//udpa/annotations:pkg", | ||
], | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
syntax = "proto3"; | ||
|
||
package envoy.extensions.common.key_value.v3; | ||
|
||
import "envoy/config/core/v3/extension.proto"; | ||
|
||
import "google/protobuf/any.proto"; | ||
import "google/protobuf/duration.proto"; | ||
|
||
import "udpa/annotations/status.proto"; | ||
import "validate/validate.proto"; | ||
|
||
option java_package = "io.envoyproxy.envoy.extensions.common.key_value.v3"; | ||
option java_outer_classname = "ConfigProto"; | ||
option java_multiple_files = true; | ||
option (udpa.annotations.file_status).package_version_status = ACTIVE; | ||
|
||
// [#protodoc-title: Key Value Store storage plugin] | ||
|
||
// [#alpha:] | ||
// This shared configuration for Envoy key value stores. | ||
message KeyValueStoreConfig { | ||
// [#extension-category: envoy.common.key_value] | ||
config.core.v3.TypedExtensionConfig config = 1 [(validate.rules).message = {required: true}]; | ||
|
||
// The interval at which the key value store should be flushed to long term | ||
// storage. | ||
google.protobuf.Duration flush_interval = 2; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess this gets to my earlier question, do we know that all implementations will flush? Or will flushing be a property of a specific key-value story, e.g. the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ditto - current uses all involve persisting but can't hurt to move it to file based and just dup the single value for mobile based. |
||
} | ||
|
||
// [#alpha:] | ||
// [#extension: envoy.common.key_value.file_based] | ||
// This is configuration to flush a key value store out to disk. | ||
message FileBasedKeyValueStoreConfig { | ||
alyssawilk marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// The filename to read the keys and values from, and write the keys and | ||
// values to. | ||
string filename = 1 [(validate.rules).string = {min_len: 1}]; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,10 @@ | ||
#pragma once | ||
|
||
#include "envoy/common/pure.h" | ||
#include "envoy/config/typed_config.h" | ||
#include "envoy/event/dispatcher.h" | ||
#include "envoy/filesystem/filesystem.h" | ||
#include "envoy/protobuf/message_validator.h" | ||
|
||
#include "absl/strings/string_view.h" | ||
#include "absl/types/optional.h" | ||
|
@@ -37,6 +41,45 @@ class KeyValueStore { | |
* Flushes the store to long term storage. | ||
*/ | ||
virtual void flush() PURE; | ||
|
||
// Returns for the iterate function. | ||
enum class Iterate { Continue, Break }; | ||
|
||
/** | ||
* Callback when calling iterate() in a key value store. | ||
* @param key is the key for a given entry | ||
* @param value is the value for a given entry | ||
* @return Iterate::Continue to continue iteration, or Iterate::Break to stop. | ||
*/ | ||
using ConstIterateCb = std::function<Iterate(const std::string& key, const std::string& value)>; | ||
|
||
/** | ||
* Iterate over a key value store. | ||
* @param cb supplies the iteration callback. | ||
*/ | ||
virtual void iterate(ConstIterateCb cb) const PURE; | ||
}; | ||
|
||
using KeyValueStorePtr = std::unique_ptr<KeyValueStore>; | ||
|
||
// A factory for creating key value stores. | ||
class KeyValueStoreFactory : public Envoy::Config::TypedFactory { | ||
public: | ||
/** | ||
* Function to create KeyValueStores from the specified config. | ||
* @param cb supplies the key value store configuration | ||
* @param validation_visitor the configuration validator | ||
* @dispatcher the dispatcher for the thread, for flush alarms. | ||
* @file_system the file system. | ||
* @return a new key value store. | ||
*/ | ||
virtual KeyValueStorePtr createStore(const Protobuf::Message& config, | ||
ProtobufMessage::ValidationVisitor& validation_visitor, | ||
Event::Dispatcher& dispatcher, | ||
Filesystem::Instance& file_system) PURE; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we just pass There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unfortunately we can't - the DNS store is created both from ServerFactoryContext and from the cluster's TransportSocketFactoryContextImpl which have wide overlap but no common base class. |
||
|
||
// @brief the category of the key value store for factory registration. | ||
std::string category() const override { return "envoy.common.key_value"; } | ||
}; | ||
|
||
} // namespace Envoy |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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.
Nit on naming: given this is referencing an extension point, do we know that there will always be persistence guaranteed?
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.
Good question. I can't think of a use case where we'd add a key-value store and not persist it. We already have a DNS cache so the point of this is to persist. That said, just because I can't think of a use case it certainly doesn't hurt to future-proof :-)