Skip to content

ip tagging: refactor ip tagging to make it lock free#45166

Merged
nezdolik merged 6 commits into
envoyproxy:mainfrom
wbpcode:dev-make-ip-tag-better
May 24, 2026
Merged

ip tagging: refactor ip tagging to make it lock free#45166
nezdolik merged 6 commits into
envoyproxy:mainfrom
wbpcode:dev-make-ip-tag-better

Conversation

@wbpcode

@wbpcode wbpcode commented May 20, 2026

Copy link
Copy Markdown
Member

Commit Message: ip tagging: refactor ip tagging to make it lock free
Additional Description:

Make the ip tagging lock free and removed unnecessary update callback of data source.

Risk Level: mid.
Testing: unit.
Docs Changes: n/a.
Release Notes: n/a.
Platform Specific Features: n/a.

Signed-off-by: wbpcode/wangbaiping <wbphub@gmail.com>
@wbpcode wbpcode requested review from nezdolik and zuercher as code owners May 20, 2026 03:06
@wbpcode wbpcode requested a review from Copilot May 20, 2026 03:07
@wbpcode

wbpcode commented May 20, 2026

Copy link
Copy Markdown
Member Author

/gemini review

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request refactors the IP tagging filter to use atomic snapshots for tries and statistics, ensuring that lookups and stat increments remain consistent during file reloads. It also simplifies the general DataSourceProvider by removing the data_update_cb mechanism. A high-severity issue was identified where validation_visitor is captured by reference in a lambda within a singleton-managed provider, potentially leading to use-after-free bugs if the provider outlives the configuration.

Comment thread source/extensions/filters/http/ip_tagging/ip_tagging_filter.cc

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Refactors the HTTP IP tagging filter to publish immutable “loaded snapshot” objects (trie + matching stats container) so request-path lookups and stat updates can be performed without locking, and removes the unused/incorrect DataSourceProvider update callback mechanism.

Changes:

  • Introduce LoadedIpTags snapshots and IpTagsStats to keep trie + per-tag builtin stat names consistent across reloads.
  • Rework IpTagsProvider to publish LoadedIpTags atomically from the datasource transform callback (enabling lock-free request path).
  • Remove DataUpdateCb support from Config::DataSource::DataSourceProvider / DynamicData.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
test/extensions/filters/http/ip_tagging/ip_tagging_filter_test.cc Updates tests to validate sharing behavior via the new LoadedIpTags snapshot/trie access.
source/extensions/filters/http/ip_tagging/ip_tagging_filter.h Introduces IpTagsStats + LoadedIpTags and updates provider/config APIs to use snapshots.
source/extensions/filters/http/ip_tagging/ip_tagging_filter.cc Implements snapshot creation on load/reload and updates filter request path to use a single per-request snapshot.
source/common/config/datasource.h Removes DataUpdateCb plumbing from DynamicData/DataSourceProvider and associated invocation logic.

Comment thread source/extensions/filters/http/ip_tagging/ip_tagging_filter.cc Outdated
Signed-off-by: wbpcode/wangbaiping <wbphub@gmail.com>
@wbpcode

wbpcode commented May 20, 2026

Copy link
Copy Markdown
Member Author

/retest

Signed-off-by: wbpcode/wangbaiping <wbphub@gmail.com>
const FilterRequestType request_type_;
Stats::Scope& scope_;
Runtime::Loader& runtime_;
const std::string stats_prefix_str_;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

this is a nice cleanup

Http::StreamDecoderFilterCallbacks* callbacks_{};
// Used for testing only.
mutable Thread::ThreadSynchronizer synchronizer_;
// Allow the unit test to have access to private members.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

this comment may be useful?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Great.

if (absl::EndsWith(datasource_filename, MessageUtil::FileExtensions::get().Yaml)) {
auto data = std::string(new_data);
auto load_status =
// TODO(nezdolik) remove string casting once yaml utility has been migrated to

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

now looking at this comment, looks like it better suits to be above line 91. (can fix it separately)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Good catch.

IpTagsStatsSharedPtr stats;
};

using LoadedIpTagsSharedPtr = std::shared_ptr<LoadedIpTags>;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

should we add const here?

using LoadedIpTagsSharedPtr = std::shared_ptr<const LoadedIpTags>;

nezdolik
nezdolik previously approved these changes May 22, 2026
Signed-off-by: wbpcode/wangbaiping <wbphub@gmail.com>
@nezdolik nezdolik merged commit 977327f into envoyproxy:main May 24, 2026
31 of 32 checks passed
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