Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions superset/databases/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ def post(self) -> Response:
except DatabaseInvalidError as ex:
return self.response_422(message=ex.normalized_messages())
except DatabaseConnectionFailedError as ex:
logger.exception("Database connection failed")

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.

Can we downgrade these from exception logging? Connection failures are an expected part of setting up new database connections and shouldn't wind up in exception tracking systems.

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.

If you want to understand the reasons for failures, it would also be a good idea to log the exception. However, beware: these exceptions frequently contain database credentials, which it would be bad to track.

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.

Good point on the level. Just a note, @willbarrett: @logger.exception logs the full traceback plus the message, so it would've helped figuring out the reason.

@nytai nytai Feb 19, 2021

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.

logger.warning("Database connection failed", exc_info=True) also achieves the same. As the one currently running the error/exception logs portion of our biweekly alerts review, I would greatly appreciate if we reduced the amount of expected exceptions being logged at error and exception level. It would make my job significantly easier, as well as help reduce the strain on our log quota

@dpgaspar dpgaspar Feb 19, 2021

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 agree with @willbarrett concern, unfortunately some engines dbapi surface exceptions with sensitive information logger.warning("Database connection failed", exc_info=True) will actually log this info. we can lower it to debug, since on normal situations production systems are not set to this level.

Also there's an ongoing effort to remap these exceptions at the engine spec level #12869, so that we can add more granularity to connection failures for example

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'm now wondering if there's a better way to get the info that @betodealmeida and @hughhhh are looking for - would you be able to describe the questions that you're trying to answer with this logging? Then we can support you better in coming to a safe solution.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

We want to answer the following:
What db engines are failing the most?
What are the test connection and db connection exception error for these db engines?

If we can get this information with other data let us know

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.

What DB engines are failing the most?
I think you could parse the submitted SQLAlchemy URL to pull out the scheme portion of the URL and log that on failure. This would avoid the risk of capturing secure credentials.

What are the the test connection and DB connection exceptions for these engines?
Would it be sufficient to log the exception class from the engine without the message? The class will give you the category of error without including any of the potentially sensitive details. If this would work, you could more easily perform this logging from the command rather than in the endpoint.

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.

This is a great use case for statsd!

return self.response_422(message=str(ex))
except DatabaseCreateFailedError as ex:
logger.error(
Expand Down Expand Up @@ -607,6 +608,7 @@ def test_connection( # pylint: disable=too-many-return-statements
TestConnectionDatabaseCommand(g.user, item).run()
return self.response(200, message="OK")
except DatabaseTestConnectionFailedError as ex:
logger.exception("Database test connection failed")
return self.response_422(message=str(ex))

@expose("/<int:pk>/related_objects/", methods=["GET"])
Expand Down