Example #1
0
        public DefaultHealthCheckService(ISystemClock clock, IHealthCheckPolicyProvider policyProvider, ICheckFactory checkFactory)
        {
            if (checkFactory == null)
            {
                throw new ArgumentNullException(nameof(checkFactory));
            }

            if (clock == null)
            {
                throw new ArgumentNullException(nameof(clock));
            }

            if (policyProvider == null)
            {
                throw new ArgumentNullException(nameof(policyProvider));
            }

            _checkFactory  = checkFactory;
            _clock         = clock;
            _defaultPolicy = policyProvider.DefaultPolicy;
            _resultCache   = CreateCache();
        }
        public HealthCheckMiddleware(
            RequestDelegate next,
            IOptions <HealthCheckOptions> options,
            ILoggerFactory loggerFactory,
            IHealthCheckService healthService,
            IHealthCheckPolicyProvider policyProvider,
            IAuthorizationService authorizationService)
        {
            if (next == null)
            {
                throw new ArgumentNullException(nameof(next));
            }

            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            if (loggerFactory == null)
            {
                throw new ArgumentNullException(nameof(loggerFactory));
            }

            if (healthService == null)
            {
                throw new ArgumentNullException(nameof(healthService));
            }

            if (policyProvider == null)
            {
                throw new ArgumentNullException(nameof(policyProvider));
            }

            if (authorizationService == null)
            {
                throw new ArgumentNullException(nameof(authorizationService));
            }

            _next                 = next;
            _options              = options.Value;
            _logger               = loggerFactory.CreateLogger <HealthCheckMiddleware>();
            _healthService        = healthService;
            _policyProvider       = policyProvider;
            _authorizationService = authorizationService;

            _charPool     = ArrayPool <char> .Shared;
            _jsonCharPool = new JsonArrayPool <char>(_charPool);
            _bytePool     = ArrayPool <byte> .Shared;
            JsonSerializerSettings jsonSettings = new JsonSerializerSettings
            {
                ContractResolver = new DefaultContractResolver
                {
                    NamingStrategy = new SnakeCaseNamingStrategy(true, true),
                },
                Converters = new List <JsonConverter>
                {
                    new StringEnumConverter
                    {
                        CamelCaseText = true
                    }
                },
                NullValueHandling = NullValueHandling.Ignore
            };

            _jsonSerializer = JsonSerializer.Create(jsonSettings);
        }
Example #3
0
        public CanaryMiddleware(
            RequestDelegate next,
            IOptions <CanaryOptions> options,
            ILoggerFactory loggerFactory,
            IHealthCheckService healthService,
            IHealthCheckPolicyProvider policyProvider,
            IServerSwitch serverSwitch,
            IAuthorizationService authorizationService)
        {
            if (next == null)
            {
                throw new ArgumentNullException(nameof(next));
            }

            if (options == null)
            {
                throw new ArgumentNullException(nameof(options));
            }

            if (loggerFactory == null)
            {
                throw new ArgumentNullException(nameof(loggerFactory));
            }

            if (healthService == null)
            {
                throw new ArgumentNullException(nameof(healthService));
            }

            if (policyProvider == null)
            {
                throw new ArgumentNullException(nameof(policyProvider));
            }

            if (authorizationService == null)
            {
                throw new ArgumentNullException(nameof(authorizationService));
            }

            if (authorizationService == null)
            {
                throw new ArgumentNullException(nameof(authorizationService));
            }

            _next                 = next;
            _options              = options.Value;
            _logger               = loggerFactory.CreateLogger <CanaryMiddleware>();
            _healthService        = healthService;
            _serverSwitch         = serverSwitch;
            _authorizationService = authorizationService;

            if (_options.EnableHealthCheck)
            {
                var defaultPolicy = policyProvider.GetPolicy(_options.PolicyName);
                if (defaultPolicy == null)
                {
                    throw new ArgumentException($"{nameof(_options.PolicyName)} '{_options.PolicyName}' is not a valid policy.", nameof(_options));
                }

                _defaultPolicy = defaultPolicy;
            }
        }