-
Notifications
You must be signed in to change notification settings - Fork 578
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
FilterUtility::GetFilterTargets(): don't run filter for specific object(s) for all objects #9895
Conversation
if (dynamic_cast<ConfigObjectTargetProvider*>(provider.get())) { | ||
auto dict (dynamic_cast<DictExpression*>(ufilter.get())); | ||
|
||
if (dict) { | ||
auto& subex (dict->GetExpressions()); | ||
|
||
if (subex.size() == 1u) { | ||
if (type == "Host") { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- There's a filter on Hosts/Services
lib/remote/filterutility.cpp
Outdated
if (type == "Host") { | ||
std::vector<const String *> targetNames; | ||
|
||
if (GetTargetHosts(subex.at(0).get(), filter_vars, targetNames)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Does it unambiguously target only specific Hosts/Services?
if (targeted) { | ||
for (auto& target : targets) { | ||
if (FilterUtility::EvaluateFilter(permissionFrame, permissionFilter.get(), target, variableName)) { | ||
result.emplace_back(std::move(target)); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- If yes: fetch just them, don't run filter for all
Test
👍 The above one is 50x faster, just because no Config
|
af3f5a4
to
f52fbc0
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Apart from the comments below it's just fine, I'm not sure how this would in any way fix the memory leak referenced in the PR desc though.
if (type == "Host") { | ||
std::vector<const String *> targetNames; | ||
|
||
if (ApplyRule::GetTargetHosts(subex.at(0).get(), targetNames, filter_vars)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since the goal of this PR is reducing the performance overhead, you should favour subex[0]
over subex.at(0)
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Won't give much in addition, at the cost of SEGV -not just exception- if the code breaks in the future.
} else if (type == "Service") { | ||
std::vector<std::pair<const String *, const String *>> targetNames; | ||
|
||
if (ApplyRule::GetTargetServices(subex.at(0).get(), targetNames, filter_vars)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's better to use BOOST_(UN)EQUAL()
, BOOST_REQUIRE_(UN)EQUAL()
instead of BOOST_CHECK()
as Julian suggested in another PR of yours.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Doesn't work for vectors unfortunately.
in addition to literal strings. This is for sandboxed filters with some variables pre-set by the caller. They're "constant" in that scope, too.
…ct(s) for all objects
f52fbc0
to
687309e
Compare
687309e
to
191bf93
Compare
test/config-apply.cpp
Outdated
actualServiceNames.emplace_back(*s.first, *s.second); | ||
} | ||
|
||
BOOST_CHECK(actualServiceNames == services); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should also be possible to replace this with BOOST_CHECK_EQUAL_COLLECTIONS()
by implementing the output operator for the std::pair<String, String>
type.
template<>
struct boost::test_tools::tt_detail::print_log_value<std::pair<String, String>>
{
inline void operator()(std::ostream& os, const std::pair<String, String>& hs)
{
os << hs.first << "!" << hs.second;
}
};
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not bad! Please open a PR into my PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or push directly here. At your option.
…TIONS() to show the value diff in case of mismatch. Co-authored-by: Yonas Habteab <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As an optimisation of the object lookup for simple API filters targeting the Service
or/and Host
names LGTM! However, this is unlikely to fix the memory leak described in the community form, as we don't even know where it is leaking.
This is basically the same as
but for API filters, not for assign rules: