This document describes how to create, manage, and query analytics views. For a conceptual overview, see About analytics views.
Before you begin
Because analytics views query log views, to create and query analytics views, your IAM roles must also let you query log views and use Log Analytics. This section lists the IAM roles required to create analytics views, and those required to query log views and to use Log Analytics:
-
To get the permissions that you need to create, manage, and use analytics views, ask your administrator to grant you the Observability Analytics User (
roles/observability.analyticsUser
) IAM role on your project.This predefined role contains the permissions required to create, manage, and use analytics views. To see the exact permissions that are required, expand the Required permissions section:
Required permissions
The following permissions are required to create, manage, and use analytics views:
-
observability.analyticsViews.get
-
observability.analyticsViews.list
-
observability.analyticsViews.create
-
observability.analyticsViews.update
-
observability.analyticsViews.delete
-
-
To get the permissions that you need to query a log view and to use Log Analytics, ask your administrator to grant you the following IAM roles on your project:
-
To query the
_Required
and_Default
log buckets: Logs Viewer (roles/logging.viewer
) -
To query all log views in a project:
Logs View Accessor (
roles/logging.viewAccessor
)
You can restrict a principal to a specific log view either by adding an IAM condition to the Logs View Accessor role grant made at the project level, or by adding an IAM binding to the policy file of the log view. For more information, see Control access to a log view.
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. -
To query the
Create an analytics view
To create an analytics view, do the following:
-
In the Google Cloud console, go to the Log Analytics page:
If you use the search bar to find this page, then select the result whose subheading is Logging.
In the Views menu, go to the
Logs section, and then select the log view to query.To find a log view, you can use the filter_list Filter bar or scroll through the list of log views. Each entry in the list is in the following format
BUCKET_ID.LOG_VIEW_ID
, where these fields refer to the IDs of the log bucket and log view.In the Schema toolbar, click Query.
The Query pane is updated with a SQL query.
Ensure that the toolbar displays Run query.
If the toolbar displays Run in BigQuery, then click settings Settings and select Log Analytics (default).
Update the SQL query in the Query pane until you're satisfied with the results of the query.
In the toolbar, click
Save, and then select Save as analytics view.Enter a name and description for the analytics view, and then click Save.
Your analytics view is created and is listed in the Views pane, in the section titled
Analytics Views. Each entry in the list is in the following formatLOCATION.ANALYTICS_VIEW_ID
, where these fields refer to the location and ID of an analytics view. For example, if you created an analytics view with the namemy-analytic-view
that queries a log view whose log bucket is in theglobal
region, then this section displaysglobal.my-analytic-view
.
Query an analytics view
After an analytics view exists, you can query it similarly to querying a log view. For a list of documents that describe how to use the Log Analytics page, see the What's next section of this document.
To run the default query for an analytics view, do the following:
-
In the Google Cloud console, go to the Log Analytics page:
If you use the search bar to find this page, then select the result whose subheading is Logging.
Enter a query or load the default query for the analytics view. The
FROM
clause for your query should have the following format:FROM `analytics_view.PROJECT_ID.LOCATION.ANALYTICS_VIEW_ID`
In the previous expression, the fields have the following meaning:
- PROJECT_ID: The identifier of the project.
- LOCATION: The location of the analytics view.
The location of an analytics view is inherited from the resource
it queries. For example, if an analytics view queries a log view that
is in the
global
location, then the location of the analytics view is alsoglobal
. - ANALYTICS_VIEW_ID: The ID of the analytics view.
To run the default query, do the following:
In the Views menu, go to the
Analytics Views section, and select the analytics view that you want to query.To find an analytics view, you can use the filter_list Filter bar or scroll through the list of analytics views. Each entry in the list is in the following format
LOCATION.ANALYTICS_VIEW_ID
, where these fields refer to the location and ID of an analytics view.In the Schema toolbar, click Query.
The Query pane is updated with a SQL query that is querying the analytics view you selected.
Click Run query.
If the toolbar displays Run in BigQuery, then click settings Settings and select Log Analytics (default).
List analytics views
To list the analytics views in your Google Cloud project, do the following:
-
In the Google Cloud console, go to the Log Analytics page:
If you use the search bar to find this page, then select the result whose subheading is Logging.
In the Views menu, go to the
Analytics Views section.A list of analytics views is shown. Each entry in the list is in the following format
LOCATION.ANALYTICS_VIEW_ID
, where these fields refer to the location and ID of an analytics view. For example, if you created an analytics view with the namemy-analytic-view
that queries a log view whose log bucket is in theglobal
region, then this section displaysglobal.my-analytic-view
.To view the details of a specific analytics view, do the following:
Select the analytics view.
The schema of the analytics view is shown in the Schema section.
In to the Schema toolbar click more_vert View analytics view options, and select View details.
The dialog displays information about the analytics view, including when the analytics view was created, the schema, and the query.
Modify an analytics view
To modify an analytics view, do the following:
-
In the Google Cloud console, go to the Log Analytics page:
If you use the search bar to find this page, then select the result whose subheading is Logging.
- In the Views menu, go to the Analytics Views section, and select the analytics view that you want to query.
In the Schema toolbar, click more_vert View analytics view options, and select Edit view.
A dialog opens that displays information about the analytics view. You can modify the description and query.
After you made your modifications, click Overwrite saved view.
Delete an analytics view
To delete an analytics view, do the following:
-
In the Google Cloud console, go to the Log Analytics page:
If you use the search bar to find this page, then select the result whose subheading is Logging.
- In the Views menu, go to the Analytics Views section, and select the analytics view that you want to query.
- In the Schema toolbar, click more_vert View analytics view options, select Delete view, and complete the dialog.
Limitations
The following limitations apply to analytics views:
- An analytics view can't query another analytics view.
- An analytics view can query multiple log views. However, the log buckets
that host the queried log views must be in one location. For example,
suppose you have two log buckets, one in
us-east1
and the other inasia-east1
. You can't create a analytics view that queries log views on those log buckets. - The parent resource of an analytics view must be a Google Cloud project. You can't create an analytics view in folders or organizations.
- Linked datasets aren't supported for analytics views. Therefore, you can query analytics views only by using the Log Analytics page. Also, you must run those queries on the default Cloud Logging service.
- There is no API support for creating or managing analytics views.
The following limits apply to analytics views:
- Maximum number of analytics views per Google Cloud project: 100
- Per Google Cloud project, the maximum number of analytics views per region: 50
- Per Google Cloud project, the maximum number of regions that can store analytics views: 10
What's next
- Query and analyze logs overview
- Save and share a SQL query
- Chart SQL query results
- Sample SQL queries