public FileRateLimitingService(IConfigService configService) { this._configService = configService; var rateLimitingConfig = configService.GetJson <RateLimitingConfig>("RateLimiting"); this._createRate = new RequestsCounter(rateLimitingConfig.SavePerIP.DurationTime); this._getPerIpRate = new RequestsCounter(rateLimitingConfig.GetPerIP.DurationTime); this._getPerFileKeyRate = new RequestsCounter(rateLimitingConfig.GetPerFileKey.DurationTime); _clearTimer = new Timer((_) => OnClearTimerTick(), null, 10 * 1000, 10 * 1000); }
public async Task InjectsPollyCircuitBreakerPolicy() { // Arrange this.SetBaseAddress("http://localhost/v3/"); var counter = new RequestsCounter(); var serviceCollection = new ServiceCollection(); serviceCollection.AddSingleton(counter); serviceCollection.AddTransient <IHttpMessageHandlerBuilderFilter, RequestsFilter>(); serviceCollection.AddEcsTaskMetadataClientFactory(); var serviceProvider = serviceCollection.BuildServiceProvider(); var client = serviceProvider.GetService <IEcsTaskMetadataClient>(); // Act var firstResponse = await client !.GetContainerStatsAsync(CancellationToken.None).ConfigureAwait(true); var firstRequestCount = counter.Requests; var secondResponse = await Assert.ThrowsAsync <BrokenCircuitException <HttpResponseMessage> >(() => client !.GetContainerStatsAsync(CancellationToken.None)).ConfigureAwait(true); var secondRequestCount = counter.Requests; var thirdResponse = await Assert.ThrowsAsync <BrokenCircuitException <HttpResponseMessage> >(() => client !.GetContainerStatsAsync(CancellationToken.None)).ConfigureAwait(true); var thirdRequestCount = counter.Requests; // Assert Assert.Null(firstResponse); Assert.Equal(4, firstRequestCount); Assert.NotNull(secondResponse); Assert.Equal(5, secondRequestCount); Assert.NotNull(thirdResponse); Assert.Equal(5, thirdRequestCount); }
public async Task InjectsPollyRetryPolicy() { // Arrange this.SetBaseAddress("http://localhost/v3/"); var counter = new RequestsCounter(); var serviceCollection = new ServiceCollection(); serviceCollection.AddSingleton(counter); serviceCollection.AddTransient <IHttpMessageHandlerBuilderFilter, RequestsFilter>(); serviceCollection.AddEcsTaskMetadataClientFactory(); var serviceProvider = serviceCollection.BuildServiceProvider(); var client = serviceProvider.GetService <IEcsTaskMetadataClient>(); // Act var response = await client !.GetContainerStatsAsync(CancellationToken.None).ConfigureAwait(true); // Assert Assert.Null(response); Assert.Equal(4, counter.Requests); }
public RequestsFilter(RequestsCounter counter) => this.counter = counter;
public RequestsHandler(RequestsCounter counter) => this.counter = counter;
public void IncrementRequests(string method = null, string details = null) { if (RequestsCounter == null) RequestsCounter = new RequestsCounterData(); RequestsCounter.IncrementRequests(method, details); } // IncrementRequests