Cloud Run Traffic Splitting: Need for Fractional Percentages in Version 1.x
0 reputation · 03 Feb 2023, 21:24 UTC
0 reputation · 03 Feb 2023, 21:24 UTC
Enable precise, non‑integer traffic allocation to revisions for canary and blue‑green deployments, such as 33.3%/33.3%/33.4% splits.
33775 reputation · 04 Feb 2023, 04:11 UTC
Google Cloud Run currently requires traffic weights to be defined as integers. Fractional percentages (e.g., 33.3%) are not supported by the Cloud Run API, the gcloud CLI, or the Google Cloud Console. Any attempt to input decimal values will result in a validation error.
The Cloud Run traffic management system is designed around a simple weighted distribution where the sum of all revision weights must equal exactly 100. Because the underlying API schema expects integer values, there is no native mechanism to handle floating-point precision for traffic steering.
Since native fractional splitting is unavailable, you can approximate these distributions using the following methods:
To apply a split using the CLI, ensure your values are whole numbers. For example, to split traffic between two revisions:
gcloud run services update-traffic [SERVICE_NAME] --to-revisions [REVISION_A]=33,[REVISION_B]=67
To verify the current allocation and ensure no rounding errors occurred during deployment, run:
gcloud run services describe [SERVICE_NAME]
When approximating splits with integers, be aware that for very low-traffic services, the actual request distribution may deviate from your defined percentages due to the nature of load balancing algorithms and connection pooling. This is a characteristic of the distribution mechanism rather than a result of the integer constraint.
Diagnostic Detail Needed: Are you utilizing a Global External Load Balancer (XLB) in front of your service, or are you relying solely on the default *.a.run.app URL?
Use comments to ask for clarification. Post a solution as an answer.
33,775 reputation · 04 Feb 2023, 01:56 UTC
The Cloud Run traffic‑weight field is defined as an integer in the REST schema. Any attempt to provide values like 33.3 or 33.4 triggers a validation error from both the gcloud CLI and the API. The sum of all revision weights must equal 100 and each value must be between 0 and 100.
For splits finer than 1% you can place Cloud Run behind a Global External HTTP(S) Load Balancer. By creating three backend services pointing to the same Cloud Run service and assigning backend weights 333, 333, and 334, you achieve an effective 33.3/33.3/33.4 split. This adds a small latency and cost overhead but gives true fractional routing.
When approximating with integers (e.g., 33/33/34), apply a consistent rounding strategy to avoid cumulative bias across revisions.