Соответствующий фрагмент кода:
Код: Выделить всё
Service service = serviceClient.getService(...)
List updatedTrafficTargets = ...
I fetch existing traffic targets from Cloud run using
service.getTrafficList(), and extract
the target that matches the one that I want to modify, then add
the percentage of traffic I want to split
...
Service serviceWithTrafficUpdate = Service.newBuilder()
.setName(service.getName())
.addAllTraffic(updatedTrafficTargets)
.build()
UpdateServiceRequest updateRequest = UpdateServiceRequest.newBuilder()
.setService(serviceWithTrafficUpdate)
.setUpdateMask(FieldMask.newBuilder().addPaths("traffic").build())
.build()
servicesClient.updateServiceAsync(updateRequest).get();
< /code>
Содержание запроса службы обновления при регистрации выглядит следующим образом: < /p>
service {
name: "projects/my-project/locations/us-central1/services/my-service"
traffic {
type: TRAFFIC_TARGET_ALLOCATION_TYPE_REVISION
revision: "my-target-revision-dfjs"
percent: 100
tag: "custom-B"
}
}
< /code>
Однако API отвечает ошибкой: < /p>
java.util.concurrent.ExecutionException: com.google.api.gax.rpc.AlreadyExistsException: io.grpc.StatusRuntimeException: ALREADY_EXISTS: Revision named 'my-target-revision-dfjs' with different configuration already exists.
< /code>
Я также попытался включить как пересмотр источника, от которой я разделяю, так и пересмотр цели, на которую я разделяю (с оставшимся 99 -процентным трафиком на источнике, и 1 процент на цель) < /p>
service {
name: "projects/my-project/locations/us-central1/services/my-service"
traffic {
type: TRAFFIC_TARGET_ALLOCATION_TYPE_REVISION
revision: "my-target-revision-dfjs"
percent: 1
tag: "custom-B"
}
traffic {
type: TRAFFIC_TARGET_ALLOCATION_TYPE_REVISION
revision: "my-source-revision-wkjl"
percent: 99
tag: "prod-A"
}
}
update_mask {
paths: "traffic"
}
< /code>
, что немного сбивает с толку, потому что, очевидно, мне нужно уже существовать, если я разделяю трафик на него; Что заставляет меня верить, что я, вероятно, каким -то образом использую клиентскую библиотеку. />n.b.: Для здравомыслия я попытался разделить трафик вручную с помощью gcloud Код: Выделить всё
gcloud run services update-traffic my-service --region=us-central1 --project=my-project --to-revisions=my-target-revision-dfjs=1,my-source-revision-wkjl=99
Подробнее здесь: https://stackoverflow.com/questions/797 ... nt-library