You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by hu...@apache.org on 2021/03/04 21:14:16 UTC

[superset] branch hugh/use-event-db created (now f9d5f3f)

This is an automated email from the ASF dual-hosted git repository.

hugh pushed a change to branch hugh/use-event-db
in repository https://gitbox.apache.org/repos/asf/superset.git.


      at f9d5f3f  add logs to test_connection

This branch includes the following new commits:

     new 2d05a37  add logs to database/create
     new f9d5f3f  add logs to test_connection

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



[superset] 02/02: add logs to test_connection

Posted by hu...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

hugh pushed a commit to branch hugh/use-event-db
in repository https://gitbox.apache.org/repos/asf/superset.git

commit f9d5f3f2d9166db05a5aa505efc05978beae818d
Author: hughhhh <hu...@gmail.com>
AuthorDate: Thu Mar 4 16:13:12 2021 -0500

    add logs to test_connection
---
 superset/databases/commands/test_connection.py | 53 +++++++++++++++++++-------
 1 file changed, 39 insertions(+), 14 deletions(-)

diff --git a/superset/databases/commands/test_connection.py b/superset/databases/commands/test_connection.py
index d35d07a..0123bf7 100644
--- a/superset/databases/commands/test_connection.py
+++ b/superset/databases/commands/test_connection.py
@@ -32,6 +32,7 @@ from superset.databases.commands.exceptions import (
 )
 from superset.databases.dao import DatabaseDAO
 from superset.exceptions import SupersetSecurityException
+from superset.extensions import event_logger
 from superset.models.core import Database
 
 logger = logging.getLogger(__name__)
@@ -55,25 +56,49 @@ class TestConnectionDatabaseCommand(BaseCommand):
                 impersonate_user=self._properties.get("impersonate_user", False),
                 encrypted_extra=self._properties.get("encrypted_extra", "{}"),
             )
-            if database is not None:
-                database.set_sqlalchemy_uri(uri)
-                database.db_engine_spec.mutate_db_for_connection_test(database)
-                username = self._actor.username if self._actor is not None else None
-                engine = database.get_sqla_engine(user_name=username)
+            if database is None:
+                raise DBAPIError("Database is not found", None, None)
+
+            database.set_sqlalchemy_uri(uri)
+            database.db_engine_spec.mutate_db_for_connection_test(database)
+            username = self._actor.username if self._actor is not None else None
+            engine = database.get_sqla_engine(user_name=username)
             with closing(engine.raw_connection()) as conn:
                 if not engine.dialect.do_ping(conn):
                     raise DBAPIError(None, None, None)
-        except (NoSuchModuleError, ModuleNotFoundError):
+
+            with event_logger(
+                action="test_connection_success", engine=make_url(uri).drivername
+            ):
+                pass
+
+        except (NoSuchModuleError, ModuleNotFoundError) as ex:
             driver_name = make_url(uri).drivername
-            raise DatabaseTestConnectionDriverError(
-                message=_("Could not load database driver: {}").format(driver_name),
-            )
-        except DBAPIError:
-            raise DatabaseTestConnectionFailedError()
+            with event_logger(
+                action=f"test_connection_error.{ex.__class__.__name__}",
+                engine=make_url(uri).drivername,
+            ):
+                raise DatabaseTestConnectionDriverError(
+                    message=_("Could not load database driver: {}").format(driver_name),
+                )
+        except DBAPIError as ex:
+            with event_logger(
+                action=f"test_connection_error.{ex.__class__.__name__}",
+                engine=make_url(uri).drivername,
+            ):
+                raise DatabaseTestConnectionFailedError()
         except SupersetSecurityException as ex:
-            raise DatabaseSecurityUnsafeError(message=str(ex))
-        except Exception:
-            raise DatabaseTestConnectionUnexpectedError()
+            with event_logger(
+                action=f"test_connection_error.{ex.__class__.__name__}",
+                engine=make_url(uri).drivername,
+            ):
+                raise DatabaseSecurityUnsafeError(message=str(ex))
+        except Exception as ex:
+            with event_logger(
+                action=f"test_connection_error.{ex.__class__.__name__}",
+                engine=make_url(uri).drivername,
+            ):
+                raise DatabaseTestConnectionUnexpectedError()
 
     def validate(self) -> None:
         database_name = self._properties.get("database_name")


[superset] 01/02: add logs to database/create

Posted by hu...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

hugh pushed a commit to branch hugh/use-event-db
in repository https://gitbox.apache.org/repos/asf/superset.git

commit 2d05a37d94bbaa2eb0e15fc722342f452dde1dc7
Author: hughhhh <hu...@gmail.com>
AuthorDate: Thu Mar 4 15:50:51 2021 -0500

    add logs to database/create
---
 superset/databases/commands/create.py | 20 ++++++++++++++------
 1 file changed, 14 insertions(+), 6 deletions(-)

diff --git a/superset/databases/commands/create.py b/superset/databases/commands/create.py
index c438444..dbc0940 100644
--- a/superset/databases/commands/create.py
+++ b/superset/databases/commands/create.py
@@ -32,7 +32,7 @@ from superset.databases.commands.exceptions import (
 )
 from superset.databases.commands.test_connection import TestConnectionDatabaseCommand
 from superset.databases.dao import DatabaseDAO
-from superset.extensions import db, security_manager
+from superset.extensions import db, event_logger, security_manager
 
 logger = logging.getLogger(__name__)
 
@@ -51,8 +51,12 @@ class CreateDatabaseCommand(BaseCommand):
             try:
                 TestConnectionDatabaseCommand(self._actor, self._properties).run()
             except Exception:
-                db.session.rollback()
-                raise DatabaseConnectionFailedError()
+                with event_logger.log_context(
+                    action="db_connection_failed",
+                    engine=database.db_engine_spec.__name__,
+                ):
+                    db.session.rollback()
+                    raise DatabaseConnectionFailedError()
 
             # adding a new database we always want to force refresh schema list
             schemas = database.get_all_schema_names(cache=False)
@@ -63,8 +67,11 @@ class CreateDatabaseCommand(BaseCommand):
             security_manager.add_permission_view_menu("database_access", database.perm)
             db.session.commit()
         except DAOCreateFailedError as ex:
-            logger.exception(ex.exception)
-            raise DatabaseCreateFailedError()
+            with event_logger.log_context(
+                action=f"db_creation_failed.{ex.exception}",
+                engine=database.db_engine_spec.__name__,
+            ):
+                raise DatabaseCreateFailedError()
         return database
 
     def validate(self) -> None:
@@ -84,4 +91,5 @@ class CreateDatabaseCommand(BaseCommand):
         if exceptions:
             exception = DatabaseInvalidError()
             exception.add_list(exceptions)
-            raise exception
+            with event_logger.log_context(action="db_connection_failed"):
+                raise exception