我想用云函数以编程方式删除基于日志的度量。我写了以下脚本:
for metric in client_metric.list_metrics():
if metric.name not in item_list:
metric.delete()
print('delete {}'.format(metric.name))
item_list
包含我不想删除的度量的列表。
当测试功能时,我有以下错误:
status = StatusCode.FAILED_PRECONDITION
details = "The metric was modified during the request."
debug_error_string = "{"created":"@1636482330.781263800","description":"Error received from peer ipv4:172.217.20.202:443","file":"src/core/lib/surface/call.cc","file_line":1069,"grpc_message":"The metric was modified during the request.","grpc_status":9}"
这里怎么了?
好的,在像这样使用它之前,我需要定义度量:
metric = client_metric.metric(
metric.name
)
最终代码看起来是这样的:
for metric in client_metric.list_metrics():
if metric.name not in item_list:
metric = client_metric.metric(
metric.name
)
metric.delete()
但我还是不明白为什么要这样做。