mirror of
https://github.com/jcreek/CosmicClash.git
synced 2026-09-14 09:42:02 +00:00
feat: add ranked season rollover policy
This commit is contained in:
+27
-17
@@ -8,16 +8,16 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
ProbeFreshness = 30 * time.Second
|
||||
ProbeFutureSkew = 5 * time.Second
|
||||
ProbeFreshness = 30 * time.Second
|
||||
ProbeFutureSkew = 5 * time.Second
|
||||
MaxOpaqueLocationBytes = 512
|
||||
DiscrepancyWindow = 24 * time.Hour
|
||||
DiscrepancyLimit = 3
|
||||
CleanSamplesToRelease = 5
|
||||
DiscrepancyWindow = 24 * time.Hour
|
||||
DiscrepancyLimit = 3
|
||||
CleanSamplesToRelease = 5
|
||||
)
|
||||
|
||||
var (
|
||||
ErrInvalidProbe = errors.New("invalid latency probe evidence")
|
||||
ErrInvalidProbe = errors.New("invalid latency probe evidence")
|
||||
ErrProbeQuarantined = errors.New("latency samples are quarantined")
|
||||
)
|
||||
|
||||
@@ -26,10 +26,10 @@ var (
|
||||
// no client-provided RTT is used for placement.
|
||||
type ProbeEvidence struct {
|
||||
OpaqueLocation []byte
|
||||
Nonce []byte
|
||||
IssuedAt time.Time
|
||||
Region string
|
||||
ServerRTT time.Duration
|
||||
Nonce []byte
|
||||
IssuedAt time.Time
|
||||
Region string
|
||||
ServerRTT time.Duration
|
||||
}
|
||||
|
||||
func ValidateProbe(evidence ProbeEvidence, expectedNonce []byte, now time.Time) error {
|
||||
@@ -52,9 +52,9 @@ func ValidateProbe(evidence ProbeEvidence, expectedNonce []byte, now time.Time)
|
||||
}
|
||||
|
||||
type DiscrepancyTracker struct {
|
||||
BadSamples []time.Time
|
||||
BadSamples []time.Time
|
||||
CleanSamples int
|
||||
Quarantined bool
|
||||
Quarantined bool
|
||||
}
|
||||
|
||||
// RecordComparison compares backend-computed predicted and observed RTT. A
|
||||
@@ -65,14 +65,20 @@ func (tracker *DiscrepancyTracker) RecordComparison(predicted, observed time.Dur
|
||||
maxAllowed := 25 * time.Millisecond
|
||||
if predicted > 0 {
|
||||
percent := time.Duration(float64(predicted) * 0.30)
|
||||
if percent > maxAllowed { maxAllowed = percent }
|
||||
if percent > maxAllowed {
|
||||
maxAllowed = percent
|
||||
}
|
||||
}
|
||||
delta := predicted - observed
|
||||
if delta < 0 { delta = -delta }
|
||||
if delta < 0 {
|
||||
delta = -delta
|
||||
}
|
||||
if delta > maxAllowed {
|
||||
tracker.BadSamples = append(tracker.BadSamples, now)
|
||||
tracker.CleanSamples = 0
|
||||
if len(tracker.BadSamples) >= DiscrepancyLimit { tracker.Quarantined = true }
|
||||
if len(tracker.BadSamples) >= DiscrepancyLimit {
|
||||
tracker.Quarantined = true
|
||||
}
|
||||
return
|
||||
}
|
||||
if tracker.Quarantined {
|
||||
@@ -89,12 +95,16 @@ func (tracker *DiscrepancyTracker) prune(now time.Time) {
|
||||
cutoff := now.Add(-DiscrepancyWindow)
|
||||
kept := tracker.BadSamples[:0]
|
||||
for _, sample := range tracker.BadSamples {
|
||||
if !sample.Before(cutoff) { kept = append(kept, sample) }
|
||||
if !sample.Before(cutoff) {
|
||||
kept = append(kept, sample)
|
||||
}
|
||||
}
|
||||
tracker.BadSamples = kept
|
||||
}
|
||||
|
||||
func (tracker DiscrepancyTracker) PlacementAllowed() error {
|
||||
if tracker.Quarantined { return ErrProbeQuarantined }
|
||||
if tracker.Quarantined {
|
||||
return ErrProbeQuarantined
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user