1

I am trying to analyze the logs for the services running in Cloud Run using Google Cloud Operations Logging (Logging Explorer). The logs are present if I use the Logs section present in Cloud Run. However, not all the services running in Cloud Run are present in the Google Cloud Logging. Is there any configuration changes required to make the cloud service reflect in the Logging?

Thank you

asked Aug 12, 2021 at 17:43
3
  • 1
    Are all your services written a log entry these 30 last days? Commented Aug 12, 2021 at 18:54
  • 1
    Cloud run logs to Cloud Logging automatically. Provide details about missing services and how you are determining they are missing in the logs. Commented Aug 12, 2021 at 18:57
  • @guillaumeblaquiere yes, We have been running our Cloud run services continuously. And we could see the logs in section available in Cloud run. But the same is missing in Logs explorer Commented Aug 30, 2021 at 11:14

1 Answer 1

2

This should give you an easy reconciliation:

# The Project in which the Cloud Run services are deployed
PROJECT=.... # GCP Project ID
# The list of Cloud Run services in the project
SERVICES=$(gcloud run services list \
--project=${PROJECT} \
--format="value(metadata.name)") && echo ${SERVICES}
# For each service
for SERVICE in ${SERVICES}
do
 # Filter the service's logs
 FILTER="resource.type=\"cloud_run_revision\" resource.labels.service_name=\"${SERVICE}\""
 # Count them (there is likely a better way)
 COUNT=$(gcloud logging read "${FILTER}" \
 --project=${PROJECT} \
 --format="value(textPayload)" | wc -l)
 # List the services and their log counts
 printf "%s\t\t%s\n" ${SERVICE} ${COUNT}
done
answered Aug 13, 2021 at 20:47
Sign up to request clarification or add additional context in comments.

2 Comments

Apologies for the delayed response. I am bit confused here, could you please help me understanding where I need to update the given snippet?
The (Linux|bash) script uses gcloud to list the Cloud Run services in a project, grab a count of each service's log entries and output them. This demonstrates that service logs are written to Cloud Logging and should give you a basis upon which to develop your own solution.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.