Recognos/Metrics.NET

authentication on the metrics endpoint

Opened this issue · 1 comments

Just testing the metrics.net library, curious if one can put authentication on the metrics endpoint? Below is our snippet in the configuration() method. What am I missing? My controller is expecting basic authentication but the metrics endpoint is allowing me to go to it.

        appBuilder.Use(typeof(AuthenticationMiddleware));
        appBuilder.UseCors(CorsOptions.AllowAll);

        Metric.Config
         .WithAllCounters()
         //.WithReporting(r => r.WithConsoleReport(TimeSpan.FromSeconds(30)))
         .WithOwin(m => appBuilder.Use(m), cfg => cfg
             .WithRequestMetricsConfig(c => c.WithAllOwinMetrics(), new[]
             {
                new Regex("(?i)^sampleignore"),
                new Regex("(?i)^metrics"),
                new Regex("(?i)^health"),
                new Regex("(?i)^json")
             })
             .WithMetricsEndpoint()
         );

        HttpConfiguration config = new HttpConfiguration();
        config.MapHttpAttributeRoutes();

        config.Routes.MapHttpRoute(
            name: "DefaultApi",
            routeTemplate: "api/{controller}/{id}",
            defaults: new { id = RouteParameter.Optional }
        );

        appBuilder.UseWebApi(config);
Liwoj commented

You are creating Metrics endpoint using Owin. Metrics is just one of the Owin handlers. For each request, Owin handlers are called in the order of registration. So problem is probably in your AuthenticationMiddleware not stopping the request before it reaches Metrics middleware...