Skip to content
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

Merged
merged 1 commit into from Jul 27, 2018

Conversation

thibaultcha
Copy link
Member

@thibaultcha thibaultcha commented Jul 26, 2018

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). 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.

@thibaultcha thibaultcha changed the title fix(cli) ensure Cassandra errors are prefixed fix(cli) prefix Cassandra connector errors in new DAO Jul 26, 2018
return nil, prefix_err(self, err)
end

return ok
Copy link
Member

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

Copy link
Member Author

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.

Copy link
Member

Choose a reason for hiding this comment

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

I thought so 😄

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).
@@ -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,
Copy link
Contributor

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!

@thibaultcha thibaultcha merged commit 9f5102f into master Jul 27, 2018
@thibaultcha thibaultcha deleted the fix/db-prefix-err branch July 27, 2018 15:21
@thibaultcha
Copy link
Member Author

Thank you all for taking a look

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.

None yet

5 participants