mirror of
https://github.com/apache/superset.git
synced 2024-09-16 10:39:55 -04:00
chore: Add statsd logger for ssh tunneling creation (#23225)
This commit is contained in:
parent
b479e93b49
commit
0a7016df2e
@ -17,6 +17,7 @@
|
|||||||
import logging
|
import logging
|
||||||
from typing import Any, Dict, List, Optional
|
from typing import Any, Dict, List, Optional
|
||||||
|
|
||||||
|
from flask import current_app
|
||||||
from flask_appbuilder.models.sqla import Model
|
from flask_appbuilder.models.sqla import Model
|
||||||
from marshmallow import ValidationError
|
from marshmallow import ValidationError
|
||||||
|
|
||||||
@ -42,6 +43,7 @@ from superset.exceptions import SupersetErrorsException
|
|||||||
from superset.extensions import db, event_logger, security_manager
|
from superset.extensions import db, event_logger, security_manager
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
stats_logger = current_app.config["STATS_LOGGER"]
|
||||||
|
|
||||||
|
|
||||||
class CreateDatabaseCommand(BaseCommand):
|
class CreateDatabaseCommand(BaseCommand):
|
||||||
@ -91,14 +93,14 @@ class CreateDatabaseCommand(BaseCommand):
|
|||||||
).run()
|
).run()
|
||||||
except (SSHTunnelInvalidError, SSHTunnelCreateFailedError) as ex:
|
except (SSHTunnelInvalidError, SSHTunnelCreateFailedError) as ex:
|
||||||
event_logger.log_with_context(
|
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],
|
engine=self._properties.get("sqlalchemy_uri", "").split(":")[0],
|
||||||
)
|
)
|
||||||
# So we can show the original message
|
# So we can show the original message
|
||||||
raise ex
|
raise ex
|
||||||
except Exception as ex:
|
except Exception as ex:
|
||||||
event_logger.log_with_context(
|
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],
|
engine=self._properties.get("sqlalchemy_uri", "").split(":")[0],
|
||||||
)
|
)
|
||||||
raise DatabaseCreateFailedError() from ex
|
raise DatabaseCreateFailedError() from ex
|
||||||
@ -111,6 +113,7 @@ class CreateDatabaseCommand(BaseCommand):
|
|||||||
)
|
)
|
||||||
|
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
|
||||||
except DAOCreateFailedError as ex:
|
except DAOCreateFailedError as ex:
|
||||||
db.session.rollback()
|
db.session.rollback()
|
||||||
event_logger.log_with_context(
|
event_logger.log_with_context(
|
||||||
@ -118,6 +121,10 @@ class CreateDatabaseCommand(BaseCommand):
|
|||||||
engine=database.db_engine_spec.__name__,
|
engine=database.db_engine_spec.__name__,
|
||||||
)
|
)
|
||||||
raise DatabaseCreateFailedError() from ex
|
raise DatabaseCreateFailedError() from ex
|
||||||
|
|
||||||
|
if ssh_tunnel:
|
||||||
|
stats_logger.incr("db_creation_success.ssh_tunnel")
|
||||||
|
|
||||||
return database
|
return database
|
||||||
|
|
||||||
def validate(self) -> None:
|
def validate(self) -> None:
|
||||||
|
Loading…
Reference in New Issue
Block a user