ahmetb / cloud-run-faq

Unofficial FAQ and everything you've been wondering about Google Cloud Run.
https://cloud.run
Creative Commons Attribution 4.0 International
2.32k stars 124 forks source link

Flushing logs after request has finished. #133

Open Henery309 opened 3 years ago

Henery309 commented 3 years ago

Hi I am working on a POC for cloud run to use in our app.

I came across 1 interesting use case. The docs for google cloud logging suggest that for high throughput applications we should avoid awaiting when logging (background process takes care of it).

From my understanding - once a request is completed cloud run will immediately throttle the CPU in which case the pending logging request will be dropped. Are we able to flush the logs after the request has completed or do we have to log before returning the response? Logging request takes approximately 300ms adding this time onto the request would be an issue.

Cloud Logging Docs

image

ahmetb commented 3 years ago

Your analysis is correct. We recommend doing the same for distributed traces. 

Henery309 commented 3 years ago

@ahmetb what if we mark the container as keep warm. If we try to send logs after request has finished will they be dropped?

ahmetb commented 3 years ago

Warm containers don't mean their cpu is allocated. So you can still lose logs if they're not getting requests when the log flush timer fires.