This document describes how to monitor and troubleshoot Managed Service for Apache Spark [interactive sessions](https://docs.cloud.google.com/managed-spark/docs/quickstarts/jupyterlab-sessions) using the Spark UI.

<br />

## Spark UI

The Spark UI collects Apache Spark execution details from Managed Service for Apache Spark
interactive sessions. There is no charge for the Spark UI feature,
which is enabled by default. Data collected by the Spark UI feature is retained
for 90 days.

> [!NOTE]
> **Note:** The Spark UI also collects and displays execution details from Managed Service for Apache Spark batch workloads. See [Monitor and troubleshoot batch workloads](https://docs.cloud.google.com/managed-spark/docs/guides/monitor-troubleshoot-batches.md.txt) for more information.

### Required Identity and Access Management permissions and roles

The following permissions are required to use the Spark UI feature with interactive
sessions:

- Data collection permission: `dataproc.sessions.sparkApplicationWrite`. This
  permission must be granted to the service account that runs interactive sessions.
  It is included in the
  [`Managed Service for Apache Spark Worker`](https://docs.cloud.google.com/iam/docs/roles-permissions/dataproc.md.txt#dataproc.worker)
  role, which is automatically granted to the Compute Engine default service account
  that Managed Service for Apache Spark uses by default. However, if you specify a
  [custom service account](https://docs.cloud.google.com/managed-spark/docs/concepts/service-account)
  for your [session](https://docs.cloud.google.com/sdk/gcloud/reference/beta/dataproc/sessions/create.md.txt#--service-account)
  or [runtime profile (session template)](https://docs.cloud.google.com/managed-spark/docs/guides/create-serverless-sessions-templates.md.txt#create-a-session-template),
  you must add this `dataproc.sessions.sparkApplicationWrite` permission to that service account
  (typically, by granting the service account the Managed Service for Apache Spark `Worker` role).

- Spark UI access permission: `dataproc.sessions.sparkApplicationRead`. This
  permission must be granted to a user to access the Spark UI in the
  Google Cloud console. It is included in the
  [`Dataproc Viewer`, `Dataproc Editor` and `Dataproc Administrator`](https://docs.cloud.google.com/managed-spark/docs/concepts/iam#roles)
  roles. To open the Spark UI in the Google Cloud console, you must have one of
  these roles or have a custom role that includes this permission.

### Open the Spark UI

The Spark UI page is available in the Google Cloud console.

1. In the Google Cloud console, go to the Managed Service for Apache Spark
   **Sessions** page.


   [Go to Managed Service for Apache Spark Sessions](https://console.cloud.google.com/dataproc/interactive)

   <br />

2. Click a **Session ID** to open the **Session details** page.

3. Click **View Spark UI** in the top menu.

**Is the *View Spark UI* link disabled?** If a
[required permission isn't granted](https://docs.cloud.google.com/managed-spark/docs/guides/monitor-troubleshoot-sessions.md.txt#required-iam-permissions-and-roles),
or if you clear the **Enable Spark UI** checkbox on the interactive session details page or set
the `spark.dataproc.appContext.enabled` property to `false` (default: `true`) when you
[create a session](https://docs.cloud.google.com/sdk/gcloud/reference/beta/dataproc/sessions/create/spark.md.txt#--property) or
[create a runtime profile (session template)](https://docs.cloud.google.com/managed-spark/docs/guides/create-serverless-sessions-templates.md.txt#create-a-session-template),
the **View Spark UI** button is disabled.