-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
fix(cli) prefix Cassandra connector errors in new DAO #3648
Conversation
538bf78
to
d20193e
Compare
return nil, prefix_err(self, err) | ||
end | ||
|
||
return ok |
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.
considering the repetitive nature of this error checking, could we do something like:
local function prefix_err(self, ok, err, ...)
if not ok then
return ok, "[" .. self.strategy .. " error] " .. err
end
return ok, err, ...
end
-- and calling it here (and in other places) as:
return prefix_err(self, self.connector:truncate())
can probably be cleaner if exporting prefix_err
as well
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.
Considered it, but I don't want to introduce the extra cost of calling a variadic function on every call of the connector's functions. Five occurrences, and it is unlikely that we add more methods to the connector, is not that repetitive is what I told myself.
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 thought so 😄
d20193e
to
3e3c622
Compare
Since recently, we call the new DAO's `assert(db:init_connector())` in the CLI _before_ instantiating the old DAO (because the latter needs the former as an attribute). For Cassandra, this has the effect of retrieving the cluster's topology, and thus trying to connect to the given contact points. If any error is encountered, the new DAO does not properly prefix the error with the `[Cassandra error]` prefix, as the old DAO would do. This goes unnoticed for the PostgreSQL strategy since the connector initialization is nopping. See a related CI failure here: https://travis-ci.com/Kong/kong-private/jobs/136391637#L1094 We now prefix connector errors (which are always strings).
3e3c622
to
dc9857e
Compare
@@ -81,6 +83,7 @@ function DB.new(kong_config, strategy) | |||
daos = daos, -- each of those has the connector singleton | |||
strategies = strategies, | |||
connector = connector, | |||
strategy = strategy, |
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 had the exact same change done in my codebase here as I work on the Plugins entity. :) We really need to start making smaller PRs with this little "minor tweaks" as we work through major changes!
Thank you all for taking a look |
Since recently, we call the new DAO's
assert(db:init_connector())
inthe CLI before instantiating the old DAO (because the latter needs the
former as an attribute).
For Cassandra, this has the effect of retrieving the cluster's topology,
and thus trying to connect to the given contact points. If any error is
encountered, the new DAO does not properly prefix the error with the
[Cassandra error]
prefix, as the old DAO would do. This goes unnoticedfor the PostgreSQL strategy since the connector initialization is
nopping.
See a related CI failure here:
https://travis-ci.com/Kong/kong-private/jobs/136391637#L1094
We now prefix connector errors (which are always strings). We also include the strategy in the reported error, as it should have always been, but was missing due to the lack of second argument (it is optional) when calling the
DB.new()
function from the tests.