From 58a799975f2099493dd0d1ec31013f485d2ea93d Mon Sep 17 00:00:00 2001 From: hughhhh Date: Mon, 27 Feb 2023 17:57:05 -0500 Subject: [PATCH 1/3] add db creation action --- superset/databases/commands/create.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/superset/databases/commands/create.py b/superset/databases/commands/create.py index 0ed23549608de..3f84ef3ffaa46 100644 --- a/superset/databases/commands/create.py +++ b/superset/databases/commands/create.py @@ -91,14 +91,14 @@ def run(self) -> Model: ).run() except (SSHTunnelInvalidError, SSHTunnelCreateFailedError) as ex: event_logger.log_with_context( - action=f"db_creation_failed.{ex.__class__.__name__}", + action=f"db_creation_failed.{ex.__class__.__name__}.ssh_tunnel", engine=self._properties.get("sqlalchemy_uri", "").split(":")[0], ) # So we can show the original message raise ex except Exception as ex: event_logger.log_with_context( - action=f"db_creation_failed.{ex.__class__.__name__}", + action=f"db_creation_failed.{ex.__class__.__name__}.ssh_tunnel", engine=self._properties.get("sqlalchemy_uri", "").split(":")[0], ) raise DatabaseCreateFailedError() from ex @@ -111,6 +111,7 @@ def run(self) -> Model: ) db.session.commit() + except DAOCreateFailedError as ex: db.session.rollback() event_logger.log_with_context( @@ -118,6 +119,13 @@ def run(self) -> Model: engine=database.db_engine_spec.__name__, ) raise DatabaseCreateFailedError() from ex + + action_str = "db_creation_success.ssh_tunnel" if ssh_tunnel else "db_creation_success" + event_logger.log_with_context( + action=action_str, + engine=database.db_engine_spec.__name__, + ) + return database def validate(self) -> None: From fad4c22fb5001f4f8116a707d998e06df3f1cd3f Mon Sep 17 00:00:00 2001 From: hughhhh Date: Mon, 27 Feb 2023 18:08:44 -0500 Subject: [PATCH 2/3] remove event logger and just use statsd --- superset/databases/commands/create.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/superset/databases/commands/create.py b/superset/databases/commands/create.py index 3f84ef3ffaa46..c0ff30a660174 100644 --- a/superset/databases/commands/create.py +++ b/superset/databases/commands/create.py @@ -17,6 +17,7 @@ import logging from typing import Any, Dict, List, Optional +from flask import current_app from flask_appbuilder.models.sqla import Model from marshmallow import ValidationError @@ -42,7 +43,7 @@ from superset.extensions import db, event_logger, security_manager logger = logging.getLogger(__name__) - +stats_logger = current_app.config["STATS_LOGGER"] class CreateDatabaseCommand(BaseCommand): def __init__(self, data: Dict[str, Any]): @@ -120,11 +121,8 @@ def run(self) -> Model: ) raise DatabaseCreateFailedError() from ex - action_str = "db_creation_success.ssh_tunnel" if ssh_tunnel else "db_creation_success" - event_logger.log_with_context( - action=action_str, - engine=database.db_engine_spec.__name__, - ) + if ssh_tunnel: + stats_logger.incr("db_creation_success.ssh_tunnel") return database From e9616d8ce18e9b8e3f3a11e0c2793ba95a84c0ed Mon Sep 17 00:00:00 2001 From: hughhhh Date: Mon, 27 Feb 2023 18:25:50 -0500 Subject: [PATCH 3/3] black link --- superset/databases/commands/create.py | 1 + 1 file changed, 1 insertion(+) diff --git a/superset/databases/commands/create.py b/superset/databases/commands/create.py index c0ff30a660174..eb0582a980fca 100644 --- a/superset/databases/commands/create.py +++ b/superset/databases/commands/create.py @@ -45,6 +45,7 @@ logger = logging.getLogger(__name__) stats_logger = current_app.config["STATS_LOGGER"] + class CreateDatabaseCommand(BaseCommand): def __init__(self, data: Dict[str, Any]): self._properties = data.copy()