google-cloud-platformstackdrivergoogle-cloud-stackdriver

How do I write a stack driver log query that samples 5% of all logs returned?


I keep reading that I can write a log query to sample a percentage of logs but I have found zero examples.

https://cloud.google.com/blog/products/gcp/preventing-log-waste-with-stackdriver-logging\ You can also choose to sample certain messages so that only a percentage of the messages appear in Stackdriver Logs Viewer

How do I get 10% of all GCE load balancer logs with a log query? I know I can configure this on the backend, but I don't want that. I want to get 100% of logs in stackdriver and create a pub/sub log sink with a log query that only captures 10% of them and sends those sampled logs somewhere else.


Solution

  • I suspect you'll want to create a Pub/Sub sink for Log Router. See Configure and manage sinks

    Using Google's Log querying, you can use sample to filter (inclusion) logs.