Exemple #1
0
        public async Task can_pack_metrics()
        {
            // Arrange
            var token          = CancellationToken.None;
            var payloadBuilder = new TestPayloadBuilder();
            var reporter       = new TestReporter(payloadBuilder);
            var filter         = new DefaultMetricsFilter().WithEnvironmentInfo(false);

            // Act
            await _reportGenerator.GenerateAsync(reporter, _metrics, filter, token);

            var payload = payloadBuilder.PayloadFormatted();

            // Assert
            payload.Should().
            Be(
                "application__test_counter tag1=value mtype=counter value=1i" + Environment.NewLine +
                "application__test_gauge mtype=gauge value=8" + Environment.NewLine +
                "application__test_histogram mtype=histogram samples=1i last=5 count.hist=1i sum=5 min=5 max=5 mean=5 median=5 stddev=0 p999=5 p99=5 p98=5 p95=5 p75=5" +
                Environment.NewLine +
                "application__test_meter tag2=value mtype=meter count.meter=1i rate1m=0 rate5m=0 rate15m=0 rate.mean=6000" +
                Environment.NewLine +
                "application__test_timer mtype=timer count.meter=1i rate1m=0 rate5m=0 rate15m=0 rate.mean=6000 samples=1i last=10 count.hist=1i sum=10 min=10 max=10 mean=10 median=10 stddev=0 p999=10 p99=10 p98=10 p95=10 p75=10" +
                Environment.NewLine);
        }
        public async Task can_disable_reporting_environment_info()
        {
            var metricReporter = new Mock <IMetricReporter>();

            metricReporter.Setup(x => x.ReportEnvironment(It.IsAny <EnvironmentInfo>()));
            var token  = CancellationToken.None;
            var filter = new DefaultMetricsFilter().WithEnvironmentInfo(false);

            await _reportGenerator.GenerateAsync(metricReporter.Object, _metrics, filter, token);

            metricReporter.Verify(p => p.ReportEnvironment(It.IsAny <EnvironmentInfo>()), Times.Never);
        }
Exemple #3
0
        public async Task <IActionResult> OnPostAsync(string returnUrl = null)
        {
            returnUrl = returnUrl ?? Url.Content("~/");
            if (ModelState.IsValid)
            {
                var user = new IdentityUser {
                    UserName = Input.Email, Email = Input.Email
                };
                var result = await _userManager.CreateAsync(user, Input.Password);

                if (result.Succeeded)
                {
                    _logger.LogInformation("User created a new account with password.");

                    //add new user to "eq-manager" role
                    result = await _userManager.AddToRoleAsync(user, DefaultEqAuthProvider.EqManagerRole);

                    if (result.Succeeded)
                    {
                        _logger.LogInformation("User has beed added to role: " + DefaultEqAuthProvider.EqManagerRole);
                    }

                    var code = await _userManager.GenerateEmailConfirmationTokenAsync(user);

                    var callbackUrl = Url.Page(
                        "/Account/ConfirmEmail",
                        pageHandler: null,
                        values: new { userId = user.Id, code = code },
                        protocol: Request.Scheme);

                    await _emailSender.SendEmailAsync(Input.Email, "Confirm your email",
                                                      $"Please confirm your account by <a href='{HtmlEncoder.Default.Encode(callbackUrl)}'>clicking here</a>.");

                    await _signInManager.SignInAsync(user, isPersistent : false);

                    // generate default reports
                    await _reportGenerator.GenerateAsync(user);

                    return(LocalRedirect(returnUrl));
                }
                foreach (var error in result.Errors)
                {
                    ModelState.AddModelError(string.Empty, error.Description);
                }
            }

            // If we got this far, something failed, redisplay form
            return(Page());
        }
Exemple #4
0
        public async Task Invoke(HttpContext context)
        {
            if (Options.MetricsTextEndpointEnabled && Options.MetricsTextEndpoint.IsPresent() && Options.MetricsTextEndpoint == context.Request.Path)
            {
                Logger.MiddlewareExecuting(GetType());

                var stringReporter = new StringReporter();
                await _reportGenerator.GenerateAsync(stringReporter, Metrics, context.RequestAborted);

                await WriteResponseAsync(context, stringReporter.Result, "text/plain");

                Logger.MiddlewareExecuted(GetType());

                return;
            }

            await Next(context);
        }
Exemple #5
0
        public async Task Invoke(IDictionary <string, object> environment)
        {
            var requestPath = environment["owin.RequestPath"] as string;

            if (Options.MetricsTextEndpointEnabled && Options.MetricsTextEndpoint.IsPresent() &&
                Options.MetricsTextEndpoint == requestPath)
            {
                Logger.MiddlewareExecuting(GetType());

                var stringReporter = new StringReporter();
                //TODO: AH - confirm cancellation token is correct
                var cancellationToken = (CancellationToken)environment["owin.CallCancelled"];
                await _reportGenerator.GenerateAsync(stringReporter, Metrics, cancellationToken);

                await WriteResponseAsync(environment, stringReporter.Result, "text/plain");

                Logger.MiddlewareExecuted(GetType());

                return;
            }

            await Next(environment);
        }