protected internal override void SetMonitoring() { if (string.IsNullOrEmpty(this.HealthCheck.FullClassName)) { HealthChecksBuilder.AddAsyncCheck(Name, () => { return(CustomCheck != null ? CustomCheck() : Task.FromResult(HealthCheckResult.Healthy())); }); } else { Type classType = null; Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies(); foreach (Assembly assem in assemblies) { classType = assem.GetType(HealthCheck.FullClassName); if (classType != null) { break; } } if (classType == null) { throw new Exception( $"Invalid class name {HealthCheck.FullClassName} defined in custom test named {Name}"); } var classInstance = ActivatorUtilities.CreateInstance(_serviceProvider, classType) as IHealthCheck; HealthChecksBuilder.AddCheck(Name, classInstance); } }
public static IHealthChecksBuilder AddHealthChecks(this IMetricsBuilder metricsBuilder, Action <IHealthChecksBuilder> configure) { if (configure == null) { throw new ArgumentNullException(nameof(configure)); } var services = metricsBuilder.Services; var store = new InMemoryHealthChecksStore(); var host = new HealthChecksHost(store); var registry = new InMemoryHealthChecksRegistry(); registry.Add(host); services.TryAdd(ServiceDescriptor.Singleton <IHealthChecksRegistry>(r => registry)); services.TryAdd(ServiceDescriptor.Singleton <IHealthChecksStore, InMemoryHealthChecksStore>(r => store)); services.TryAdd(ServiceDescriptor.Singleton <IHealthChecksHost, HealthChecksHost>(r => host)); services.TryAdd(ServiceDescriptor.Singleton <IHealthChecksStore>(r => new InMemoryHealthChecksStore())); var healthChecksBuilder = new HealthChecksBuilder(metricsBuilder.Services); configure(healthChecksBuilder); return(healthChecksBuilder); }
public void ShoudlReturnTrueIfNoNeedValidation() { var builder = new HealthChecksBuilder(); var sut = new AuthenticationService(builder); var act = sut.NeedAuthentication(); Assert.True(act == false); }
public void ShoudlReturnTrueIfNeedValidation() { var builder = new HealthChecksBuilder().UseAuthorization("AnyApiKey"); var sut = new AuthenticationService(builder); var act = sut.NeedAuthentication(); Assert.True(act == true); }
public void ShouldReturnTrueIfNoNeedValidation() { var customConfig = new HealthChecksBuilder() .HealthCheckConfig; var sut = new AuthenticationService(customConfig); var act = sut.NeedAuthentication(); Assert.False(act); }
protected internal override void SetMonitoring() { var connectionFactory = new RabbitMQ.Client.ConnectionFactory(); connectionFactory.Uri = new Uri(HealthCheck.EndpointOrHost); HealthChecksBuilder.AddRabbitMQ(provider => { return(connectionFactory); }, Name, HealthStatus.Unhealthy); }
public async Task ShouldReturnErrorIfValidationFails() { var hcCustomBuilder = new HealthChecksBuilder().UseAuthorization("AnotherApiKey"); var sut = new AuthenticationHandler(hcCustomBuilder.HealthCheckConfig, _mockAuthService.Object); var act = await sut.HandleRequest(_httpRequestFake, default); string json = JsonConvert.SerializeObject(new ForbiddenError(_wrongApiKey).HttpErrorResponse, hcCustomBuilder.HealthCheckConfig.SerializerSettings); Assert.Equal(HttpStatusCode.Forbidden, act.StatusCode); Assert.Equal(json, await act.Content.ReadAsStringAsync()); }
protected internal override void SetMonitoring() { HealthChecksBuilder.AddHangfire(options => { var minimumAvailableServers = this.HealthCheck.HealthCheckConditions.HangfireBehaviour?.MinimumAvailableServers; var maximumJobsFailed = this.HealthCheck.HealthCheckConditions.HangfireBehaviour?.MinimumAvailableServers; options.MinimumAvailableServers = minimumAvailableServers; options.MaximumJobsFailed = maximumJobsFailed; }, this.HealthCheck.Name); }
public AuthenticationHandler(HttpConfiguration httpConfiguration, HealthChecksBuilder healthChecksBuilder) : base(httpConfiguration, healthChecksBuilder) { }
protected HealthHandlerBase(HttpConfiguration httpConfiguration, HealthChecksBuilder healthChecksBuilder) { _httpConfiguration = httpConfiguration; HealthChecksBuilder = healthChecksBuilder; }
public DependencyHandler(HttpConfiguration httpConfig, HealthChecksBuilder builder) { _httpConfig = httpConfig; _hcBuilder = builder; }
public HealthUiHandler(HttpConfiguration httpConfiguration, HealthChecksBuilder healthChecksBuilder) : base( httpConfiguration, healthChecksBuilder) { }
public HealthCheckService(HealthChecksBuilder healthChecksBuilder) { _healthChecksBuilder = healthChecksBuilder; }
public HealthCheckHandler(HttpConfiguration httpConfiguration, HealthChecksBuilder healthChecksBuilder) : base(httpConfiguration, healthChecksBuilder) { //criar serviço aqui por injeção e uma interface pro serviço }
protected internal override void SetMonitoring() { HealthChecksBuilder.AddSqlServer(this.HealthCheck.ConnectionString, this.HealthCheck.HealthCheckConditions.SqlBehaviour?.Query); }