[Observability Analytics](https://docs.cloud.google.com/logging/docs/log-analytics.md.txt) lets you run SQL queries to analyze your logs,
create analytics views, link log buckets to BigQuery datasets, and
monitor query results with alerting policies. If you encounter errors when
configuring or querying Observability Analytics, you can use the guidance in this document
to identify and resolve them. For issues with upgrading a log bucket, see
[Troubleshoot upgrading a bucket to use Observability Analytics](https://docs.cloud.google.com/logging/docs/analyze/troubleshoot-upgrade-bucket.md.txt).

## Error messages

This section describes error messages you might see and how to resolve the
corresponding error conditions.

### `No completion signal within allotted timeframe` error message

You enter a SQL query and select **Run query**. The query doesn't complete and
you see the following error message:

```
The query failed to execute and return results due to error: No completion signal within allotted timeframe.
```

To resolve this error, do one of the following:

- Shorten the interval over which logs are queried and then retry the query.
  For example, if a query interval is 14 days, shorten the interval to 7 days,
  and then run the query.

- Create a linked BigQuery dataset
  and then run the query from the BigQuery interface. The
  BigQuery interface supports queries that require a longer execution
  time than the Cloud Logging interface. For more information, see
  [Create a linked BigQuery dataset](https://docs.cloud.google.com/logging/docs/analyze/query-linked-dataset.md.txt).

### Queries against buckets with distinct CMEK keys error message

You enter a SQL query that queries multiple log buckets and select
**Run query**. The query doesn't complete and
you see the following error message:

```
Queries against buckets with distinct CMEK keys must have a key configured in the LogSettings.
```

To resolve this situation, do one of the following:

- Configure your log buckets to use the same Cloud Key Management Service (Cloud KMS) key.
- When the log buckets are in the same location, you can configure a folder or organization that is a parent resource for the log buckets with a default Cloud KMS key. The parent's default key must be in the same location as the log buckets. With this configuration, the parent's default key encrypts any temporary data generated by the Observability Analytics query. For more information, see [Observability Analytics restrictions](https://docs.cloud.google.com/logging/docs/log-analytics.md.txt#restrictions).

### `FROM clause must contain exactly one log view` error message

You enter a SQL query in the query pane of the **Observability Analytics** page
in the Google Cloud console, but the SQL parser displays the following
error:

```
FROM clause must contain exactly one log view
```

The previous error is reported when the table specified in the `FROM`
statement can't be resolved to a specific log view.

To resolve this error, ensure that your table name has the proper syntax:

- Ensure that the table name follows the syntax required by the
  Observability Analytics naming scheme. BigQuery and Observability Analytics have
  different requirements for the table name. You can find the required
  syntax for the table name by
  [viewing the default query](https://docs.cloud.google.com/logging/docs/analyze/query-and-view.md.txt#query-view).

- If the Google Cloud project ID, region, bucket ID, or view ID of a
  log bucket contains period characters, `(.)`, then ensure that each of these
  fields is wrapped by single backquotes, ``(`)``.

  For example, if a Google Cloud project ID is `example.com:bluebird`, then to
  query the `_AllLogs` view of the `_Default` log bucket,
  use the following syntax to specify the table:


      SELECT *
      FROM `example.com:bluebird`.`global`.`_Default`.`_AllLogs`

  The previous query assumes that the `_Default` bucket is in the `global`
  region.

## Unable to save a query

You want to save your current query, so you run the query and then
click **Save** , but the **Save query** option is
disabled or you can't complete the dialog steps.

The cause of this failure is a conflict between an organization policy and
default resource settings for Cloud Logging. For an organization or folder, you can configure
default resource settings for Cloud Logging that specify a location. This location is where your saved
queries are stored. However, if the location conflicts with an
organization policy, then your queries can't be saved.

To resolve this failure, ask the
administrator of your organization to update the default resource settings for Cloud Logging so that the
location setting is allowed by your organization policy.
For more information, see
[Configure default resource settings for Cloud Logging](https://docs.cloud.google.com/logging/docs/default-settings.md.txt).

If the **Save query** option is enabled
but you can't complete the dialog and save the query, then do the following:

1. Ensure that the query doesn't contain syntax errors. You can only save valid queries.
2. Optional: Copy the query into your clipboard.
3. Reload the page.
4. If you copied the query into your clipboard, then paste the query into the **Query** pane, run the query, and then perform the save operation.

## Unable to create an analytics view

You want to create an analytics view, so you
enter and run a SQL query and then click **Save** ,
but the **Save as analytic view** option is disabled.

To resolve this situation, ensure that your IAM roles include
the following permissions:

- `observability.analyticsViews.{get, list, create, update, delete}`

These permissions aren't included in any predefined Cloud Logging role.
For information about the required roles, see
[Create and query analytics views: Before you begin](https://docs.cloud.google.com/logging/docs/analyze/create-and-manage-analytics-views.md.txt#before-you-begin).

## Unable to query an analytics view

You want to query an analytics view, but the **Views** pane in the
**Observability Analytics** page doesn't show any analytics views.

To resolve this failure, try the following:

- Ensure that your IAM roles include the following permissions:

  - `observability.analyticsViews.{get, list}`

  These permissions aren't included in any predefined Cloud Logging role.
  For information about the required roles, see
  [Create and query analytics views: Before you begin](https://docs.cloud.google.com/logging/docs/analyze/create-and-manage-analytics-views.md.txt#before-you-begin).
- Ensure that analytics views exist in your Google Cloud project.

## Access denied to the **Observability Analytics** page

You open the **Observability Analytics** page in the Google Cloud console
and a permission-denied error message is displayed.


To get the permissions that
you need to load the **Observability Analytics** page, run queries, and
view logs,

ask your administrator to grant you the
following IAM roles on your project:

- View logs: [Logs Viewer](https://docs.cloud.google.com/iam/docs/roles-permissions/logging.md.txt#logging.viewer) (`roles/logging.viewer`)
- View logs in custom log buckets: [Logs View Accessor](https://docs.cloud.google.com/iam/docs/roles-permissions/logging.md.txt#logging.viewAccessor) (`roles/logging.viewAccessor`)


You might also be able to get the required permissions through
[custom roles](https://docs.cloud.google.com/iam/docs/creating-custom-roles.md.txt) or Logging
[predefined roles](https://docs.cloud.google.com/logging/docs/access-control.md.txt#permissions_and_roles).

The permissions that you need to view log entries and run queries on the
**Observability Analytics** page are the same as those that you need to view
logs on the **Logs Explorer** page. For information about
additional roles that you need to query views on user-defined buckets or
to query the `_AllLogs` view of the `_Default` log bucket, see
[Cloud Logging roles](https://docs.cloud.google.com/logging/docs/access-control.md.txt#considerations).

## Creating a log bucket fails due to a location constraint

You attempt to create a log bucket, but the action fails with a message similar
to the following:

    Constraint `constraints/gcp.resourceLocations` violated for `<CONTAINER>` attempting to change `<BUCKET_NAME>` with location `<LOCATION>`. The location must be in the allowed location list configured by the organization policy administrator.

The previous error message indicates that the location you selected for the
new log bucket isn't supported by your organization.

To resolve this failure, select a location that is supported by your
organization.

## Creating a linked BigQuery dataset fails

You edit a log bucket to create a linked BigQuery dataset or you
create a new log bucket and select the option to create a
linked BigQuery dataset;
however, the linked BigQuery dataset isn't created.

To resolve this error, ask the system administrator for the Google Cloud project
to grant you an IAM role that includes the
following permission:

- `logging.links.create`

The previous permission is included in the Logging Admin (`roles/logging.admin`)
and Logs Configuration Writer (`roles/logging.configWriter`) roles.

For information about roles and permissions, see
[Access control with IAM](https://docs.cloud.google.com/logging/docs/access-control.md.txt).

## Deleting a linked BigQuery dataset fails

You no longer want the linked BigQuery dataset, but the option
to delete that dataset is disabled.

To resolve this error, ask the system administrator for the Google Cloud project
to grant you an IAM role that includes the
following permission:

- `logging.links.delete`

The previous permission is included in the Logging Admin (`roles/logging.admin`)
and Logs Configuration Writer (`roles/logging.configWriter`) roles.

This permission lets you delete the linked BigQuery dataset from
the **Logs Storage** page of the Google Cloud console.
For more information about roles and permissions, see
[Access control with IAM](https://docs.cloud.google.com/logging/docs/access-control.md.txt).

## Observability Analytics displays a warning about sensitive metadata

The **Observability Analytics** page displays a message similar to the following:

    This SQL query is configured to run on the BigQuery engine using [PROJECT_ID],
    and references resources from [RESOURCE, ...]. Sensitive metadata,
    including table contents, may be written to [PROJECT_ID].

The warning message indicates that the query crosses ownership boundaries
and it provides you an opportunity to verify the query before it is executed.
Ownership boundaries are determined by several factors, one of which is the
hierarchy of the resources the query uses.

You can't prevent these types of warnings.

If the **Observability Analytics** page displays a warning dialog, then you can do any of
the following:

- If you know the query is safe to run and if you want to view the query
  results, then click **Confirm and Run**.

  > [!NOTE]
  > **Note:** Don't run a query unless you know that it is safe to run.

- Analyze the query and, if necessary, discard it. For example,
  you might do the following:

  1. Inspect the query. In your inspection, consider what data is queried, the potential size of the queried dataset, and the query engine. Queries run on the BigQuery service might result in charges.
  2. If you were sent a link to the **Observability Analytics** page, then verify that the sender is a trusted source.

  > [!NOTE]
  > **Note:** If you determine that a query isn't safe to execute, then delete it.

Google Cloud provides some features that can help prevent data exfiltration
through phishing, insider attacks, or external entities. To learn more, see
[Data security with Observability Analytics](https://docs.cloud.google.com/logging/docs/analyze/data-security-with-analytics.md.txt).

## Querying a linked BigQuery dataset fails with dataset not found

You issue a query to a linked BigQuery dataset, and the command
fails with an error message similar to "Dataset not found".

To resolve this problem, try the following:

- Make sure that the path to the dataset name is correct.
- Run the following
  [`gcloud logging links list`](https://docs.cloud.google.com/sdk/gcloud/reference/logging/links/list.md.txt)
  command and verify that the response lists your
  linked BigQuery dataset.

  If your linked BigQuery dataset isn't listed, then the dataset
  is orphaned. To resolve this scenario, delete the
  linked BigQuery dataset.

  A project can have an orphaned linked BigQuery dataset if
  you revoke IAM role grants from a service account that
  Google Cloud Observability uses to manage data and then delete the link on the log bucket.
  In that scenario, Google Cloud Observability can't delete the
  linked BigQuery dataset.

## Not able to set the query engine to BigQuery

The **Settings** menu has the BigQuery option
disabled.

To enable this option, make sure that you have a
[linked BigQuery dataset](https://docs.cloud.google.com/logging/docs/buckets.md.txt#link-bq-dataset) on the log bucket that
is queried.

## Run on BigQuery button is disabled

If the **Run on BigQuery** button is displayed but disabled,
then a log view referenced by your query doesn't have a
linked BigQuery dataset.
To run your query on the BigQuery engine,
[create a linked BigQuery dataset](https://docs.cloud.google.com/logging/docs/buckets.md.txt#link-bq-dataset) on your
log bucket.

## No Monitoring Service Account

You want to create an alerting policy to monitor the results of a SQL query.
The setup steps require that you grant IAM roles
to the Monitoring Service Account, but that account doesn't exist.

The [Monitoring Service Account](https://docs.cloud.google.com/iam/docs/service-agents.md.txt#monitoring-service-account)
is called a *service agent* because it is created and managed by
Google Cloud. The account is created automatically when you configure a
resource or service that requires the account. For example, if you create a
Pub/Sub notification channel, then that action might cause the
Monitoring Service Account to be created.

To create the Monitoring Service Account and grant it the permissions required
for SQL-based alerting policies, do the following:

1. Create the Monitoring Service Account. For more information, see
   [Create and grant roles to service agents](https://docs.cloud.google.com/iam/docs/create-service-agents.md.txt).

2. Grant the following roles to the Monitoring Service Account:

   - [Monitoring Service Agent (`roles/monitoring.notificationServiceAgent`)](https://docs.cloud.google.com/iam/docs/roles-permissions/monitoring.md.txt#monitoring.NotificationServiceAgent) on your project.
   - [BigQuery Data Viewer (`roles/bigquery.dataViewer`)](https://docs.cloud.google.com/iam/docs/roles-permissions/bigquery.md.txt#bigquery.dataViewer) on your linked BigQuery dataset.

## Monitoring Service Account permission denied error

You want to create an alerting policy to monitor the results of a SQL query.
However, you see a `PermissionDenied` error with a message that starts with
`Error authenticating service account`.

To resolve this failure, grant the following roles to the Monitoring Service
Account:

- [Monitoring Service Agent (`roles/monitoring.notificationServiceAgent`)](https://docs.cloud.google.com/iam/docs/roles-permissions/monitoring.md.txt#monitoring.NotificationServiceAgent) on your project.
- [BigQuery Data Viewer (`roles/bigquery.dataViewer`)](https://docs.cloud.google.com/iam/docs/roles-permissions/bigquery.md.txt#bigquery.dataViewer) on your linked BigQuery dataset.

## There are duplicate log entries in my Observability Analytics results

You run a query that is counting or reporting duplicate entries.
Because the Logs Explorer removes duplicate entries based on log name,
timestamp, and insert ID, you expect Observability Analytics to deduplicate log entries
before a query is run.

Observability Analytics doesn't perform the same type of deduplication that is performed
by the Logs Explorer.

To resolve duplicate log entries, try the following:

1. Determine if the duplicate log entries have different receive timestamp
   values. When the timestamps differ, that indicates that the same data was
   written to Logging multiple times.

   To resolve duplicate writes, investigate your logging integration for error
   messages or misconfigurations.
2. If your bucket is configured to use Cloud Key Management Service keys, then ensure that you
   are within [quota](https://docs.cloud.google.com/kms/quotas.md.txt) and that your key is consistently
   [accessible](https://docs.cloud.google.com/logging/docs/routing/managed-encryption-storage.md.txt#key-unavailable). Going over quota or loss of
   key access can result in duplicate log entries.

   To resolve these failures, ensure that you don't exceed your quota and that
   your key is accessible.
3. Modify your query to remove duplicate log entries.

   > [!NOTE]
   > **Note:** Modifying your SQL query to perform row qualification slows the query computation. Therefore, we recommend that you use this approach only when the query is sensitive to duplicate log entries or when the results must not contain duplicate entries.


   For example, assume that the JSON payload contains `fieldA` and `fieldB`,
   where the first is a string and the second is numeric.
   Also, assume that the JSON payload contains a
   field labeled `server`, which contains a string. Next,
   consider the following query:

   ```sql
   SELECT
     JSON_VALUE(json_payload.fieldA) AS fieldA,
     SUM(IFNULL(SAFE_CAST(JSON_VALUE(json_payload.fieldB) AS INT64), 0)) AS sum_fieldB
   FROM
     `VIEW`
   WHERE
     JSON_VALUE(json_payload.server) = "test"
   GROUP BY
     fieldA;
   ```

   You can modify the query to remove duplicate log entries, where the
   log name, timestamp, and insert ID are examined to determine whether
   a log entry is a duplicate:

   ```sql
   WITH
     deduplicated AS (
     SELECT
       JSON_VALUE(json_payload.fieldA) AS fieldA,
       IFNULL(SAFE_CAST(JSON_VALUE(json_payload.fieldB) AS INT64), 0) AS fieldB
     FROM
       `VIEW` a
     WHERE
       JSON_VALUE(json_payload.server) = "test"
     QUALIFY
       ROW_NUMBER() OVER (PARTITION BY a.log_name, a.timestamp, a.insert_id ) = 1 )

   SELECT
     fieldA,
     SUM(fieldB) AS sum_fieldB
   FROM
     deduplicated
   GROUP BY
     fieldA;
   ```