Skip to content

Commit

Permalink
chore: Add statsd logger for ssh tunneling creation (#23225)
Browse files Browse the repository at this point in the history
  • Loading branch information
hughhhh committed Feb 28, 2023
1 parent b479e93 commit 0a7016d
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions superset/databases/commands/create.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -42,6 +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):
Expand Down Expand Up @@ -91,14 +93,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
Expand All @@ -111,13 +113,18 @@ def run(self) -> Model:
)

db.session.commit()

except DAOCreateFailedError as ex:
db.session.rollback()
event_logger.log_with_context(
action=f"db_creation_failed.{ex.__class__.__name__}",
engine=database.db_engine_spec.__name__,
)
raise DatabaseCreateFailedError() from ex

if ssh_tunnel:
stats_logger.incr("db_creation_success.ssh_tunnel")

return database

def validate(self) -> None:
Expand Down

0 comments on commit 0a7016d

Please sign in to comment.