-
Notifications
You must be signed in to change notification settings - Fork 501
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Internal] CTL: Fixes Reservoir Sampling Logic (#3712)
* Code changes to fix the reservoir sampling logic in CTL * Code changes to modify help text on reservoir type. * Code changes to address minor code refactor.
- Loading branch information
1 parent
67e1a90
commit b257f8e
Showing
5 changed files
with
66 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
Microsoft.Azure.Cosmos.Samples/Tools/CTL/ReservoirProvider.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
//------------------------------------------------------------ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
//------------------------------------------------------------ | ||
|
||
namespace CosmosCTL | ||
{ | ||
using System; | ||
using App.Metrics.ReservoirSampling; | ||
|
||
/// <summary> | ||
/// Returns the <see cref="IReservoir"/> based on the CTL configuration. | ||
/// </summary> | ||
public class ReservoirProvider | ||
{ | ||
/// <summary> | ||
/// Create and returns a new instance of the <see cref="IReservoir"/> based on the CTL configuration. | ||
/// </summary> | ||
/// <param name="ctlConfig">An instance of <see cref="CTLConfig"/> containing the CTL config params.</param> | ||
/// <returns>An implementation of <see cref="IReservoir"/>.</returns> | ||
public static IReservoir GetReservoir(CTLConfig ctlConfig) | ||
{ | ||
return ctlConfig.ReservoirType switch | ||
{ | ||
ReservoirTypes.Uniform => new App.Metrics.ReservoirSampling.Uniform.DefaultAlgorithmRReservoir( | ||
sampleSize: ctlConfig.ReservoirSampleSize), | ||
|
||
ReservoirTypes.SlidingWindow => new App.Metrics.ReservoirSampling.SlidingWindow.DefaultSlidingWindowReservoir( | ||
sampleSize: ctlConfig.ReservoirSampleSize), | ||
|
||
ReservoirTypes.ExponentialDecay => new App.Metrics.ReservoirSampling.ExponentialDecay.DefaultForwardDecayingReservoir( | ||
sampleSize: ctlConfig.ReservoirSampleSize, | ||
alpha: 0.015), | ||
|
||
_ => throw new ArgumentException( | ||
message: "Invalid ReservoirType Specified."), | ||
}; | ||
} | ||
|
||
/// <summary> | ||
/// An enum containing different reservoir types. | ||
/// </summary> | ||
public enum ReservoirTypes | ||
{ | ||
Uniform, | ||
SlidingWindow, | ||
ExponentialDecay | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters