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
KK2491
5081 gold badge10 silver badges28 bronze badges
-
1Are all your services written a log entry these 30 last days?guillaume blaquiere– guillaume blaquiere2021年08月12日 18:54:22 +00:00Commented Aug 12, 2021 at 18:54
-
1Cloud run logs to Cloud Logging automatically. Provide details about missing services and how you are determining they are missing in the logs.John Hanley– John Hanley2021年08月12日 18:57:13 +00:00Commented 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 explorerKK2491– KK24912021年08月30日 11:14:41 +00:00Commented Aug 30, 2021 at 11:14
1 Answer 1
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
DazWilkin
41.7k8 gold badges61 silver badges113 bronze badges
Sign up to request clarification or add additional context in comments.
2 Comments
KK2491
Apologies for the delayed response. I am bit confused here, could you please help me understanding where I need to update the given snippet?
DazWilkin
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.Explore related questions
See similar questions with these tags.