content/en/blog/2018/export-logs-through-stackdriver/index.md
This post shows how to direct Istio logs to Stackdriver and export those logs to various configured sinks such as such as BigQuery, Google Cloud Storage or Cloud Pub/Sub. 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 Bookinfo sample application is used as the example application throughout this task.
Install Istio in your cluster and deploy an application.
Istio exports logs using the logentry template.
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:
{{< image width="75%" link="./istio-analytics-using-stackdriver.png" caption="Exporting logs from Istio to Stackdriver for analysis" >}}
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 set up your favorite sink for exporting logs first and then Stackdriver in Istio.
Common setup for all sinks:
principalEmail that would be setting up the sink has write access to the project and Logging Admin role permissions.GOOGLE_APPLICATION_CREDENTIALS environment variable is set. Please follow instructions here to set it up.bigquery.googleapis.com/projects/[PROJECT_ID]/datasets/[DATASET_ID][email protected] BigQuery Data Editor role in IAM.bigquery Scope is enabled on the cluster.storage.googleapis.com/[BUCKET_ID][email protected] Storage Object Creator role in IAM.pubsub.googleapis.com/projects/[PROJECT_ID]/topics/[TOPIC_ID][email protected] Pub/Sub Publisher role in IAM.pubsub Scope is enabled on the cluster.A Stackdriver handler must be created to export data to Stackdriver. The configuration for a Stackdriver handler is described here.
Save the following yaml file as stackdriver.yaml. Replace <project_id>, <sink_id>, <sink_destination>, <log_filter> with their specific values.
{{< text yaml >}} apiVersion: "config.istio.io/v1alpha2" kind: stackdriver metadata: name: handler namespace: istio-system spec:
project_id: "<project_id>"
appCredentials, which corresponds toapiVersion: "config.istio.io/v1alpha2" kind: rule metadata: name: stackdriver namespace: istio-system spec: match: "true" # If omitted match is true. actions:
{{< /text >}}
Push the configuration
{{< text bash >}} $ kubectl apply -f stackdriver.yaml stackdriver "handler" created rule "stackdriver" created logentry "stackdriverglobalmr" created metric "stackdriverrequestcount" created metric "stackdriverrequestduration" created metric "stackdriverrequestsize" created metric "stackdriverresponsesize" created {{< /text >}}
Send traffic to the sample application.
For the Bookinfo sample, visit http://$GATEWAY_URL/productpage in your web
browser or issue the following command:
{{< text bash >}} $ curl http://$GATEWAY_URL/productpage {{< /text >}}
Verify that logs are flowing through Stackdriver to the configured sink.
accesslog_logentry_istio in your sink
dataset.accesslog.logentry.istio-system in your sink bucket.accesslog in your sink
topic.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
{{< text yaml >}} apiVersion: "config.istio.io/v1alpha2" kind: stackdriver metadata: name: handler namespace: <your defined namespace> {{< /text >}}
Added logInfo in spec
{{< text yaml >}} spec: logInfo: accesslog.logentry.istio-system: labelNames: - sourceIp - destinationIp ... ... sinkInfo: id: '<sink_id>' destination: '<sink_destination>' filter: '<log_filter>' {{< /text >}}
In 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
{{< text yaml >}} apiVersion: "config.istio.io/v1alpha2" kind: rule metadata: name: stackdriver namespace: istio-system spec: match: "true" # If omitted match is true actions:
Remove the new Stackdriver configuration:
{{< text bash >}} $ kubectl delete -f stackdriver.yaml {{< /text >}}
If you are not planning to explore any follow-on tasks, refer to the Bookinfo cleanup instructions to shutdown the application.
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.