A canary release exposes a new version to a small traffic slice and compares its health with the stable version before wider rollout.
Design a CanaryReleaseEvaluator class:
CanaryReleaseEvaluator() creates a stateless evaluator.String decide(int canaryErrors, int canaryTotal, int baselineErrors, int baselineTotal, int threshold) returns "rollback" or "promote".
threshold is an allowed difference in percentage points. Roll back only when:
Otherwise, promote. In particular, a canary whose rate is better than the baseline, equal to it, or exactly threshold points worse must be promoted.
Use integer cross-multiplication so the decision is exact:
Use wide integer arithmetic for every product. Each call is independent.
Example 1:
Input:
Output:
Explanation: The canary has a 5% error rate and the baseline has a 2% rate. The 3-point difference is greater than the 1-point threshold.
Example 2:
Input:
Output:
Explanation: The canary rate is 3% and the baseline rate is 2%. The difference equals the allowed 1 percentage point, so the release is promoted.
Constraints
1 <= canaryTotal, baselineTotal <= 10^60 <= canaryErrors <= canaryTotal0 <= baselineErrors <= baselineTotal0 <= threshold <= 100threshold is measured in percentage points.- Use 64-bit integer arithmetic for intermediate products.
- At most
100 calls are made to decide.