home / tils / til

Menu
  • GraphQL API

til: cloudrun_gcloud-run-services-list.md

This data as json

path topic title url body html shot created created_utc updated updated_utc shot_hash slug
cloudrun_gcloud-run-services-list.md cloudrun Using the gcloud run services list command https://github.com/simonw/til/blob/main/cloudrun/gcloud-run-services-list.md The `gcloud run services list` command lists your services running on Google Cloud Run: ``` ~ % gcloud run services list --platform=managed SERVICE REGION URL LAST DEPLOYED BY LAST DEPLOYED AT ✔ calands us-central1 https://calands-j7hipcg4aq-uc.a.run.app ...@gmail.com 2020-09-02T00:15:29.563846Z ✔ cloud-run-hello us-central1 https://cloud-run-hello-j7hipcg4aq-uc.a.run.app ...@gmail.com 2020-09-02T00:16:07.835843Z ✔ covid-19 us-central1 https://covid-19-j7hipcg4aq-uc.a.run.app ...@gmail.com 2020-09-02T00:16:46.979188Z ... ``` It has two useful but under-documented options: `--filter` which filters based on a special filter language, and `--format` which customizes the output format. ## --filter I found the `--filter` option really hard to figure out. It has [documentation here](https://cloud.google.com/sdk/gcloud/reference/topic/filters) describing the predicate language it uses, but I had to apply trial and error to find options that worked for `gcloud run services`. Here are a few I found. To see data for just one specific service by name, use `--filter=SERVICE:covid-19`. Lowercase `service` doesn't work for some reason. ``` ~ % gcloud run services list --platform=managed --filter=SERVICE:covid-19 SERVICE REGION URL LAST DEPLOYED BY LAST DEPLOYED AT ✔ covid-19 us-central1 https://covid-19-j7hipcg4aq-uc.a.run.app ...@gmail.com 2020-09-02T00:16:46.979188Z ``` To filter by labels that you have set on your services, use `--filter="metadata.labels.name=value"`. It took me a while to figure out I needed the `metadata.` prefix here. Here's a filter for every service that does NOT have a label called `service` (I apply a label of 'service' to all of my services so I can [see them separately in billing](https://til.simonwillison.net/til/til/cloudrun_use-labels-for-billing-breakdown.md)). ``` gcloud run services list --platform=managed --filter='NOT metadata.labels.service:*' ``` ## --format The `--format` option is [documented here](https://cloud.google.com/sdk/gcloud/reference/topic/formats). Here's what I've worked out. `gcloud run services list --platform=managed --format=json` outputs JSON. `--format=yaml` outputs YAML. Two more interesting ones are `--format='table(colums go here)'` and `--format='csv(columns go here)'`. For example: ``` ~ % gcloud run services list --platform=managed --format='table(SERVICE,URL)' SERVICE URL calands https://calands-j7hipcg4aq-uc.a.run.app covid-19 https://covid-19-j7hipcg4aq-uc.a.run.app ``` Or for CSV: ``` ~ % gcloud run services list --platform=managed --format='csv(SERVICE,URL)' service,url calands,https://calands-j7hipcg4aq-uc.a.run.app covid-19,https://covid-19-j7hipcg4aq-uc.a.run.app ``` Other values I found that work include `REGION`, `labels` and `metadata`. The latter two output a not-valid-JSON (possibly Python `repr()`) nested structure: ``` ~ % gcloud run services list --platform=managed --format='table(SERVICE,labels,metadata)' --filter=SERVICE:covid-19 SERVICE LABELS METADATA covid-19 {'service': 'covid-19', 'cloud.googleapis.com/location': 'us-central1'} {'annotations': {'client.knative.dev/user-image': 'gcr.io/datasette-222320/datasette', 'run.googleapis.com/client-name': 'gcloud', 'run.googleapis.com/client-version': '302.0.0', 'serving.knative.dev/creator': 'swillison@gmail.com', 'serving.knative.dev/lastModifier': 'swillison@gmail.com'}, 'creationTimestamp': '2020-03-10T18:47:04.923274Z', 'generation': 670, 'labels': {'cloud.googleapis.com/location': 'us-central1', 'service': 'covid-19'}, 'name': 'covid-19', 'namespace': '99025868001', 'resourceVersion': 'AAWuSY0eaHQ', 'selfLink': '/apis/serving.knative.dev/v1/namespaces/99025868001/services/covid-19', 'uid': '6ff64723-a38d-4784-ac5e-07a745061845'} ``` <p>The <code>gcloud run services list</code> command lists your services running on Google Cloud Run:</p> <pre><code>~ % gcloud run services list --platform=managed SERVICE REGION URL LAST DEPLOYED BY LAST DEPLOYED AT ✔ calands us-central1 https://calands-j7hipcg4aq-uc.a.run.app ...@gmail.com 2020-09-02T00:15:29.563846Z ✔ cloud-run-hello us-central1 https://cloud-run-hello-j7hipcg4aq-uc.a.run.app ...@gmail.com 2020-09-02T00:16:07.835843Z ✔ covid-19 us-central1 https://covid-19-j7hipcg4aq-uc.a.run.app ...@gmail.com 2020-09-02T00:16:46.979188Z ... </code></pre> <p>It has two useful but under-documented options: <code>--filter</code> which filters based on a special filter language, and <code>--format</code> which customizes the output format.</p> <h2> <a id="user-content---filter" class="anchor" href="#--filter" aria-hidden="true"><span aria-hidden="true" class="octicon octicon-link"></span></a>--filter</h2> <p>I found the <code>--filter</code> option really hard to figure out. It has <a href="https://cloud.google.com/sdk/gcloud/reference/topic/filters" rel="nofollow">documentation here</a> describing the predicate language it uses, but I had to apply trial and error to find options that worked for <code>gcloud run services</code>. Here are a few I found.</p> <p>To see data for just one specific service by name, use <code>--filter=SERVICE:covid-19</code>. Lowercase <code>service</code> doesn't work for some reason.</p> <pre><code>~ % gcloud run services list --platform=managed --filter=SERVICE:covid-19 SERVICE REGION URL LAST DEPLOYED BY LAST DEPLOYED AT ✔ covid-19 us-central1 https://covid-19-j7hipcg4aq-uc.a.run.app ...@gmail.com 2020-09-02T00:16:46.979188Z </code></pre> <p>To filter by labels that you have set on your services, use <code>--filter="metadata.labels.name=value"</code>. It took me a while to figure out I needed the <code>metadata.</code> prefix here.</p> <p>Here's a filter for every service that does NOT have a label called <code>service</code> (I apply a label of 'service' to all of my services so I can <a href="https://til.simonwillison.net/til/til/cloudrun_use-labels-for-billing-breakdown.md" rel="nofollow">see them separately in billing</a>).</p> <pre><code>gcloud run services list --platform=managed --filter='NOT metadata.labels.service:*' </code></pre> <h2> <a id="user-content---format" class="anchor" href="#--format" aria-hidden="true"><span aria-hidden="true" class="octicon octicon-link"></span></a>--format</h2> <p>The <code>--format</code> option is <a href="https://cloud.google.com/sdk/gcloud/reference/topic/formats" rel="nofollow">documented here</a>. Here's what I've worked out.</p> <p><code>gcloud run services list --platform=managed --format=json</code> outputs JSON. <code>--format=yaml</code> outputs YAML.</p> <p>Two more interesting ones are <code>--format='table(colums go here)'</code> and <code>--format='csv(columns go here)'</code>. For example:</p> <pre><code>~ % gcloud run services list --platform=managed --format='table(SERVICE,URL)' SERVICE URL calands https://calands-j7hipcg4aq-uc.a.run.app covid-19 https://covid-19-j7hipcg4aq-uc.a.run.app </code></pre> <p>Or for CSV:</p> <pre><code>~ % gcloud run services list --platform=managed --format='csv(SERVICE,URL)' service,url calands,https://calands-j7hipcg4aq-uc.a.run.app covid-19,https://covid-19-j7hipcg4aq-uc.a.run.app </code></pre> <p>Other values I found that work include <code>REGION</code>, <code>labels</code> and <code>metadata</code>. The latter two output a not-valid-JSON (possibly Python <code>repr()</code>) nested structure:</p> <pre><code>~ % gcloud run services list --platform=managed --format='table(SERVICE,labels,metadata)' --filter=SERVICE:covid-19 SERVICE LABELS METADATA covid-19 {'service': 'covid-19', 'cloud.googleapis.com/location': 'us-central1'} {'annotations': {'client.knative.dev/user-image': 'gcr.io/datasette-222320/datasette', 'run.googleapis.com/client-name': 'gcloud', 'run.googleapis.com/client-version': '302.0.0', 'serving.knative.dev/creator': 'swillison@gmail.com', 'serving.knative.dev/lastModifier': 'swillison@gmail.com'}, 'creationTimestamp': '2020-03-10T18:47:04.923274Z', 'generation': 670, 'labels': {'cloud.googleapis.com/location': 'us-central1', 'service': 'covid-19'}, 'name': 'covid-19', 'namespace': '99025868001', 'resourceVersion': 'AAWuSY0eaHQ', 'selfLink': '/apis/serving.knative.dev/v1/namespaces/99025868001/services/covid-19', 'uid': '6ff64723-a38d-4784-ac5e-07a745061845'} </code></pre> <Binary: 73,290 bytes> 2020-09-01T21:40:04-07:00 2020-09-02T04:40:04+00:00 2020-09-01T21:40:25-07:00 2020-09-02T04:40:25+00:00 18f4f503f9530d61e27ad5f3c77d9bdd gcloud-run-services-list
Powered by Datasette · How this site works · Code of conduct