Skip to content
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
10 changes: 9 additions & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Version Compatibility
*********************

- ``platform-plugin-aspects`` version 1.x: Nutmeg to Sumac
- ``platform-plugin-aspects`` version 2.x: Redwood and above
- ``platform-plugin-aspects`` version 2.x: Redwood (with in-context metrics turned off), or Sumac and above

Sinks
*****
Expand Down Expand Up @@ -156,6 +156,14 @@ superset pipeline into the filter as follows:
- `SUPERSET_DASHBOARD_LOCALES` - This setting is used to configure the available locales
for the dashboards. The configuration is a list of supported locales by `Aspects`_.

- `ASPECTS_ENABLE_STUDIO_IN_CONTEXT_METRICS` - This setting turns on and off the in-context
metrics feature. It must be turned off in Open edX releases before Sumac and when using
tutor-contrib-aspects before v2.2.0 as those dashboards will not exist, causing errors in
the embedded Instructor Dashboards.

- `ASPECTS_IN_CONTEXT_DASHBOARDS` - This setting mirrors the `ASPECTS_INSTRUCTOR_DASHBOARDS` but
with additional keys used for filtering the boards to specific courses and blocks.

Event Sink Configuration
========================

Expand Down
2 changes: 1 addition & 1 deletion platform_plugin_aspects/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
import os
from pathlib import Path

__version__ = "1.1.0"
__version__ = "1.1.1"

ROOT_DIRECTORY = Path(os.path.dirname(os.path.abspath(__file__)))
4 changes: 4 additions & 0 deletions platform_plugin_aspects/settings/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,10 @@ def plugin_settings(settings):
},
}

# This is on by default here, off by default in tutor-contrib-aspects until we only
# support versions Sumac and beyond
settings.ASPECTS_ENABLE_STUDIO_IN_CONTEXT_METRICS = True

settings.ASPECTS_IN_CONTEXT_DASHBOARDS = {
"course": {
"name": _("Course"),
Expand Down
4 changes: 4 additions & 0 deletions platform_plugin_aspects/settings/production.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ def plugin_settings(settings):
"EVENT_SINK_CLICKHOUSE_PII_MODELS",
settings.EVENT_SINK_CLICKHOUSE_PII_MODELS,
)
settings.ASPECTS_ENABLE_STUDIO_IN_CONTEXT_METRICS = settings.ENV_TOKENS.get(
"ASPECTS_ENABLE_STUDIO_IN_CONTEXT_METRICS",
settings.ASPECTS_ENABLE_STUDIO_IN_CONTEXT_METRICS,
)
settings.ASPECTS_IN_CONTEXT_DASHBOARDS = settings.ENV_TOKENS.get(
"ASPECTS_IN_CONTEXT_DASHBOARDS",
settings.ASPECTS_IN_CONTEXT_DASHBOARDS,
Expand Down
6 changes: 4 additions & 2 deletions platform_plugin_aspects/tests/test_xblock.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"""
Test basic SupersetXBlock display function
"""

import json
from unittest import TestCase
from unittest.mock import Mock, patch
Expand Down Expand Up @@ -154,6 +155,7 @@ def test_guest_token_handler_failed(self, mock_generate_guest_token):

assert response.status_code == 500
data = json.loads(response.body.decode("utf-8"))
assert data.get("error") == (
"Unable to fetch Superset guest token, mostly likely due to invalid settings.SUPERSET_CONFIG"
assert (
"Error trying to fetch Superset guest token, mostly likely due to invalid"
in data.get("error")
)
33 changes: 15 additions & 18 deletions platform_plugin_aspects/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,26 +155,23 @@ def generate_guest_token(user, course, dashboards, filters) -> str:
token = response.json().get("token")
return token

except HTTPError as err:
# Superset server errors sometimes come with messages, so log the response.
logger.error(
f"{err.response.status_code} {err.response.json()} for url: {err.response.url}, data: {data}"
)
raise ImproperlyConfigured(
_(
"Unable to fetch Superset guest token, "
"Superset server error {server_response}"
).format(server_response=err.response.json())
) from err
# We manually log the error message here because ImproperlyConfigured is eaten up the stack
except HTTPError as exc:
err = f"""Unable to fetch Superset guest token, mostly likely due to invalid
settings.SUPERSET_CONFIG or because one of the dashboard UUIDs requested does not
exist in Superset.\n
{exc.response.status_code} {exc.response.json()} for url:
{exc.response.url}, data: {data}\n\n dashboards: {dashboards}"""

logger.error(err)
raise ImproperlyConfigured(err) from exc

except Exception as exc:
logger.error(exc)
raise ImproperlyConfigured(
_(
"Unable to fetch Superset guest token, "
"mostly likely due to invalid settings.SUPERSET_CONFIG"
)
) from exc
err = f"""Error trying to fetch Superset guest token, mostly likely due to invalid
settings.SUPERSET_CONFIG or because one of the dashboard UUIDs requested does not
exist in Superset. data: {data} \n\n exception: {exc}"""
logger.error(err)
raise ImproperlyConfigured(err) from exc


def _fix_service_url(url: str) -> str:
Expand Down
9 changes: 8 additions & 1 deletion platform_plugin_aspects/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,14 @@ def get(self, request, *args, **kwargs):
course = self.get_object()

dashboards = settings.ASPECTS_INSTRUCTOR_DASHBOARDS.copy()
dashboards.extend(settings.ASPECTS_IN_CONTEXT_DASHBOARDS.values())

# Only include these dashboards if in-context metrics are on,
# otherwise this call will always fail in older releases without
# admin intervention. This can be removed when we stop supporting
# < Sumac.
if settings.ASPECTS_ENABLE_STUDIO_IN_CONTEXT_METRICS:
dashboards.extend(settings.ASPECTS_IN_CONTEXT_DASHBOARDS.values())

extra_filters_format = settings.SUPERSET_EXTRA_FILTERS_FORMAT

try:
Expand Down
1 change: 1 addition & 0 deletions test_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@
}
]

ASPECTS_ENABLE_STUDIO_IN_CONTEXT_METRICS = True
ASPECTS_IN_CONTEXT_DASHBOARDS = {
"course": {
"slug": "in-context-course",
Expand Down
Loading