Skip to content

Commit

Permalink
chore: improve analytics (#11714)
Browse files Browse the repository at this point in the history
* chore: improve analytics

* lint

* log more events, add note in UPDATING.md

* handling base class

* more events\!

* get ref through

* right before @expose

* fix context

* touchups
  • Loading branch information
mistercrunch authored Nov 25, 2020
1 parent 9215a31 commit 0504cf1
Show file tree
Hide file tree
Showing 13 changed files with 229 additions and 50 deletions.
5 changes: 4 additions & 1 deletion UPDATING.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ assists people when migrating to a new version.
## Next

- [11704](https://github.com/apache/incubator-superset/pull/11704) Breaking change: Jinja templating for SQL queries has been updated, removing default modules such as `datetime` and `random` and enforcing static template values. To restore or extend functionality, use `JINJA_CONTEXT_ADDONS` and `CUSTOM_TEMPLATE_PROCESSORS` in `superset_config.py`.

- [11714](https://github.com/apache/incubator-superset/pull/11714): Logs
significantly more analytics events (roughly double?), and when
using DBEventLogger (default) could result in stressing the metadata
database more.
- [11509](https://github.com/apache/incubator-superset/pull/11509): Config value `TABLE_NAMES_CACHE_CONFIG` has been renamed to `DATA_CACHE_CONFIG`, which will now also hold query results cache from connected datasources (previously held in `CACHE_CONFIG`), in addition to the table names. If you will set `DATA_CACHE_CONFIG` to a new cache backend different than your previous `CACHE_CONFIG`, plan for additional cache warmup to avoid degrading charting performance for the end users.

- [11575](https://github.com/apache/incubator-superset/pull/11575) The Row Level Security (RLS) config flag has been moved to a feature flag. To migrate, add `ROW_LEVEL_SECURITY: True` to the `FEATURE_FLAGS` dict in `superset_config.py`.
Expand Down
5 changes: 5 additions & 0 deletions superset/annotation_layers/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
openapi_spec_methods_override,
)
from superset.constants import RouteMethod
from superset.extensions import event_logger
from superset.models.annotations import AnnotationLayer
from superset.views.base_api import BaseSupersetModelRestApi, statsd_metrics

Expand Down Expand Up @@ -110,6 +111,7 @@ class AnnotationLayerRestApi(BaseSupersetModelRestApi):
@safe
@statsd_metrics
@permission_name("delete")
@event_logger.log_this_with_context(log_to_statsd=False)
def delete(self, pk: int) -> Response:
"""Delete an annotation layer
---
Expand Down Expand Up @@ -159,6 +161,7 @@ def delete(self, pk: int) -> Response:
@safe
@statsd_metrics
@permission_name("post")
@event_logger.log_this_with_context(log_to_statsd=False)
def post(self) -> Response:
"""Creates a new Annotation Layer
---
Expand Down Expand Up @@ -218,6 +221,7 @@ def post(self) -> Response:
@safe
@statsd_metrics
@permission_name("put")
@event_logger.log_this_with_context(log_to_statsd=False)
def put(self, pk: int) -> Response:
"""Updates an Annotation Layer
---
Expand Down Expand Up @@ -284,6 +288,7 @@ def put(self, pk: int) -> Response:
@safe
@statsd_metrics
@rison(get_delete_ids_schema)
@event_logger.log_this_with_context(log_to_statsd=False)
def bulk_delete(self, **kwargs: Any) -> Response:
"""Delete bulk Annotation layers
---
Expand Down
2 changes: 1 addition & 1 deletion superset/cachekeys/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ class CacheRestApi(BaseSupersetModelRestApi):
openapi_spec_component_schemas = (CacheInvalidationRequestSchema,)

@expose("/invalidate", methods=["POST"])
@event_logger.log_this
@protect()
@safe
@statsd_metrics
@event_logger.log_this_with_context(log_to_statsd=False)
def invalidate(self) -> Response:
"""
Takes a list of datasources, finds the associated cache records and
Expand Down
11 changes: 10 additions & 1 deletion superset/charts/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ def __init__(self) -> None:
@protect()
@safe
@statsd_metrics
@event_logger.log_this_with_context(log_to_statsd=False)
def post(self) -> Response:
"""Creates a new Chart
---
Expand Down Expand Up @@ -270,6 +271,7 @@ def post(self) -> Response:
@protect()
@safe
@statsd_metrics
@event_logger.log_this_with_context(log_to_statsd=False)
def put(self, pk: int) -> Response:
"""Changes a Chart
---
Expand Down Expand Up @@ -343,6 +345,7 @@ def put(self, pk: int) -> Response:
@protect()
@safe
@statsd_metrics
@event_logger.log_this_with_context(log_to_statsd=False)
def delete(self, pk: int) -> Response:
"""Deletes a Chart
---
Expand Down Expand Up @@ -393,6 +396,7 @@ def delete(self, pk: int) -> Response:
@safe
@statsd_metrics
@rison(get_delete_ids_schema)
@event_logger.log_this_with_context(log_to_statsd=False)
def bulk_delete(self, **kwargs: Any) -> Response:
"""Delete bulk Charts
---
Expand Down Expand Up @@ -444,10 +448,10 @@ def bulk_delete(self, **kwargs: Any) -> Response:
return self.response_422(message=str(ex))

@expose("/data", methods=["POST"])
@event_logger.log_this
@protect()
@safe
@statsd_metrics
@event_logger.log_this_with_context(log_to_statsd=False)
def data(self) -> Response:
"""
Takes a query context constructed in the client and returns payload
Expand Down Expand Up @@ -532,6 +536,7 @@ def data(self) -> Response:
@rison(screenshot_query_schema)
@safe
@statsd_metrics
@event_logger.log_this_with_context(log_to_statsd=False)
def cache_screenshot(self, pk: int, **kwargs: Dict[str, bool]) -> WerkzeugResponse:
"""
---
Expand Down Expand Up @@ -604,6 +609,7 @@ def trigger_celery() -> WerkzeugResponse:
@rison(screenshot_query_schema)
@safe
@statsd_metrics
@event_logger.log_this_with_context(log_to_statsd=False)
def screenshot(self, pk: int, digest: str) -> WerkzeugResponse:
"""Get Chart screenshot
---
Expand Down Expand Up @@ -657,6 +663,7 @@ def screenshot(self, pk: int, digest: str) -> WerkzeugResponse:
@rison(thumbnail_query_schema)
@safe
@statsd_metrics
@event_logger.log_this_with_context(log_to_statsd=False)
def thumbnail(
self, pk: int, digest: str, **kwargs: Dict[str, bool]
) -> WerkzeugResponse:
Expand Down Expand Up @@ -730,6 +737,7 @@ def thumbnail(
@safe
@statsd_metrics
@rison(get_export_ids_schema)
@event_logger.log_this_with_context(log_to_statsd=False)
def export(self, **kwargs: Any) -> Response:
"""Export charts
---
Expand Down Expand Up @@ -787,6 +795,7 @@ def export(self, **kwargs: Any) -> Response:
@safe
@statsd_metrics
@rison(get_fav_star_ids_schema)
@event_logger.log_this_with_context(log_to_statsd=False)
def favorite_status(self, **kwargs: Any) -> Response:
"""Favorite stars for Charts
---
Expand Down
2 changes: 2 additions & 0 deletions superset/css_templates/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
get_delete_ids_schema,
openapi_spec_methods_override,
)
from superset.extensions import event_logger
from superset.models.core import CssTemplate
from superset.views.base_api import BaseSupersetModelRestApi, statsd_metrics

Expand Down Expand Up @@ -87,6 +88,7 @@ class CssTemplateRestApi(BaseSupersetModelRestApi):
@safe
@statsd_metrics
@rison(get_delete_ids_schema)
@event_logger.log_this_with_context(log_to_statsd=False)
def bulk_delete(self, **kwargs: Any) -> Response:
"""Delete bulk CSS Templates
---
Expand Down
8 changes: 8 additions & 0 deletions superset/dashboards/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
openapi_spec_methods_override,
thumbnail_query_schema,
)
from superset.extensions import event_logger
from superset.models.dashboard import Dashboard
from superset.tasks.thumbnails import cache_dashboard_thumbnail
from superset.utils.screenshots import DashboardScreenshot
Expand Down Expand Up @@ -209,6 +210,7 @@ def __init__(self) -> None:
@protect()
@safe
@statsd_metrics
@event_logger.log_this_with_context(log_to_statsd=False)
def post(self) -> Response:
"""Creates a new Dashboard
---
Expand Down Expand Up @@ -267,6 +269,7 @@ def post(self) -> Response:
@protect()
@safe
@statsd_metrics
@event_logger.log_this_with_context(log_to_statsd=False)
def put(self, pk: int) -> Response:
"""Changes a Dashboard
---
Expand Down Expand Up @@ -337,6 +340,7 @@ def put(self, pk: int) -> Response:
@protect()
@safe
@statsd_metrics
@event_logger.log_this_with_context(log_to_statsd=False)
def delete(self, pk: int) -> Response:
"""Deletes a Dashboard
---
Expand Down Expand Up @@ -387,6 +391,7 @@ def delete(self, pk: int) -> Response:
@safe
@statsd_metrics
@rison(get_delete_ids_schema)
@event_logger.log_this_with_context(log_to_statsd=False)
def bulk_delete(self, **kwargs: Any) -> Response:
"""Delete bulk Dashboards
---
Expand Down Expand Up @@ -444,6 +449,7 @@ def bulk_delete(self, **kwargs: Any) -> Response:
@safe
@statsd_metrics
@rison(get_export_ids_schema)
@event_logger.log_this_with_context(log_to_statsd=False)
def export(self, **kwargs: Any) -> Response:
"""Export dashboards
---
Expand Down Expand Up @@ -519,6 +525,7 @@ def export(self, **kwargs: Any) -> Response:
@protect()
@safe
@rison(thumbnail_query_schema)
@event_logger.log_this_with_context(log_to_statsd=False)
def thumbnail(
self, pk: int, digest: str, **kwargs: Dict[str, bool]
) -> WerkzeugResponse:
Expand Down Expand Up @@ -606,6 +613,7 @@ def thumbnail(
@safe
@statsd_metrics
@rison(get_fav_star_ids_schema)
@event_logger.log_this_with_context(log_to_statsd=False)
def favorite_status(self, **kwargs: Any) -> Response:
"""Favorite Stars for Dashboards
---
Expand Down
12 changes: 9 additions & 3 deletions superset/databases/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ class DatabaseRestApi(BaseSupersetModelRestApi):
@protect()
@safe
@statsd_metrics
@event_logger.log_this_with_context(log_to_statsd=False)
def post(self) -> Response:
"""Creates a new Database
---
Expand Down Expand Up @@ -247,6 +248,7 @@ def post(self) -> Response:
@protect()
@safe
@statsd_metrics
@event_logger.log_this_with_context(log_to_statsd=False)
def put( # pylint: disable=too-many-return-statements, arguments-differ
self, pk: int
) -> Response:
Expand Down Expand Up @@ -320,6 +322,7 @@ def put( # pylint: disable=too-many-return-statements, arguments-differ
@protect()
@safe
@statsd_metrics
@event_logger.log_this_with_context(log_to_statsd=False)
def delete(self, pk: int) -> Response: # pylint: disable=arguments-differ
"""Deletes a Database
---
Expand Down Expand Up @@ -370,6 +373,7 @@ def delete(self, pk: int) -> Response: # pylint: disable=arguments-differ
@safe
@rison(database_schemas_query_schema)
@statsd_metrics
@event_logger.log_this_with_context(log_to_statsd=False)
def schemas(self, pk: int, **kwargs: Any) -> FlaskResponse:
"""Get all schemas from a database
---
Expand Down Expand Up @@ -423,8 +427,8 @@ def schemas(self, pk: int, **kwargs: Any) -> FlaskResponse:
@protect()
@check_datasource_access
@safe
@event_logger.log_this
@statsd_metrics
@event_logger.log_this_with_context(log_to_statsd=False)
def table_metadata(
self, database: Database, table_name: str, schema_name: str
) -> FlaskResponse:
Expand Down Expand Up @@ -480,8 +484,8 @@ def table_metadata(
@protect()
@check_datasource_access
@safe
@event_logger.log_this
@statsd_metrics
@event_logger.log_this_with_context(log_to_statsd=False)
def select_star(
self, database: Database, table_name: str, schema_name: Optional[str] = None
) -> FlaskResponse:
Expand Down Expand Up @@ -537,8 +541,8 @@ def select_star(
@expose("/test_connection", methods=["POST"])
@protect()
@safe
@event_logger.log_this
@statsd_metrics
@event_logger.log_this_with_context(log_to_statsd=False)
def test_connection( # pylint: disable=too-many-return-statements
self,
) -> FlaskResponse:
Expand Down Expand Up @@ -618,6 +622,7 @@ def test_connection( # pylint: disable=too-many-return-statements
@protect()
@safe
@statsd_metrics
@event_logger.log_this_with_context(log_to_statsd=False)
def related_objects(self, pk: int) -> Response:
"""Get charts and dashboards count associated to a database
---
Expand Down Expand Up @@ -676,6 +681,7 @@ def related_objects(self, pk: int) -> Response:
@safe
@statsd_metrics
@rison(get_export_ids_schema)
@event_logger.log_this_with_context(log_to_statsd=False)
def export(self, **kwargs: Any) -> Response:
"""Export database(s) with associated datasets
---
Expand Down
9 changes: 8 additions & 1 deletion superset/datasets/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
from flask_babel import ngettext
from marshmallow import ValidationError

from superset import is_feature_enabled
from superset import event_logger, is_feature_enabled
from superset.commands.exceptions import CommandInvalidError
from superset.connectors.sqla.models import SqlaTable
from superset.constants import RouteMethod
Expand Down Expand Up @@ -182,6 +182,7 @@ class DatasetRestApi(BaseSupersetModelRestApi):
@protect()
@safe
@statsd_metrics
@event_logger.log_this_with_context(log_to_statsd=False)
def post(self) -> Response:
"""Creates a new Dataset
---
Expand Down Expand Up @@ -238,6 +239,7 @@ def post(self) -> Response:
@protect()
@safe
@statsd_metrics
@event_logger.log_this_with_context(log_to_statsd=False)
def put(self, pk: int) -> Response:
"""Changes a Dataset
---
Expand Down Expand Up @@ -308,6 +310,7 @@ def put(self, pk: int) -> Response:
@protect()
@safe
@statsd_metrics
@event_logger.log_this_with_context(log_to_statsd=False)
def delete(self, pk: int) -> Response:
"""Deletes a Dataset
---
Expand Down Expand Up @@ -358,6 +361,7 @@ def delete(self, pk: int) -> Response:
@safe
@statsd_metrics
@rison(get_export_ids_schema)
@event_logger.log_this_with_context(log_to_statsd=False)
def export(self, **kwargs: Any) -> Response:
"""Export datasets
---
Expand Down Expand Up @@ -433,6 +437,7 @@ def export(self, **kwargs: Any) -> Response:
@protect()
@safe
@statsd_metrics
@event_logger.log_this_with_context(log_to_statsd=False)
def refresh(self, pk: int) -> Response:
"""Refresh a Dataset
---
Expand Down Expand Up @@ -482,6 +487,7 @@ def refresh(self, pk: int) -> Response:
@protect()
@safe
@statsd_metrics
@event_logger.log_this_with_context(log_to_statsd=False)
def related_objects(self, pk: int) -> Response:
"""Get charts and dashboards count associated to a dataset
---
Expand Down Expand Up @@ -540,6 +546,7 @@ def related_objects(self, pk: int) -> Response:
@safe
@statsd_metrics
@rison(get_delete_ids_schema)
@event_logger.log_this_with_context(log_to_statsd=False)
def bulk_delete(self, **kwargs: Any) -> Response:
"""Delete bulk Datasets
---
Expand Down
Loading

0 comments on commit 0504cf1

Please sign in to comment.