Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: improve analytics #11714

Merged
merged 9 commits into from
Nov 25, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -60,6 +60,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 @@ -205,6 +206,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 @@ -263,6 +265,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 @@ -333,6 +336,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 @@ -383,6 +387,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 @@ -440,6 +445,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 @@ -515,6 +521,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 @@ -602,6 +609,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 @@ -184,6 +184,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 @@ -246,6 +247,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 @@ -319,6 +321,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 @@ -369,6 +372,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 @@ -422,8 +426,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 @@ -479,8 +483,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 @@ -536,8 +540,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 @@ -617,6 +621,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 @@ -675,6 +680,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 @@ -181,6 +181,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 @@ -237,6 +238,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 @@ -307,6 +309,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 @@ -357,6 +360,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 @@ -432,6 +436,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 @@ -481,6 +486,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 @@ -539,6 +545,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