Skip to content

Commit

Permalink
fix context
Browse files Browse the repository at this point in the history
  • Loading branch information
mistercrunch committed Nov 24, 2020
1 parent b03b59e commit aab4d2d
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 45 deletions.
8 changes: 4 additions & 4 deletions superset/annotation_layers/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ class AnnotationLayerRestApi(BaseSupersetModelRestApi):
@safe
@statsd_metrics
@permission_name("delete")
@event_logger.log_this
@event_logger.log_this_with_context(log_to_statsd=False)
def delete(self, pk: int) -> Response:
"""Delete an annotation layer
---
Expand Down Expand Up @@ -161,7 +161,7 @@ def delete(self, pk: int) -> Response:
@safe
@statsd_metrics
@permission_name("post")
@event_logger.log_this
@event_logger.log_this_with_context(log_to_statsd=False)
def post(self) -> Response:
"""Creates a new Annotation Layer
---
Expand Down Expand Up @@ -221,7 +221,7 @@ def post(self) -> Response:
@safe
@statsd_metrics
@permission_name("put")
@event_logger.log_this
@event_logger.log_this_with_context(log_to_statsd=False)
def put(self, pk: int) -> Response:
"""Updates an Annotation Layer
---
Expand Down Expand Up @@ -288,7 +288,7 @@ def put(self, pk: int) -> Response:
@safe
@statsd_metrics
@rison(get_delete_ids_schema)
@event_logger.log_this
@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
20 changes: 10 additions & 10 deletions superset/charts/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ def __init__(self) -> None:
@protect()
@safe
@statsd_metrics
@event_logger.log_this
@event_logger.log_this_with_context(log_to_statsd=False)
def post(self) -> Response:
"""Creates a new Chart
---
Expand Down Expand Up @@ -271,7 +271,7 @@ def post(self) -> Response:
@protect()
@safe
@statsd_metrics
@event_logger.log_this
@event_logger.log_this_with_context(log_to_statsd=False)
def put(self, pk: int) -> Response:
"""Changes a Chart
---
Expand Down Expand Up @@ -345,7 +345,7 @@ def put(self, pk: int) -> Response:
@protect()
@safe
@statsd_metrics
@event_logger.log_this
@event_logger.log_this_with_context(log_to_statsd=False)
def delete(self, pk: int) -> Response:
"""Deletes a Chart
---
Expand Down Expand Up @@ -396,7 +396,7 @@ def delete(self, pk: int) -> Response:
@safe
@statsd_metrics
@rison(get_delete_ids_schema)
@event_logger.log_this
@event_logger.log_this_with_context(log_to_statsd=False)
def bulk_delete(self, **kwargs: Any) -> Response:
"""Delete bulk Charts
---
Expand Down Expand Up @@ -448,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 @@ -536,7 +536,7 @@ def data(self) -> Response:
@rison(screenshot_query_schema)
@safe
@statsd_metrics
@event_logger.log_this
@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 @@ -609,7 +609,7 @@ def trigger_celery() -> WerkzeugResponse:
@rison(screenshot_query_schema)
@safe
@statsd_metrics
@event_logger.log_this
@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 @@ -663,7 +663,7 @@ def screenshot(self, pk: int, digest: str) -> WerkzeugResponse:
@rison(thumbnail_query_schema)
@safe
@statsd_metrics
@event_logger.log_this
@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 @@ -737,7 +737,7 @@ def thumbnail(
@safe
@statsd_metrics
@rison(get_export_ids_schema)
@event_logger.log_this
@event_logger.log_this_with_context(log_to_statsd=False)
def export(self, **kwargs: Any) -> Response:
"""Export charts
---
Expand Down Expand Up @@ -795,7 +795,7 @@ def export(self, **kwargs: Any) -> Response:
@safe
@statsd_metrics
@rison(get_fav_star_ids_schema)
@event_logger.log_this
@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: 1 addition & 1 deletion superset/css_templates/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ class CssTemplateRestApi(BaseSupersetModelRestApi):
@safe
@statsd_metrics
@rison(get_delete_ids_schema)
@event_logger.log_this
@event_logger.log_this_with_context(log_to_statsd=False)
def bulk_delete(self, **kwargs: Any) -> Response:
"""Delete bulk CSS Templates
---
Expand Down
14 changes: 7 additions & 7 deletions superset/dashboards/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ def __init__(self) -> None:
@protect()
@safe
@statsd_metrics
@event_logger.log_this
@event_logger.log_this_with_context(log_to_statsd=False)
def post(self) -> Response:
"""Creates a new Dashboard
---
Expand Down Expand Up @@ -265,7 +265,7 @@ def post(self) -> Response:
@protect()
@safe
@statsd_metrics
@event_logger.log_this
@event_logger.log_this_with_context(log_to_statsd=False)
def put(self, pk: int) -> Response:
"""Changes a Dashboard
---
Expand Down Expand Up @@ -336,7 +336,7 @@ def put(self, pk: int) -> Response:
@protect()
@safe
@statsd_metrics
@event_logger.log_this
@event_logger.log_this_with_context(log_to_statsd=False)
def delete(self, pk: int) -> Response:
"""Deletes a Dashboard
---
Expand Down Expand Up @@ -387,7 +387,7 @@ def delete(self, pk: int) -> Response:
@safe
@statsd_metrics
@rison(get_delete_ids_schema)
@event_logger.log_this
@event_logger.log_this_with_context(log_to_statsd=False)
def bulk_delete(self, **kwargs: Any) -> Response:
"""Delete bulk Dashboards
---
Expand Down Expand Up @@ -445,7 +445,7 @@ def bulk_delete(self, **kwargs: Any) -> Response:
@safe
@statsd_metrics
@rison(get_export_ids_schema)
@event_logger.log_this
@event_logger.log_this_with_context(log_to_statsd=False)
def export(self, **kwargs: Any) -> Response:
"""Export dashboards
---
Expand Down Expand Up @@ -521,7 +521,7 @@ def export(self, **kwargs: Any) -> Response:
@protect()
@safe
@rison(thumbnail_query_schema)
@event_logger.log_this
@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 @@ -609,7 +609,7 @@ def thumbnail(
@safe
@statsd_metrics
@rison(get_fav_star_ids_schema)
@event_logger.log_this
@event_logger.log_this_with_context(log_to_statsd=False)
def favorite_status(self, **kwargs: Any) -> Response:
"""Favorite Stars for Dashboards
---
Expand Down
18 changes: 9 additions & 9 deletions superset/databases/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ class DatabaseRestApi(BaseSupersetModelRestApi):
@protect()
@safe
@statsd_metrics
@event_logger.log_this
@event_logger.log_this_with_context(log_to_statsd=False)
def post(self) -> Response:
"""Creates a new Database
---
Expand Down Expand Up @@ -247,7 +247,7 @@ def post(self) -> Response:
@protect()
@safe
@statsd_metrics
@event_logger.log_this
@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 @@ -321,7 +321,7 @@ def put( # pylint: disable=too-many-return-statements, arguments-differ
@protect()
@safe
@statsd_metrics
@event_logger.log_this
@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 @@ -372,7 +372,7 @@ def delete(self, pk: int) -> Response: # pylint: disable=arguments-differ
@safe
@rison(database_schemas_query_schema)
@statsd_metrics
@event_logger.log_this
@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 @@ -426,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 @@ -483,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 @@ -540,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 @@ -621,7 +621,7 @@ def test_connection( # pylint: disable=too-many-return-statements
@protect()
@safe
@statsd_metrics
@event_logger.log_this
@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 @@ -680,7 +680,7 @@ def related_objects(self, pk: int) -> Response:
@safe
@statsd_metrics
@rison(get_export_ids_schema)
@event_logger.log_this
@event_logger.log_this_with_context(log_to_statsd=False)
def export(self, **kwargs: Any) -> Response:
"""Export database(s) with associated datasets
---
Expand Down
14 changes: 7 additions & 7 deletions superset/datasets/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ class DatasetRestApi(BaseSupersetModelRestApi):
@protect()
@safe
@statsd_metrics
@event_logger.log_this
@event_logger.log_this_with_context(log_to_statsd=False)
def post(self) -> Response:
"""Creates a new Dataset
---
Expand Down Expand Up @@ -238,7 +238,7 @@ def post(self) -> Response:
@protect()
@safe
@statsd_metrics
@event_logger.log_this
@event_logger.log_this_with_context(log_to_statsd=False)
def put(self, pk: int) -> Response:
"""Changes a Dataset
---
Expand Down Expand Up @@ -309,7 +309,7 @@ def put(self, pk: int) -> Response:
@protect()
@safe
@statsd_metrics
@event_logger.log_this
@event_logger.log_this_with_context(log_to_statsd=False)
def delete(self, pk: int) -> Response:
"""Deletes a Dataset
---
Expand Down Expand Up @@ -360,7 +360,7 @@ def delete(self, pk: int) -> Response:
@safe
@statsd_metrics
@rison(get_export_ids_schema)
@event_logger.log_this
@event_logger.log_this_with_context(log_to_statsd=False)
def export(self, **kwargs: Any) -> Response:
"""Export datasets
---
Expand Down Expand Up @@ -436,7 +436,7 @@ def export(self, **kwargs: Any) -> Response:
@protect()
@safe
@statsd_metrics
@event_logger.log_this
@event_logger.log_this_with_context(log_to_statsd=False)
def refresh(self, pk: int) -> Response:
"""Refresh a Dataset
---
Expand Down Expand Up @@ -486,7 +486,7 @@ def refresh(self, pk: int) -> Response:
@protect()
@safe
@statsd_metrics
@event_logger.log_this
@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 @@ -545,7 +545,7 @@ def related_objects(self, pk: int) -> Response:
@safe
@statsd_metrics
@rison(get_delete_ids_schema)
@event_logger.log_this
@event_logger.log_this_with_context(log_to_statsd=False)
def bulk_delete(self, **kwargs: Any) -> Response:
"""Delete bulk Datasets
---
Expand Down
12 changes: 6 additions & 6 deletions superset/utils/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,14 +113,14 @@ def log_context(
)

def _wrapper(
self, f: Callable[..., Any], action: Optional[str] = None
self, f: Callable[..., Any], **wrapper_kwargs: Any
) -> Callable[..., Any]:
action_str: str = action or f.__name__
action_str = wrapper_kwargs.get("action") or f.__name__
ref = f.__qualname__ if hasattr(f, "__qualname__") else None

@functools.wraps(f)
def wrapper(*args: Any, **kwargs: Any) -> Any:
with self.log_context(action_str, ref) as log:
with self.log_context(action_str, ref, **wrapper_kwargs) as log:
value = f(*args, **kwargs)
log(**kwargs)
return value
Expand All @@ -131,11 +131,11 @@ def log_this(self, f: Callable[..., Any]) -> Callable[..., Any]:
"""Decorator that uses the function name as the action"""
return self._wrapper(f)

def log_this_as(self, action: str) -> Callable[..., Any]:
"""Decorator that uses the function name as the action"""
def log_this_with_context(self, **kwargs: Any) -> Callable[..., Any]:
"""Decorator that can override kwargs of log_context"""

def func(f: Callable[..., Any]) -> Callable[..., Any]:
return self._wrapper(f, action)
return self._wrapper(f, **kwargs)

return func

Expand Down

0 comments on commit aab4d2d

Please sign in to comment.