Metric CRUD.

def metric_crud(client, to_delete):
    """Metric CRUD."""
    METRIC_NAME = "robots-%d" % (_millis(),)
    DESCRIPTION = "Robots all up in your server"
    FILTER = "logName:apache-access AND textPayload:robot"
    UPDATED_FILTER = "textPayload:robot"
    UPDATED_DESCRIPTION = "Danger, Will Robinson!"

    # [START client_list_metrics]
    for metric in client.list_metrics():  # API call(s)
        do_something_with(metric)
    # [END client_list_metrics]

    # [START metric_create]
    metric = client.metric(METRIC_NAME, filter_=FILTER, description=DESCRIPTION)
    assert not metric.exists()  # API call
    metric.create()  # API call
    assert metric.exists()  # API call
    # [END metric_create]
    to_delete.append(metric)

    # [START metric_reload]
    existing_metric = client.metric(METRIC_NAME)
    existing_metric.reload()  # API call
    # [END metric_reload]
    assert existing_metric.filter_ == FILTER
    assert existing_metric.description == DESCRIPTION

    # [START metric_update]
    existing_metric.filter_ = UPDATED_FILTER
    existing_metric.description = UPDATED_DESCRIPTION
    existing_metric.update()  # API call
    # [END metric_update]
    existing_metric.reload()
    assert existing_metric.filter_ == UPDATED_FILTER
    assert existing_metric.description == UPDATED_DESCRIPTION

    def _metric_delete():
        # [START metric_delete]
        metric.delete()
        # [END metric_delete]

    _backoff_not_found(_metric_delete)
    to_delete.remove(metric)