.. _troubleshooting_aspects:

Troubleshoot Aspects
#######################

Most common problems with Aspects can be fixed by making sure everything is up to date by deleting
any potentially orphaned Superset assets, rebuilding Docker images, and re-initializing Aspects:

- From your TUTOR_ROOT: ``rm -rf env/plugins/aspects``
- ``tutor config save``
- ``tutor images build openedx aspects aspects-superset``
- ``tutor [dev|local|k8s] do init -l aspects``

  - This may take a long time if you have lots of data!


Common Issues
*************
In some cases things can get into a state which isn't resolved by those steps, below are some
common Aspects problems and how to fix them.


Superset Logo Just Spins
========================

Symptom: In the Instructor Dashboard "Reports" tab, In-Context Metrics in Studio, or in Superset,
some or all Superset dashboards appear to load but the "S" logo just spins and no data appears.

Causes: This most often happens where ClickHouse has no data for filters needed to display a
dashboard.

Solution: Make sure you have published your courses since installing / reinstalling Aspects, or :ref:`backfill course blocks <backfill_course_blocks>` .


Embedded Dashboard / Superset Login Errors
==========================================

Symptom: In the Instructor Dashboard "Reports" tab or In-Context Metrics in Studio the dashboards
fail to load, showing only a message like:

- ``Something went wrong with embedded authentication. Check the dev console for details.``
- or ``Error: invalid_request Invalid client_id``

There are numerous potential causes of these errors, but most they often happen when moving between
Tutor deployment types (dev/local/k8s) but can also happen when the hostnames or ports in your LMS or
Superset configuration change (such as when populating a staging environment from a production database).

This root issue is usually an the OAuth Application LMS database entry not matching the Superset
URL. Make sure your ``config.yml`` settings are correct for your environment (especially
``SUPERSET_HOST`` and ``SUPERSET_PORT``).

External Proxy
--------------

If you are running behind a proxy separate from Tutor's Caddy there may be mismatches between
the expected http/https redirect URIs that Aspects sets by default. In this case you can set
the ``SUPERSET_PROXY_FIX`` Tutor setting to True in your config. It tells Superset to use the
headers set by the proxy to confirm the URL. See the
`Flask documentation <https://flask.palletsprojects.com/en/latest/deploying/proxy_fix/>`_
for important details and security implications.

Outdated Settings
-----------------

If you are not running behind an external proxy you can take these steps:

- Go into the Django admin: ``{LMS_ROOT}/admin/oauth2_provider/application/``
- Delete the Application entries for `superset-sso` and ``superset-sso-dev`` if they exist
- Re-run ``tutor [dev|local|k8s] do init -l aspects`` to recreate the entries

Tutor Local HTTPS
-----------------

Some configurations of ``tutor local`` (usually when selecting HTTPS for a localhost development
installation, which cannot support HTTPS) can cause this error as well. In those cases you can
get around the error by using the following Tutor patch.

.. warning::

    This patch turns off an important security setting and potentially creates a vulnerability in
    your application. If you run into the above error in a production environment please reach out
    for assistance instead of using this patch!


.. code-block:: yaml

    name: superset-auth-override
    version: "1.0.0"
    patches:
        openedx-common-settings: |
            import os
            os.environ["OAUTHLIB_INSECURE_TRANSPORT"] = "1"
            SUPERSET_CONFIG["internal_service_url"] = "http://superset:8088"


General Troubleshooting
***********************

Logs to check for errors:

When running with the Ralph data pipeline:

- lms-worker
- cms-worker
- ralph

When running with the Vector data pipeline:

- lms
- cms
- vector

When running with the event bus data pipeline:

- lms
- cms
- aspects-consumer
