evaluate method
Implementation
@override
Future<DVGateOutcome> evaluate(DVReleaseGateContext context) async {
final String candidate = context.candidate.id;
final String? previous = context.previous?.id;
if (previous == null) {
const String code = 'DV-RELEASE-003';
final String message =
'release $candidate has no previous release to compare against; the '
'gate held the rollout rather than passing it vacuously';
_diagnose(code, message);
return DVGateOutcome.hold(name, message, code: code);
}
final _Read now = await _readTraffic(candidate, context);
if (now.hold != null) return now.hold!;
final _Read before = await _readTraffic(previous, context);
if (before.hold != null) return before.hold!;
final DVReleaseTraffic c = now.traffic!;
final DVReleaseTraffic b = before.traffic!;
for (final DVRequestStage stage in thresholds.stages.keys) {
for (final (String release, DVReleaseTraffic t) in <(String, DVReleaseTraffic)>[
(candidate, c),
(previous, b),
]) {
if (!t.stageFailures.containsKey(stage)) {
return DVGateOutcome.hold(
name,
'stage ${stage.number} (${stage.name}) failures were not reported '
'for $release, and an unreported stage is not a clean one',
);
}
}
}
if (c.latencyP95 == null || b.latencyP95 == null) {
return DVGateOutcome.hold(
name,
'p95 latency was not reported for '
'${c.latencyP95 == null ? candidate : previous}',
);
}
final List<String> regressions = <String>[];
final double cRate = c.failed / c.requests;
final double bRate = b.failed / b.requests;
if (cRate - bRate > thresholds.errorRate + _epsilon) {
regressions.add(
'error rate ${_pct(cRate)} against ${_pct(bRate)}, over the '
'${_pct(thresholds.errorRate)} margin',
);
}
final Map<String, Object?> stages = <String, Object?>{};
thresholds.stages.forEach((DVRequestStage stage, double margin) {
final double cs = c.stageFailures[stage]! / c.requests;
final double bs = b.stageFailures[stage]! / b.requests;
stages['${stage.number}'] = <String, double>{'candidate': cs, 'previous': bs};
if (cs - bs > margin + _epsilon) {
regressions.add(
'stage ${stage.number} (${stage.name}) failures ${_pct(cs)} against '
'${_pct(bs)}, over the ${_pct(margin)} margin',
);
}
});
final int cp95 = c.latencyP95!.inMicroseconds;
final int bp95 = b.latencyP95!.inMicroseconds;
if (cp95 > bp95 * (1 + thresholds.latencyP95Increase) + _epsilon) {
regressions.add(
'p95 latency ${cp95 / 1000} ms against ${bp95 / 1000} ms, over the '
'+${(thresholds.latencyP95Increase * 100).toStringAsFixed(0)}% margin',
);
}
final Map<String, Object?> evidence = <String, Object?>{
'candidate': candidate,
'previous': previous,
'requests': <String, int>{'candidate': c.requests, 'previous': b.requests},
'errorRate': <String, double>{'candidate': cRate, 'previous': bRate},
'stages': stages,
'latencyP95Micros': <String, int>{'candidate': cp95, 'previous': bp95},
};
if (regressions.isNotEmpty) {
return DVGateOutcome.rollBack(
name,
'$candidate regressed against $previous: ${regressions.join('; ')}',
evidence: evidence,
);
}
return DVGateOutcome.pass(name, evidence: evidence);
}