我如何获得谷歌云cdn无效缓存结果



我通过google cloud cdn的python客户端库发送了清理缓存的任务,并得到了GCP响应的请求id。但是,在哪里可以根据请求id查询清理缓存的任务进度呢?

发送请求的地址:https://cloud.google.com/compute/docs/reference/rest/v1/urlMaps/invalidateCache

发送请求的地址:https://cloud.google.com/compute/docs/reference/rest/v1/urlMaps/invalidateCache

在Log Explorer中,查看cloudaudit.googleapis.com提要和您的请求ID。您还可以使用protoPayload.request.@type="type.googleapis.com/compute.urlMaps.invalidateCache"过滤日志资源管理器日志,以列出所做的所有无效操作。

您可能需要扩展您的审计日志记录权限,否则信息可能对您不可见。

您不能使用请求ID查询缓存无效的状态;请求ID用于重复数据删除请求,而不是检索操作的状态。

要检索缓存无效的状态,请使用urlMaps中返回的操作名称。invalidateCache响应。您可以使用globalOperations.get查询指定操作的状态。

如果您正在使用Python客户端库,则可以使用GlobalOperationsClient类。有一个例子在gcloud的invalidate-cdn-cache实现在github.com/googleapis/python-compute/blob/main/google/cloud/compute_v1/services/url_maps/client.py.

我通过以下文档中的API查询Google Cloud CDN的Invalidate缓存结果:https://cloud.google.com/compute/docs/reference/rest/v1/globalOperations/get

我通过下面的python代码得到了我想要的信息:

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

最新更新