"gcloud app logs tail" shows weekly data

I am trying to transfer logs for my Google Cloud Platform application. The first thing I notice is that Google sends about 10 medical hours per second, at least, so I need to grep -v /healthget any useful information. Is this a standard?

Secondly, he transfers old magazines. I start gcloud app logs tail -s defaultand receive magazines from April 11 (a week at the moment). Newer magazines (4, 3, and 2 days ago) flow slowly over several hours. I just click update in my application (which triggers a log message) and does not see new logs.

Is there a way to get an idea of ​​new log messages in real time (within minutes or hours)?

+6
source share
1 answer

For health points you do not need to rely on grep. Filters are included in the SDK , so you can simply filter the output. However, you just hide them on the terminal, but the SDK will still get them from the API (as with use grep). A more optimal way would be to use gcloud logging read 'resource.type="gae_app" AND logName:"logs/appengine.googleapis.com%2Frequest_log" AND protoPayload.resource!="/health"' --order desc, since you only request logs matching the custom filter. This gives a fairly detailed log, so you can format the output directly to the SDK to make it look like you like gcloud app logs tail.

Since it gcloud loggingdoes not have a tail mode, you can simply wrap it in watchlike:

watch 'gcloud logging read "resource.type=\"gae_app\" AND logName:\"logs/appengine.googleapis.com%2Frequest_log\" AND protoPayload.resource!=\"/health\"" --order desc --limit 1'

--format, , --limit - , ( , ).

, gcloud app logs tail -s default --log-http , SDK, , API, , .

, API, watch.

API , .

, , ( ). - , .

. GAE, , protoPayload ( , ).

, API (: quote escape-hell):

watch -tcn 0.5 'curl  -H"Authorization: Bearer $(gcloud auth print-access-token)" \
   -H"Content-Type: application/json" \
   "https://logging.googleapis.com/v2/entries:list?fields=entries%2FprotoPayload" \
   -d"{
   \"filter\":\"resource.type=\\\"gae_app\\\"
                logName=\\\"projects/$(gcloud config get-value project)/logs/appengine.googleapis.com%2Frequest_log\\\"\",
   \"pageSize\":$(tput lines),
   \"orderBy\":\"timestamp desc\",
   \"resourceNames\": [
      \"projects/$(gcloud config get-value project)\"
   ]
 }" 2>\dev\null |jq -cC ".entries[].protoPayload | { timestamp: .startTime, method, status, latency, URL: (.host + .resource) }"'

jq , , .

0

Source: https://habr.com/ru/post/1016610/


All Articles