Skip to content

Commit

Permalink
review
Browse files Browse the repository at this point in the history
Signed-off-by: Kuat Yessenov <[email protected]>
  • Loading branch information
kyessenov committed Oct 11, 2023
1 parent 43461ff commit e111ce2
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,9 @@ namespace Filters {
namespace Common {
namespace SetFilterState {

std::vector<Value> Config::parse(
const Protobuf::RepeatedPtrField<
envoy::extensions::filters::common::set_filter_state::v3::FilterStateValue>& proto_values,
Server::Configuration::CommonFactoryContext& context) const {
std::vector<Value>
Config::parse(const Protobuf::RepeatedPtrField<FilterStateValueProto>& proto_values,
Server::Configuration::CommonFactoryContext& context) const {
std::vector<Value> values;
values.reserve(proto_values.size());
for (const auto& proto_value : proto_values) {
Expand All @@ -24,10 +23,10 @@ std::vector<Value> Config::parse(
}
value.state_type_ = proto_value.read_only() ? StateType::ReadOnly : StateType::Mutable;
switch (proto_value.shared_with_upstream()) {
case envoy::extensions::filters::common::set_filter_state::v3::FilterStateValue::ONCE:
case FilterStateValueProto::ONCE:
value.stream_sharing_ = StreamSharing::SharedWithUpstreamConnectionOnce;
break;
case envoy::extensions::filters::common::set_filter_state::v3::FilterStateValue::TRANSITIVE:
case FilterStateValueProto::TRANSITIVE:
value.stream_sharing_ = StreamSharing::SharedWithUpstreamConnection;
break;
default:
Expand All @@ -37,7 +36,7 @@ std::vector<Value> Config::parse(
value.skip_if_empty_ = proto_value.skip_if_empty();
value.value_ = Formatter::SubstitutionFormatStringUtils::fromProtoConfig(
proto_value.format_string(), context);
values.push_back(value);
values.push_back(std::move(value));
}
return values;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ namespace SetFilterState {
using LifeSpan = StreamInfo::FilterState::LifeSpan;
using StateType = StreamInfo::FilterState::StateType;
using StreamSharing = StreamInfo::StreamSharingMayImpactPooling;
using FilterStateValueProto =
envoy::extensions::filters::common::set_filter_state::v3::FilterStateValue;

struct Value {
std::string key_;
Expand All @@ -28,19 +30,15 @@ struct Value {

class Config : public Logger::Loggable<Logger::Id::config> {
public:
Config(
const Protobuf::RepeatedPtrField<
envoy::extensions::filters::common::set_filter_state::v3::FilterStateValue>& proto_values,
LifeSpan life_span, Server::Configuration::CommonFactoryContext& context)
Config(const Protobuf::RepeatedPtrField<FilterStateValueProto>& proto_values, LifeSpan life_span,
Server::Configuration::CommonFactoryContext& context)
: life_span_(life_span), values_(parse(proto_values, context)) {}
void updateFilterState(const Formatter::HttpFormatterContext& context,
StreamInfo::StreamInfo& info) const;

private:
std::vector<Value> parse(
const Protobuf::RepeatedPtrField<
envoy::extensions::filters::common::set_filter_state::v3::FilterStateValue>& proto_values,
Server::Configuration::CommonFactoryContext& context) const;
std::vector<Value> parse(const Protobuf::RepeatedPtrField<FilterStateValueProto>& proto_values,
Server::Configuration::CommonFactoryContext& context) const;
const LifeSpan life_span_;
const std::vector<Value> values_;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,16 @@ class ConfigTest : public testing::Test {
public:
void initialize(const std::vector<std::string>& values,
LifeSpan life_span = LifeSpan::FilterChain) {
using ProtoValue = envoy::extensions::filters::common::set_filter_state::v3::FilterStateValue;
std::vector<ProtoValue> proto_values;
std::vector<FilterStateValueProto> proto_values;
proto_values.reserve(values.size());
for (const auto& value : values) {
ProtoValue proto_value;
FilterStateValueProto proto_value;
TestUtility::loadFromYaml(value, proto_value);
proto_values.push_back(proto_value);
}
config_ = std::make_shared<Config>(
Protobuf::RepeatedPtrField<ProtoValue>(proto_values.begin(), proto_values.end()), life_span,
context_);
Protobuf::RepeatedPtrField<FilterStateValueProto>(proto_values.begin(), proto_values.end()),
life_span, context_);
}
void update() { config_->updateFilterState({&header_map_}, info_); }
NiceMock<Server::Configuration::MockFactoryContext> context_;
Expand Down

0 comments on commit e111ce2

Please sign in to comment.