Reputation: 2876
I want to delete log-based metric programmatically with a cloud functions. I wrote the following script:
for metric in client_metric.list_metrics():
if metric.name not in item_list:
metric.delete()
print('delete {}'.format(metric.name))
item_list
contains the list of the metric I don't want to delete.
When testing the function I have the following error:
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}"
What's wrong here?
Upvotes: 0
Views: 568
Reputation: 2876
ok I need to define the metric before using it like this:
metric = client_metric.metric(
metric.name
)
Ultimately the code looks like this:
for metric in client_metric.list_metrics():
if metric.name not in item_list:
metric = client_metric.metric(
metric.name
)
metric.delete()
still I'm not sure I understand why it needs to be done like this.
Upvotes: 1