Skip to content

Commit

Permalink
Fix spelling of Reservior (#237)
Browse files Browse the repository at this point in the history
Co-authored-by: Jon Armen <[email protected]>
  • Loading branch information
jon-armen and jon-armen committed Apr 15, 2022
1 parent 6cd55ac commit 14ce4c1
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 43 deletions.
8 changes: 4 additions & 4 deletions sdk/src/Core/Sampling/DefaultSamplingStrategy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -127,17 +127,17 @@ public SamplingResponse ShouldTrace(SamplingInput input)
private SamplingResponse ProcessMatchedRule(SamplingRule sampleRule, TimeStamp time)
{
bool shouldSample = true;
Reservior reservior = sampleRule.Reservior;
Reservoir reservoir = sampleRule.Reservoir;
SamplingResponse sampleResult = null;

sampleRule.IncrementRequestCount(); // increment request counter for matched rule
ReserviorDecision reserviorDecision = reservior.BorrowOrTake(time, sampleRule.CanBorrow); // check if we can borrow or take from reservior
ReservoirDecision reservoirDecision = reservoir.BorrowOrTake(time, sampleRule.CanBorrow); // check if we can borrow or take from reservoir

if (reserviorDecision == ReserviorDecision.Borrow)
if (reservoirDecision == ReservoirDecision.Borrow)
{
sampleRule.IncrementBorrowCount();
}
else if (reserviorDecision == ReserviorDecision.Take)
else if (reservoirDecision == ReservoirDecision.Take)
{
sampleRule.IncrementSampledCount();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//-----------------------------------------------------------------------------
// <copyright file="Reservior.cs" company="Amazon.com">
// <copyright file="Reservoir.cs" company="Amazon.com">
// Copyright 2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License").
Expand All @@ -20,23 +20,23 @@
namespace Amazon.XRay.Recorder.Core.Sampling
{
/// <summary>
/// Thread safe reservior which holds fixed sampling quota, borrowed count and TTL.
/// Thread safe reservoir which holds fixed sampling quota, borrowed count and TTL.
/// </summary>
public class Reservior
public class Reservoir
{
private TimeStamp _thisSec = new TimeStamp();
private TimeStamp _refereshedAt = new TimeStamp();
private int _takenThisSec;
private int _borrowedThisSec;
private readonly int _defaultInterval = 10; // 10 seconds
private readonly ReaderWriterLockSlim _lock = new ReaderWriterLockSlim();
private static readonly Logger _logger = Logger.GetLogger(typeof(Reservior));
private static readonly Logger _logger = Logger.GetLogger(typeof(Reservoir));

public TimeStamp TTL { get; set; }
public int? Quota { get; set; }
public int? Interval { get; set; }

internal Reservior()
internal Reservoir()
{
Quota = null;
TTL = null;
Expand All @@ -45,12 +45,12 @@ internal Reservior()
}

/// <summary>
/// If quota is valid, <see cref="ReserviorDecision"/> is either take or no else 1 request/sec is borrowed.
/// If quota is valid, <see cref="ReservoirDecision"/> is either take or no else 1 request/sec is borrowed.
/// </summary>
/// <param name="current"> Current timestamp.</param>
/// <param name="canBorrow">If true, and quota not valid, single request is borrowed in the current sec for the given <see cref="SamplingRule"/>.</param>
/// <returns>The reservior decision.</returns>
internal ReserviorDecision BorrowOrTake(TimeStamp current, bool canBorrow)
/// <returns>The reservoir decision.</returns>
internal ReservoirDecision BorrowOrTake(TimeStamp current, bool canBorrow)
{
_lock.EnterWriteLock();
try
Expand All @@ -61,23 +61,23 @@ internal ReserviorDecision BorrowOrTake(TimeStamp current, bool canBorrow)
{
if(_takenThisSec >= Quota)
{
return ReserviorDecision.No;
return ReservoirDecision.No;
}
_takenThisSec += 1;
return ReserviorDecision.Take;
return ReservoirDecision.Take;
}

if (canBorrow) // Otherwise try to borrow if the quota is not present or expired.
{
if(_borrowedThisSec >= 1)
{
return ReserviorDecision.No;
return ReservoirDecision.No;
}
_borrowedThisSec += 1;
return ReserviorDecision.Borrow;
return ReservoirDecision.Borrow;
}

return ReserviorDecision.No;
return ReservoirDecision.No;
}
finally
{
Expand All @@ -96,7 +96,7 @@ internal ReserviorDecision BorrowOrTake(TimeStamp current, bool canBorrow)
}

/// <summary>
/// Load quota, ttl and interval into current reservior.
/// Load quota, ttl and interval into current reservoir.
/// </summary>
/// <param name="t">Instance of <see cref="Target"/>.</param>
/// <param name="now">Current timestamp.</param>
Expand All @@ -105,9 +105,9 @@ internal void LoadQuota(Target t, TimeStamp now)
_lock.EnterWriteLock();
try
{
if (t.ReserviorQuota != null)
if (t.ReservoirQuota != null)
{
Quota = t.ReserviorQuota;
Quota = t.ReservoirQuota;
}

if (t.TTL != null)
Expand Down Expand Up @@ -140,7 +140,7 @@ internal bool ShouldReport(TimeStamp now)
}
}

internal void CopyFrom(Reservior r)
internal void CopyFrom(Reservoir r)
{
_lock.EnterWriteLock();
try
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//-----------------------------------------------------------------------------
// <copyright file="ReserviorDecision.cs" company="Amazon.com">
// <copyright file="ReservoirDecision.cs" company="Amazon.com">
// Copyright 2016 Amazon.com, Inc. or its affiliates. All Rights Reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License").
Expand All @@ -21,7 +21,7 @@ namespace Amazon.XRay.Recorder.Core.Sampling
/// An Enum of decisions, the reservoir could make based on
/// assigned quota with TTL and the current timestamp/usage.
/// </summary>
public enum ReserviorDecision
public enum ReservoirDecision
{
Take = 't',
Borrow = 'b',
Expand Down
2 changes: 1 addition & 1 deletion sdk/src/Core/Sampling/RuleCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ public void LoadTargets(IList<Target> targets)
{
if (_cache.TryGetValue(t.RuleName, out SamplingRule rule))
{
rule.Reservior.LoadQuota(t, now);
rule.Reservoir.LoadQuota(t, now);
rule.SetRate(t.FixedRate);
}
}
Expand Down
8 changes: 4 additions & 4 deletions sdk/src/Core/Sampling/SamplingRule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public class SamplingRule : IComparable<SamplingRule>
public string Host { get; set; }
public string RuleName { get; set; }
public int Priority { get; set; }
public Reservior Reservior { get; set; }
public Reservoir Reservoir { get; set; }
public double Rate { get; private set; }
public int ReservoirSize { get; private set; }
public string HTTPMethod { get; set; }
Expand Down Expand Up @@ -63,7 +63,7 @@ public SamplingRule(string ruleName, int priority, double fixedRate, int reservo
ServiceType = serviceType;
ResourceARN = resourceARN;
Attributes = attributes;
Reservior = new Reservior();
Reservoir = new Reservoir();
Statistics = new Statistics();
}

Expand Down Expand Up @@ -156,7 +156,7 @@ internal double GetRate()

internal bool ShouldReport(TimeStamp now)
{
if (EverMatched() && Reservior.ShouldReport(now))
if (EverMatched() && Reservoir.ShouldReport(now))
{
return true;
}
Expand All @@ -172,7 +172,7 @@ internal bool EverMatched()
internal void Merge(SamplingRule oldRule)
{
Statistics.CopyFrom(oldRule.Statistics);
Reservior.CopyFrom(oldRule.Reservior);
Reservoir.CopyFrom(oldRule.Reservoir);
oldRule = null;
}

Expand Down
6 changes: 3 additions & 3 deletions sdk/src/Core/Sampling/Target.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ public class Target
public double FixedRate;

/// <summary>
/// Reservior quota for the rule.
/// Reservoir quota for the rule.
/// </summary>
public int? ReserviorQuota;
public int? ReservoirQuota;

/// <summary>
/// TTL for the rule.
Expand All @@ -51,7 +51,7 @@ public Target(string ruleName, double fixedRate, int? reservoirQuota, DateTime?
{
RuleName = ruleName;
FixedRate = fixedRate;
ReserviorQuota = reservoirQuota;
ReservoirQuota = reservoirQuota;
TTL = new TimeStamp(ttl);
Interval = interval;
}
Expand Down
24 changes: 12 additions & 12 deletions sdk/test/UnitTests/RuleCacheTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,15 +94,15 @@ public void TestLoadRulesSort() // Test whether cache is sorted after LoadRules

rulesInCache = ruleCache.GetRules(); // check targets value is copied

Reservior actualReservior2 = rulesInCache[0].Reservior;
Assert.AreEqual(currentTime.Time, actualReservior2.TTL.Time);
Assert.AreEqual(t2.Interval, actualReservior2.Interval);
Assert.AreEqual(t2.ReserviorQuota, actualReservior2.Quota);
Reservoir actualReservoir2 = rulesInCache[0].Reservoir;
Assert.AreEqual(currentTime.Time, actualReservoir2.TTL.Time);
Assert.AreEqual(t2.Interval, actualReservoir2.Interval);
Assert.AreEqual(t2.ReservoirQuota, actualReservoir2.Quota);

Reservior actualReservior1 = rulesInCache[1].Reservior;
Assert.AreEqual(currentTime.Time, actualReservior1.TTL.Time);
Assert.AreEqual(t1.Interval, actualReservior1.Interval);
Assert.AreEqual(t1.ReserviorQuota, actualReservior1.Quota);
Reservoir actualReservoir1 = rulesInCache[1].Reservoir;
Assert.AreEqual(currentTime.Time, actualReservoir1.TTL.Time);
Assert.AreEqual(t1.Interval, actualReservoir1.Interval);
Assert.AreEqual(t1.ReservoirQuota, actualReservoir1.Quota);

}

Expand Down Expand Up @@ -150,10 +150,10 @@ public void TestLoadRulesSort() // Test whether cache is sorted after LoadRules
Assert.AreEqual(1, rulesInCache.Count); // only one rule should be present and statefule info should be carried from old rule
Assert.AreEqual(1, rulesInCache[0].Priority); // implies new rule is added to cache

Reservior actualReservior1 = rulesInCache[0].Reservior;
Assert.AreEqual(currentTime.Time, actualReservior1.TTL.Time);
Assert.AreEqual(t1.Interval, actualReservior1.Interval);
Assert.AreEqual(t1.ReserviorQuota, actualReservior1.Quota);
Reservoir actualReservoir1 = rulesInCache[0].Reservoir;
Assert.AreEqual(currentTime.Time, actualReservoir1.TTL.Time);
Assert.AreEqual(t1.Interval, actualReservoir1.Interval);
Assert.AreEqual(t1.ReservoirQuota, actualReservoir1.Quota);

Statistics statistics = rulesInCache[0].Statistics;
Assert.AreEqual(expectedStatistic.RequestCount, statistics.RequestCount);
Expand Down

0 comments on commit 14ce4c1

Please sign in to comment.