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
dnsdist: Add UUIDs to rules #6030
Conversation
6c19262
to
c3700a0
Compare
c3700a0
to
770f828
Compare
770f828
to
922c7dc
Compare
Having UUID assigned to rules makes it possible to track a given rule, as opposed to the existing rule numbers that changed everytime a rule was deleted or moved around. A rule now keeps the same UUID for the lifetime of the dnsdist process and can even keep this UUID persistent across restart if the UUID is provided when the rule is added: ``` addAction(AllRule(), AllowAction(), {uuid="123e4567-e89b-12d3-a456-426655440000"}) ``` This is especially useful if the rules are managed via a central controller using the console, or to display metrics retrieved via the API.
922c7dc
to
4d5959e
Compare
pdns/dnsdist-lua-rules.cc
Outdated
@@ -892,32 +892,76 @@ std::shared_ptr<DNSRule> makeRule(const luadnsrule_t& var) | |||
return std::make_shared<NetmaskGroupRule>(nmg, true); | |||
} | |||
|
|||
static boost::uuids::uuid getRuleID(std::string& id) |
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.
get...
for something that also makes something out of thin air sounds wrong to me. Weak suggestion: makeRuleID
pdns/dnsdist-lua-rules.cc
Outdated
} | ||
}); | ||
|
||
g_lua.writeFunction("rmResponseRule", [](unsigned int num) { | ||
g_lua.writeFunction("rmResponseRule", [](boost::variant<unsigned int, std::string> num) { |
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.
rename num
to id
as done in the help strings?
pdns/dnsdist-lua-rules.cc
Outdated
rules.erase(std::remove_if(rules.begin(), | ||
rules.end(), | ||
[uuid](const DNSDistResponseRuleAction& a) { return a.d_id == uuid; }), | ||
rules.end()); |
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 now no feedback if no rule matches, right?
auto rule=makeRule(dnsrule); | ||
return std::make_shared<std::pair< luadnsrule_t, std::shared_ptr<DNSAction> > >(rule, action); | ||
DNSDistRuleAction ra({rule, action, uuid}); | ||
return std::make_shared<DNSDistRuleAction>(ra); |
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.
the given uuid is not checked against uniqueness, right?
|
||
boost_required_version=1.42 |
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.
maybe add a comment on why? (before someone puts back the old code...)
@@ -187,9 +187,10 @@ JSON Objects | |||
|
|||
:property string action: The action taken when the rule matches (e.g. "to pool abuse") | |||
:property dict action-stats: A list of statistics whose content varies depending on the kind of rule | |||
:property integer id: The identifier (or order) of this rule | |||
:property integer id: The order of this rule |
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.
s/order/position/?
FTR, my comments are mostly nits and can be fixed later. I'd welcome a merge soon, so I can rebase my then conflicted PRs. Would also prepare a followup PR to clean up some of the nits. |
Also did a lightweight test of it. |
c5a59af
to
dcdc32c
Compare
I've added cherry-pickable commits that should fix most of my nits, plus one that adds the new optional argument to addLua(Response)Action. |
Mergeable when green on Travis. |
Short description
Having UUID assigned to rules makes it possible to track a given rule, as opposed to the existing rule numbers that changed every time a rule was deleted or moved around. A rule now keeps the same UUID for the lifetime of the dnsdist process and can even keep this UUID persistent across restart if the UUID is provided when the rule is added:
This is especially useful if the rules are managed via a central controller using the console, or to display metrics retrieved via the API.
Checklist
I have: