public void Patterns_and_regex_patterns_have_default_state() { var options = new MetricsWebTrackingOptions(); options.IgnoredRoutesRegexPatterns.Should().NotBeNull(); options.IgnoredRoutesRegex.Should().NotBeNull(); }
public void Can_clear_ignored_routes_and_regex() { var options = new MetricsWebTrackingOptions(); options.IgnoredRoutesRegexPatterns = new List <string> { "abc", "123" }; options.IgnoredRoutesRegexPatterns.Clear(); options.IgnoredRoutesRegexPatterns.Should().BeEmpty(); options.IgnoredRoutesRegex.Should().BeEmpty(); }
public void ConfigureServices(IServiceCollection services) { var appMetricsOptions = new MetricsOptions(); var endpointsOptions = new MetricEndpointsOptions { MetricsTextEndpointEnabled = false, MetricsEndpointEnabled = true }; var trackingOptions = new MetricsWebTrackingOptions(); SetupServices(services, appMetricsOptions, trackingOptions, endpointsOptions); }
public void Setting_ignored_routes_sets_regex_patters() { var patterns = new List <string> { "abc", "123" }; var options = new MetricsWebTrackingOptions(); options.IgnoredRoutesRegexPatterns = patterns; options.IgnoredRoutesRegexPatterns .Should().BeEquivalentTo(patterns); options.IgnoredRoutesRegex.Select(r => r.ToString()) .Should().BeEquivalentTo(patterns); }
public void Can_override_settings_from_configuration() { var options = new MetricsWebTrackingOptions(); var provider = SetupServicesAndConfiguration( (o) => { o.ApdexTSeconds = 0.7; o.ApdexTrackingEnabled = true; }); Action resolveOptions = () => { options = provider.GetRequiredService <IOptions <MetricsWebTrackingOptions> >().Value; }; resolveOptions.ShouldNotThrow(); options.ApdexTrackingEnabled.Should().Be(true); options.ApdexTSeconds.Should().Be(0.7); }
protected void SetupServices( IServiceCollection services, MetricsOptions appMetricsOptions, MetricsWebTrackingOptions webTrackingOptions, MetricEndpointsOptions endpointsOptions, IFilterMetrics filter = null) { services.AddLogging().AddRouting(options => { options.LowercaseUrls = true; }); services.AddMvc(options => options.AddMetricsResourceFilter()); var builder = new MetricsBuilder().Configuration.Configure( options => { options.DefaultContextLabel = appMetricsOptions.DefaultContextLabel; options.Enabled = appMetricsOptions.Enabled; }) .OutputEnvInfo.AsPlainText() .OutputEnvInfo.AsJson() .OutputMetrics.AsJson() .OutputMetrics.AsPlainText() .SampleWith.AlgorithmR(1028) .TimeWith.Clock <TestClock>(); if (filter != null) { builder.Filter.With(filter); } services.AddMetrics(builder); services.AddMetricsEndpoints( options => { options.MetricsTextEndpointEnabled = endpointsOptions.MetricsTextEndpointEnabled; options.MetricsEndpointEnabled = endpointsOptions.MetricsEndpointEnabled; }); services.AddMetricsTrackingMiddleware( options => { options.OAuth2TrackingEnabled = webTrackingOptions.OAuth2TrackingEnabled; options.IgnoredRoutesRegexPatterns = webTrackingOptions.IgnoredRoutesRegexPatterns; options.IgnoredHttpStatusCodes = webTrackingOptions.IgnoredHttpStatusCodes; }); }
public void Can_load_settings_from_configuration() { var trackingOptions = new MetricsWebTrackingOptions(); var endpointOptions = new MetricEndpointsOptions(); var provider = SetupServicesAndConfiguration(); Action resolveOptions = () => { trackingOptions = provider.GetRequiredService <IOptions <MetricsWebTrackingOptions> >().Value; }; Action resolveEndpointsOptions = () => { endpointOptions = provider.GetRequiredService <IOptions <MetricEndpointsOptions> >().Value; }; resolveOptions.ShouldNotThrow(); resolveEndpointsOptions.ShouldNotThrow(); trackingOptions.ApdexTrackingEnabled.Should().Be(false); trackingOptions.ApdexTSeconds.Should().Be(0.8); endpointOptions.MetricsTextEndpointEnabled.Should().Be(false); endpointOptions.MetricsEndpointEnabled.Should().Be(false); }
// ReSharper disable UnusedMember.Global public void ConfigureServices(IServiceCollection services) // ReSharper restore UnusedMember.Global { var appMetricsOptions = new MetricsOptions { Enabled = true }; var endpointOptions = new MetricEndpointsOptions(); var trackingOptions = new MetricsWebTrackingOptions(); SetupServices( services, appMetricsOptions, trackingOptions, endpointOptions, new MetricsFilter().WhereType(MetricType.Counter)); }
/// <summary> /// Adds App Metrics services, configuration and middleware to the /// <see cref="T:Microsoft.AspNetCore.Hosting.IWebHostBuilder" />. /// </summary> /// <param name="hostBuilder">The <see cref="T:Microsoft.AspNetCore.Hosting.IWebHostBuilder" />.</param> /// <param name="setupDelegate">A callback to configure <see cref="MetricsWebTrackingOptions" />.</param> /// <returns>A reference to this instance after the operation has completed.</returns> /// <exception cref="ArgumentNullException"> /// <see cref="T:Microsoft.AspNetCore.Hosting.IWebHostBuilder" /> cannot be null /// </exception> public static IHostBuilder UseMetricsWebTracking( this IHostBuilder hostBuilder, Action <HostBuilderContext, MetricsWebTrackingOptions> setupDelegate) { hostBuilder.ConfigureMetrics(); hostBuilder.ConfigureServices( (context, services) => { var trackingMiddlewareOptions = new MetricsWebTrackingOptions(); services.AddMetricsTrackingMiddleware( options => setupDelegate(context, trackingMiddlewareOptions), context.Configuration); services.AddSingleton <IStartupFilter>(new DefaultMetricsTrackingStartupFilter()); }); return(hostBuilder); }
// ReSharper disable UnusedMember.Global public void ConfigureServices(IServiceCollection services) // ReSharper restore UnusedMember.Global { var appMetricsOptions = new MetricsOptions { DefaultContextLabel = "testing", Enabled = true }; var endpointsOptions = new MetricEndpointsOptions { MetricsTextEndpointEnabled = true, MetricsEndpointEnabled = true }; var trackingOptions = new MetricsWebTrackingOptions(); SetupServices(services, appMetricsOptions, trackingOptions, endpointsOptions); }
public void ConfigureServices(IServiceCollection services) { var appMetricsOptions = new MetricsOptions { Enabled = true }; var endpointsOptions = new MetricEndpointsOptions { MetricsTextEndpointEnabled = true, MetricsEndpointEnabled = true }; var trackingoptions = new MetricsWebTrackingOptions { OAuth2TrackingEnabled = true }; trackingoptions.IgnoredRoutesRegexPatterns.Add("(?i)^api/test/ignore"); SetupServices(services, appMetricsOptions, trackingoptions, endpointsOptions); }
public void Changing_ignored_routes_changes_regex_patters() { var options = new MetricsWebTrackingOptions(); options.IgnoredRoutesRegexPatterns.Add("abc"); options.IgnoredRoutesRegexPatterns.Add("123"); options.IgnoredRoutesRegexPatterns.Add("route1"); options.IgnoredRoutesRegexPatterns.Add("route2"); options.IgnoredRoutesRegexPatterns.RemoveAt(1); options.IgnoredRoutesRegexPatterns.Remove("route2"); options.IgnoredRoutesRegexPatterns.Insert(1, "qwe"); options.IgnoredRoutesRegexPatterns[0] = "xyz"; var expected = new List <string> { "xyz", "qwe", "route1" }; options.IgnoredRoutesRegexPatterns .Should().BeEquivalentTo(expected); options.IgnoredRoutesRegex.Select(r => r.ToString()) .Should().BeEquivalentTo(expected); }