Exporting Logs to BigQuery, GCS, Pub/Sub through Stackdriver
This post shows how to direct Istio logs to Stackdriver1 and export those logs to various configured sinks such as such as BigQuery2, Google Cloud Storage3 or Cloud Pub/Sub4. At the end of this post you can perform analytics on Istio data from your favorite places such as BigQuery, GCS or Cloud Pub/Sub.
The Bookinfo5 sample application is used as the example application throughout this task.
Before you begin
Install Istio6 in your cluster and deploy an application.
Configuring Istio to export logs
Istio exports logs using the logentry
template7.
This specifies all the variables that are available for analysis. It
contains information like source service, destination service, auth
metrics (coming..) among others. Following is a diagram of the pipeline:
Istio supports exporting logs to Stackdriver which can in turn be configured to export logs to your favorite sink like BigQuery, Pub/Sub or GCS. Please follow the steps below to setup your favorite sink for exporting logs first and then Stackdriver in Istio.
Setting up various log sinks
Common setup for all sinks:
- Enable Stackdriver Monitoring API8 for the project.
- Make sure
principalEmail
that would be setting up the sink has write access to the project and Logging Admin role permissions. - Make sure the
GOOGLE_APPLICATION_CREDENTIALS
environment variable is set. Please follow instructions here9 to set it up.
BigQuery
- Create a BigQuery dataset10 as a destination for the logs export.
- Record the ID of the dataset. It will be needed to configure the Stackdriver handler.
It would be of the form
bigquery.googleapis.com/projects/[PROJECT_ID]/datasets/[DATASET_ID]
- Give sink’s writer identity11:
cloud-logs@system.gserviceaccount.com
BigQuery Data Editor role in IAM. - If using Google Kubernetes Engine12, make sure
bigquery
Scope13 is enabled on the cluster.
Google Cloud Storage (GCS)
- Create a GCS bucket14 where you would like logs to get exported in GCS.
- Recode the ID of the bucket. It will be needed to configure Stackdriver.
It would be of the form
storage.googleapis.com/[BUCKET_ID]
- Give sink’s writer identity11:
cloud-logs@system.gserviceaccount.com
Storage Object Creator role in IAM.
Google Cloud Pub/Sub
- Create a topic15 where you would like logs to get exported in Google Cloud Pub/Sub.
- Recode the ID of the topic. It will be needed to configure Stackdriver.
It would be of the form
pubsub.googleapis.com/projects/[PROJECT_ID]/topics/[TOPIC_ID]
- Give sink’s writer identity11:
cloud-logs@system.gserviceaccount.com
Pub/Sub Publisher role in IAM. - If using Google Kubernetes Engine12, make sure
pubsub
Scope13 is enabled on the cluster.
Setting up Stackdriver
A Stackdriver handler must be created to export data to Stackdriver. The configuration for a Stackdriver handler is described here16.
Save the following yaml file as
stackdriver.yaml
. Replace<project_id>, <sink_id>, <sink_destination>, <log_filter>
with their specific values.Push the configuration
Send traffic to the sample application.
For the Bookinfo sample, visit
http://$GATEWAY_URL/productpage
in your web browser or issue the following command:Verify that logs are flowing through Stackdriver to the configured sink.
- Stackdriver: Navigate to the Stackdriver Logs Viewer17 for your project and look under “GKE Container” -> “Cluster Name” -> “Namespace Id” for Istio Access logs.
- BigQuery: Navigate to the BigQuery
Interface18 for your project and you
should find a table with prefix
accesslog_logentry_istio
in your sink dataset. - GCS: Navigate to the Storage
Browser19 for your
project and you should find a bucket named
accesslog.logentry.istio-system
in your sink bucket. - Pub/Sub: Navigate to the Pub/Sub
Topic List20 for
your project and you should find a topic for
accesslog
in your sink topic.
Understanding what happened
Stackdriver.yaml
file above configured Istio to send access logs to
Stackdriver and then added a sink configuration where these logs could be
exported. In detail as follows:
Added a handler of kind
stackdriver
Added
logInfo
in specIn the above configuration sinkInfo contains information about the sink where you want the logs to get exported to. For more information on how this gets filled for different sinks please refer here.
Added a rule for Stackdriver
Cleanup
Remove the new Stackdriver configuration:
If you are not planning to explore any follow-on tasks, refer to the Bookinfo cleanup instructions to shutdown the application.
Availability of logs in export sinks
Export to BigQuery is within minutes (we see it to be almost instant), GCS can have a delay of 2 to 12 hours and Pub/Sub is almost immediately.