Search code examples
google-cloud-platformstackdriver

Filter stackdriver logs from google http loadbalancers by hostname


I want to filter requests on a google http loadbalancer by hostname. The http loadbalancer produces stackdriver logs that can be searched. I'd imagine that I can search for the start of httpRequest.requestUrl like this:

resource.type="http_load_balancer"
httpRequest.requestUrl=starts_with("https://example.com")

I assumed this would work after reading https://cloud.google.com/monitoring/api/v3/filters . Unfortunately this returns Invalid request: Non-Global functions are currently unsupported

I don't mind if I have to perform separate searches for http and https.


Solution

  • The URL you are looking at is for Stackdriver Monitoring. I assume you are looking to filter it on Stackdriver Logging.

    To filter 'http' and 'https' on Stackdriver Logging use the advanced filters as seen below. Please note that the operator that matches httpRequest.requestUrl is a colon :, not an equals sign =.

    For HTTP

    resource.type="http_load_balancer"
    httpRequest.requestUrl:"http://example.com"
    

    For HTTPS

    resource.type="http_load_balancer"
    httpRequest.requestUrl:"https://example.com"
    

    Please note that this will search the whole field httpRequest.requestUrl for the given string. Technically speaking this is wrong, but it should work just fine for most hostname searches.