Skip to content

Commit 33a359f

Browse files
authored
access-log: refactor the MetadataMatcher to use simpler present matcher (#41029)
Signed-off-by: Adi Suissa-Peleg <adip@google.com>
1 parent 8b38e06 commit 33a359f

File tree

2 files changed

+4
-8
lines changed

2 files changed

+4
-8
lines changed

source/common/access_log/access_log_impl.cc

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,8 @@ bool LogTypeFilter::evaluate(const Formatter::HttpFormatterContext& context,
292292

293293
MetadataFilter::MetadataFilter(const envoy::config::accesslog::v3::MetadataFilter& filter_config,
294294
Server::Configuration::CommonFactoryContext& context)
295-
: default_match_(PROTOBUF_GET_WRAPPED_OR_DEFAULT(filter_config, match_if_key_not_found, true)),
295+
: present_matcher_(true),
296+
default_match_(PROTOBUF_GET_WRAPPED_OR_DEFAULT(filter_config, match_if_key_not_found, true)),
296297
filter_(filter_config.matcher().filter()) {
297298

298299
if (filter_config.has_matcher()) {
@@ -306,11 +307,6 @@ MetadataFilter::MetadataFilter(const envoy::config::accesslog::v3::MetadataFilte
306307
const auto& val = matcher_config.value();
307308
value_matcher_ = Matchers::ValueMatcher::create(val, context);
308309
}
309-
310-
// Matches if the value is present in dynamic metadata
311-
auto present_val = envoy::type::matcher::v3::ValueMatcher();
312-
present_val.set_present_match(true);
313-
present_matcher_ = Matchers::ValueMatcher::create(present_val, context);
314310
}
315311

316312
bool MetadataFilter::evaluate(const Formatter::HttpFormatterContext&,
@@ -319,7 +315,7 @@ bool MetadataFilter::evaluate(const Formatter::HttpFormatterContext&,
319315
Envoy::Config::Metadata::metadataValue(&info.dynamicMetadata(), filter_, path_);
320316
// If the key corresponds to a set value in dynamic metadata, return true if the value matches the
321317
// the configured 'MetadataMatcher' value and false otherwise
322-
if (present_matcher_->match(value)) {
318+
if (present_matcher_.match(value)) {
323319
return value_matcher_ && value_matcher_->match(value);
324320
}
325321

source/common/access_log/access_log_impl.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ class MetadataFilter : public Filter {
249249
const StreamInfo::StreamInfo& info) const override;
250250

251251
private:
252-
Matchers::ValueMatcherConstSharedPtr present_matcher_;
252+
Matchers::PresentMatcher present_matcher_;
253253
Matchers::ValueMatcherConstSharedPtr value_matcher_;
254254

255255
std::vector<std::string> path_;

0 commit comments

Comments
 (0)