public SimpleScaleStrategy(string databaseId, string collectionId) { // TODO make configurable var options = new SimpleScaleStrategyOptions() { TrendDuration = TimeSpan.FromSeconds(30), TrendInterval = TimeSpan.FromSeconds(1), }; RegisterObserver(databaseId, collectionId, options); }
private void RegisterObserver(string databaseId, string collectionId, SimpleScaleStrategyOptions options) { // Note: this is an overly simplistic approach // CosmosDb RU is calculated/charged per second _requestChargeSubject.Buffer(TimeSpan.FromSeconds(1), TimeSpan.FromSeconds(1)) .Select(x => x.Sum()) .Buffer(options.TrendDuration, options.TrendInterval) .Select(graphItem => { var lineIntercept = Fit.Line(Enumerable.Range(0, graphItem.Count).Select(m => (double)m).ToArray(), graphItem.ToArray()); return(new TrendModel() { Intercept = lineIntercept.Item1, Slope = lineIntercept.Item2, LastRecordIndex = graphItem.Count }); }) .Select(trend => Observable.FromAsync(async cancelToken => await ScaleUnstableTrendAsync(databaseId, collectionId, trend))) .Subscribe(); }