Is there a way to setup a log based counter metric to detect CR cold starts? What would be the log message to parse if it is available out of the box?
Hello @dheerajpanyam ,Welcome on Google Cloud Community.
Unfortunately logs are not shows directly that container have been created or cold start has been observed. I found two logs entries which might help you count cold starts:
1. Hello from Cloud Run! The container started successfully and is listening for HTTP requests on $PORT
{
"textPayload": "2024/06/11 07:21:12 Hello from Cloud Run! The container started successfully and is listening for HTTP requests on $PORT",
"insertId": "6667fae8000ed26210cfe6f7",
"resource": {
"type": "cloud_run_revision",
"labels": {
"service_name": "cold-start",
"revision_name": "cold-start-00001-klf",
"project_id": "webaap-wordpress-load",
"location": "us-central1",
"configuration_name": "cold-start"
}
},
"timestamp": "2024-06-11T07:21:12.971362Z",
"labels": {
"instanceId": "005b70877061811d26475bf28cb34ab59df21a9c17156de648376f26308db2011a208481dc9ec7f8db0002b57c42ab726057984d9f5e126f5fcdef6a5629e8f2"
},
"logName": "projects/webaap-wordpress-load/logs/run.googleapis.com%2Fstderr",
"receiveTimestamp": "2024-06-11T07:21:12.978704723Z"
}
Following log entry indicates that a Cloud Run container named "cold-start-00001-klf" in this case within the "cold-start" service in this case has successfully started and is ready to receive HTTP requests.
2. Default STARTUP TCP probe succeeded after 1 attempt for container "hello-1" on port 8080.
{
"textPayload": "Default STARTUP TCP probe succeeded after 1 attempt for container \"hello-1\" on port 8080.",
"insertId": "6667fae8000f153512cfa794",
"resource": {
"type": "cloud_run_revision",
"labels": {
"location": "us-central1",
"project_id": "webaap-wordpress-load",
"configuration_name": "cold-start",
"service_name": "cold-start",
"revision_name": "cold-start-00001-klf"
}
},
"timestamp": "2024-06-11T07:21:12.988469Z",
"severity": "INFO",
"labels": {
"instanceId": "005b70877061811d26475bf28cb34ab59df21a9c17156de648376f26308db2011a208481dc9ec7f8db0002b57c42ab726057984d9f5e126f5fcdef6a5629e8f2"
},
"logName": "projects/webaap-wordpress-load/logs/run.googleapis.com%2Fvarlog%2Fsystem",
"receiveTimestamp": "2024-06-11T07:21:12.994636043Z"
}
Log entry indicates that the startup TCP probe for the "hello-1" container in this case on port 8080 in the "cold-start" revision in this case of the "cold-start" service in this case successfully completed after one attempt.
I've tried to find also any metric, related with cold start, however without any luck,.
--
cheers,
DamianS
LinkedIn medium.com Cloudskillsboost
Yes, you can set up a log-based counter metric to detect Cloud Run cold starts by parsing log messages containing the phrase "cold start."
Hello @maverickwhites
Show me query example or evidence screenshot please, as I cannot found any log entry with phrase "cold start".
--
cheers,
DamianS
LinkedIn medium.com Cloudskillsboost
I tried the following log query to look for coldstarts and it didn't return anything
resource.type = "cloud_run_revision"
resource.labels.service_name = "my-service-production"
resource.labels.location = "us-east1"
jsonPayload.message =~ "coldstart"
severity>=DEFAULT
Yup, I didn't found any logs containing various word schema "coldstart" either.