-1

I have sent the task of clearing the cache through the python client library of google cloud cdn, and got the request id of the GCP response. However, where can I query the progress of the task of clearing the cache according to the request id.

The address where I send the request: https://cloud.google.com/compute/docs/reference/rest/v1/urlMaps/invalidateCache

The address where I send the request: https://cloud.google.com/compute/docs/reference/rest/v1/urlMaps/invalidateCache

Duojie
  • 23
  • 4

3 Answers3

0

In Log Explorer, look under the cloudaudit.googleapis.com feed along with your request ID. You could also just filter your log explorer logs using protoPayload.request.@type="type.googleapis.com/compute.urlMaps.invalidateCache" to list all the invalidations made.

You may need to extend your audit logging permissions, else the information may not be visible to you.

Dave
  • 434
  • 5
0

You can't query the status of a cache invalidation using the request ID; the request ID is used for deduplicating requests, not retrieving the status of an operation.

To retrieve the status of a cache invalidation, use the operation name returned in the urlMaps.invalidateCache response. You can query the status of the named operation using globalOperations.get.

If you're using the Python client library, you can use the GlobalOperationsClient class. There's an example in gcloud's invalidate-cdn-cache implementation at github.com/googleapis/python-compute/blob/main/google/cloud/compute_v1/services/url_maps/client.py.

elving
  • 1,441
  • 8
  • 7
0

I query the Invalidate cache result of Google Cloud CDN through the API in the following document: https://cloud.google.com/compute/docs/reference/rest/v1/globalOperations/get

And I got the information I want through the following python code:

def get_operation_result(gcp_request_id):
    credentials = GoogleCredentials.get_application_default()

    service = discovery.build('compute', 'v1', credentials=credentials)

    # Project ID for this request.
    project = 'my-project'  # TODO: Update placeholder value.

    # Name of the Operations resource to return.
    operation = gcp_request_id  # TODO: Update placeholder value.

    request = service.globalOperations().get(project=project, operation=operation)
    response = request.execute()

    # TODO: Change code below to process the `response` dict:
    mission_status = response['status']
    return mission_status
Duojie
  • 23
  • 4
  • lol! You're welcome, I guess. I notice that you're still calling the operation name a request ID. While request IDs are a GCP concept, they're completely separate from operation names. – elving Jan 27 '23 at 05:49