Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions docs/root/configuration/advanced/well_known_filter_state.rst
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,11 @@ configuration with a :ref:`factory lookup key
This creates a filter state entry named ``my.custom.key`` containing the string ``my-value``.
The value can be accessed in access logs using ``%FILTER_STATE(my.custom.key)%``.

``envoy.hashable_string``
Same as ``envoy.string`` but supports connection pool hashing when :ref:`shared with the upstream
<arch_overview_advanced_filter_state_sharing>`. Please use with care as it can lead to significant
increase in the number of upstream connections when used with HTTP upstreams.

``envoy.network.ip``
A factory to create IP addresses from ``IPv4`` and ``IPv6`` address strings.

Expand Down
2 changes: 1 addition & 1 deletion docs/root/configuration/security/secret.rst
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ the downstream filter chain, e.g. using the following filter configuration:
"@type": type.googleapis.com/envoy.extensions.filters.network.set_filter_state.v3.Config
on_new_connection:
- object_key: envoy.tls.certificate_mappers.on_demand_secret
factory_key: envoy.string
factory_key: envoy.hashable_string
format_string:
text_format_source:
inline_string: my_secret_name
Expand Down
1 change: 1 addition & 0 deletions source/extensions/filters/common/set_filter_state/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ envoy_cc_library(
srcs = ["filter_config.cc"],
hdrs = ["filter_config.h"],
deps = [
"//envoy/common:hashable_interface",
"//envoy/formatter:substitution_formatter_interface",
"//envoy/registry",
"//envoy/stream_info:filter_state_interface",
Expand Down
20 changes: 20 additions & 0 deletions source/extensions/filters/common/set_filter_state/filter_config.cc
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "source/extensions/filters/common/set_filter_state/filter_config.h"

#include "envoy/common/hashable.h"
#include "envoy/registry/registry.h"

#include "source/common/formatter/substitution_format_string.h"
Expand All @@ -22,6 +23,25 @@ class GenericStringObjectFactory : public StreamInfo::FilterState::ObjectFactory

REGISTER_FACTORY(GenericStringObjectFactory, StreamInfo::FilterState::ObjectFactory);

class HashableString : public Router::StringAccessorImpl, public Hashable {
public:
HashableString(absl::string_view value) : StringAccessorImpl(value) {}

// Hashable
absl::optional<uint64_t> hash() const override { return HashUtil::xxHash64(asString()); }
};

class GenericHashableStringObjectFactory : public StreamInfo::FilterState::ObjectFactory {
public:
std::string name() const override { return "envoy.hashable_string"; }
std::unique_ptr<StreamInfo::FilterState::Object>
createFromBytes(absl::string_view data) const override {
return std::make_unique<HashableString>(data);
}
};

REGISTER_FACTORY(GenericHashableStringObjectFactory, StreamInfo::FilterState::ObjectFactory);

std::vector<Value>
Config::parse(const Protobuf::RepeatedPtrField<FilterStateValueProto>& proto_values,
Server::Configuration::GenericFactoryContext& context) const {
Expand Down
1 change: 1 addition & 0 deletions test/extensions/filters/common/set_filter_state/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ envoy_cc_test(
srcs = ["filter_config_test.cc"],
rbe_pool = "6gig",
deps = [
"//envoy/common:hashable_interface",
"//source/common/formatter:formatter_extension_lib",
"//source/common/router:string_accessor_lib",
"//source/extensions/filters/common/set_filter_state:filter_config_lib",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#include "envoy/common/hashable.h"

#include "source/common/router/string_accessor_impl.h"
#include "source/extensions/filters/common/set_filter_state/filter_config.h"
#include "source/server/generic_factory_context.h"
Expand Down Expand Up @@ -93,6 +95,19 @@ TEST_F(ConfigTest, SetValueWithFactory) {
EXPECT_EQ(0, info_.filterState()->objectsSharedWithUpstreamConnection()->size());
}

TEST_F(ConfigTest, SetHashableValueWithFactory) {
initialize({R"YAML(
object_key: my_key
factory_key: envoy.hashable_string
format_string:
text_format_source:
inline_string: "XXX"
)YAML"});
update();
const auto* foo = info_.filterState()->getDataReadOnly<Hashable>("my_key");
ASSERT_NE(nullptr, foo);
}

TEST_F(ConfigTest, SetValueConnection) {
initialize({R"YAML(
object_key: foo
Expand Down
Loading