Skip to content

hcm: Add DependencyManager for http filterchain validation#15109

Merged
htuch merged 24 commits intoenvoyproxy:mainfrom
aunu53:manager
Mar 2, 2021
Merged

hcm: Add DependencyManager for http filterchain validation#15109
htuch merged 24 commits intoenvoyproxy:mainfrom
aunu53:manager

Conversation

@aunu53
Copy link
Copy Markdown
Contributor

@aunu53 aunu53 commented Feb 18, 2021

Commit Message:

  • Add DependencyManager class to handle http filterchain validation
  • This class currently only supports decode path validation, but encode path validation will be trivial to add afterwards
  • This class is directly scoped to the hcm extension and http filters, but it can be abstracted out when filterchain dependency is implemented for l4.

Risk Level: Low, this only adds a class and unit tests

See design doc attached to #14470 for more details.

Signed-off-by: Auni Ahsan <auni@google.com>
@htuch
Copy link
Copy Markdown
Member

htuch commented Feb 18, 2021

@htuch

Auni Ahsan added 5 commits February 18, 2021 21:48
Signed-off-by: Auni Ahsan <auni@google.com>
Signed-off-by: Auni Ahsan <auni@google.com>
Signed-off-by: Auni Ahsan <auni@google.com>
Signed-off-by: Auni Ahsan <auni@google.com>
Signed-off-by: Auni Ahsan <auni@google.com>
@aunu53 aunu53 changed the title http connection manager: Add dependency manager hcm: Add dependency manager class for filterchain validation Feb 19, 2021
@aunu53 aunu53 changed the title hcm: Add dependency manager class for filterchain validation hcm: Add DependencyManager for http filterchain validation Feb 19, 2021
Signed-off-by: Auni Ahsan <auni@google.com>
Auni Ahsan added 2 commits February 19, 2021 15:10
Signed-off-by: Auni Ahsan <auni@google.com>
Signed-off-by: Auni Ahsan <auni@google.com>
@aunu53 aunu53 marked this pull request as ready for review February 19, 2021 15:22
Auni Ahsan added 4 commits February 19, 2021 18:43
Signed-off-by: Auni Ahsan <auni@google.com>
Signed-off-by: Auni Ahsan <auni@google.com>
Signed-off-by: Auni Ahsan <auni@google.com>
Signed-off-by: Auni Ahsan <auni@google.com>
Copy link
Copy Markdown
Member

@htuch htuch left a comment

Choose a reason for hiding this comment

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

Thanks, make sense and looks good, just a few nits.
/wait

* from the filter factory. Filters must be registered in decode path order.
*/
void registerFilter(
std::string name,
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.

Nit: absl::string_view name

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Is there any memory access risk to having a std::map keyed by absl::string_view? Does this introduce lifetime requirements on the filter factory?

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.

You probably want the map itself to have a string key, but use string_view here. This is why absl::flat_hash_map is great, as it has these polymorphic lookup methods.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I misspoke, this is a std::vector<absl::string_view,...> not a map. Any issue with that?


bool DependencyManager::decodePathIsValid() {
auto cmp = [](Dependency a, Dependency b) { return a.name() != b.name(); };
std::set<Dependency, decltype(cmp)> satisfied(cmp);
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.

Nit: prefer absl::flat_hash_set.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

While I'd also prefer the absl library, it seems not to support the custom comparator API in the same way, and I'm going to avoid the hassle of figuring that out unless you feel strongly.


bool DependencyManager::decodePathIsValid() {
auto cmp = [](Dependency a, Dependency b) { return a.name() != b.name(); };
std::set<Dependency, decltype(cmp)> satisfied(cmp);
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.

Why not just make this a absl::flat_hash_set<std::string>?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Proto comparison doesn't work properly. In the future I'll probably switch this over to use message_differencer.h.

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.

For both this and the above point, I don't think we need to store the full dependency in the set, but just its name?

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.

I think I see what the issue is. You ideally are showing that the dependency matches the provider. You need to compare both name and also the DependencyType. However in this PR so far you only have name.

I suggest following the pattern of LocalityWeightsMap in eds.h for a pattern here around custom comparators, Absl, and proto keys.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I looked at LocalityWeightsMap and talked to Ashley about it, and I think got a simpler way to do this. Since it seems an intermediary type is unavoidable, I went with this:

using DependencyTuple = std::tuple<const std::string&, int>;
absl::flat_hash_set<DependencyTuple> satisfied;

This isn't resilient to modifications to the Dependency proto but I don't really anticipate more fields being added so I think this works for now.

Auni Ahsan added 4 commits February 22, 2021 16:05
Signed-off-by: Auni Ahsan <auni@google.com>
Signed-off-by: Auni Ahsan <auni@google.com>
Signed-off-by: Auni Ahsan <auni@google.com>
Signed-off-by: Auni Ahsan <auni@google.com>
Signed-off-by: Auni Ahsan <auni@google.com>
@htuch
Copy link
Copy Markdown
Member

htuch commented Feb 24, 2021

@auni53 looks good, I think maybe if you can add support for dealing with dependency type matching that would complete this for the decode path. Thanks.
/wait

Auni Ahsan added 2 commits February 24, 2021 18:00
Signed-off-by: Auni Ahsan <auni@google.com>
Signed-off-by: Auni Ahsan <auni@google.com>
Copy link
Copy Markdown
Contributor Author

@aunu53 aunu53 left a comment

Choose a reason for hiding this comment

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

OK, was able to incorporate absl flat hash set and simplified the comparator logic. I reordered/renamed the unit tests while adding functionality around dependency type checking.

* from the filter factory. Filters must be registered in decode path order.
*/
void registerFilter(
std::string name,
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I misspoke, this is a std::vector<absl::string_view,...> not a map. Any issue with that?

Signed-off-by: Auni Ahsan <auni@google.com>
Copy link
Copy Markdown
Member

@htuch htuch left a comment

Choose a reason for hiding this comment

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

LGTM modulo small nit. Thanks for the cleanups.
/wait

bool validDecodeDependencies();

private:
std::vector<std::pair<absl::string_view,
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.

For safety I'd make this an std::string. What I mentioned before was about parameters, the persistent structure should avoid holding a string view.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yeah the polymorphism is not working here:

dependency_manager.h:26:19: error: no matching member function for call to 'push_back'
    filter_chain_.push_back({name, dependencies});

Probably I'd have to call whatever function copies the underlying string from absl::string_view, so I just changed it to const std::string& both in the function signature and the vector definition.

Signed-off-by: Auni Ahsan <auni@google.com>
@htuch htuch added the waiting label Feb 28, 2021
Auni Ahsan added 2 commits March 2, 2021 17:28
Signed-off-by: Auni Ahsan <auni@google.com>
Signed-off-by: Auni Ahsan <auni@google.com>
Copy link
Copy Markdown
Member

@htuch htuch left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

@aunu53
Copy link
Copy Markdown
Contributor Author

aunu53 commented Mar 2, 2021

/retest

@repokitteh-read-only
Copy link
Copy Markdown

Retrying Azure Pipelines:
Retried failed jobs in: envoy-presubmit

🐱

Caused by: a #15109 (comment) was created by @auni53.

see: more, trace.

@htuch htuch merged commit 314f632 into envoyproxy:main Mar 2, 2021
@aunu53 aunu53 deleted the manager branch March 2, 2021 22:29
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.

2 participants