private async Task RunHeartbeatChecker(bool sendResponse = false, int maxNonResponsiveCounter = 1)
        {
            var peers = new List <Peer> {
                _testPeer
            };
            var peerSettings   = _testPeer.PeerId.ToSubstitutedPeerSettings();
            var peerChallenger = new PeerChallengeRequest(
                Substitute.For <ILogger>(),
                _peerClient,
                peerSettings,
                PeerChallengeTimeoutSeconds);

            if (sendResponse)
            {
                peerChallenger.ChallengeResponseMessageStreamer.OnNext(new PeerChallengeResponse(_testPeer.PeerId));
            }

            _peerRepository.GetAll().Returns(peers);
            _peerHeartbeatChecker = new PeerHeartbeatChecker(
                Substitute.For <ILogger>(),
                _peerRepository,
                peerChallenger,
                PeerHeartbeatCheckSeconds,
                maxNonResponsiveCounter);

            _peerHeartbeatChecker.Run();
            await Task.Delay(TimeSpan.FromSeconds(PeerHeartbeatCheckSeconds * (maxNonResponsiveCounter + 1))
                             .Add(TimeSpan.FromSeconds(1))).ConfigureAwait(false);
        }
 public HealthController(IOptions <List <string> > urls, IHealthChecker healthChecker, IHealthJob healthJob, IHttpClientFactory client)
 {
     _urls          = urls;
     _healthChecker = healthChecker;
     _healthJob     = healthJob;
     _client        = client;
 }
 public HealthCheckOrchestratorFunction(
     IHealthCheckDBClient dbClient,
     IHealthChecker healthChecker)
 {
     DBClient      = dbClient;
     HealthChecker = healthChecker;
 }
 public HealthCheckController(ISettings settings, ISessions sessions,
                              IBodyTelemetryStorage telemetryStorage, IHealthChecker healthChecker) : base(settings,
                                                                                                           sessions)
 {
     _telemetryStorage = telemetryStorage;
     _healthChecker    = healthChecker;
 }
Esempio n. 5
0
 public ServiceFunction(
     IHealthCheckDBClient dbClient,
     IHealthChecker healthChecker)
 {
     DBClient      = dbClient;
     HealthChecker = healthChecker;
 }
 public HealthCheckMiddleware(
     RequestDelegate next,
     IHealthChecker healthChecker, HealthCheckOptions options)
 {
     _next          = next;
     _healthChecker = healthChecker ?? throw new ArgumentNullException(nameof(healthChecker));
     _options       = options;
 }
 public AutoHealthCheckMiddleware(
     RequestDelegate next,
     IHealthChecker healthChecker,
     AutoHealthAppBuilderOptions appOptions)
 {
     _next          = next;
     _healthChecker = healthChecker;
     _appOptions    = appOptions;
 }
        public static void RegisterHealthCheck(this HttpConfiguration config, IHealthChecker healthChecker, string routeUrl = "healthcheck")
        {
            var defaults    = new HttpRouteValueDictionary();
            var constraint  = new ExactMatchConstraint();
            var constraints = new HttpRouteValueDictionary {
                { routeUrl, constraint }
            };

            config.Routes.MapHttpRoute("healthcheck", routeUrl, defaults, constraints, new HealthCheckMessageHandler(healthChecker));
        }
Esempio n. 9
0
        public void ShouldTimeOutWhenHealthCheckTimeOutIsSpecified()
        {
            IHealthChecker healthChecker = GetHealthChecker(b => b.WithHealthChecks(() => new[] { new SlowRunningHealthCheck(5000) }).WithTimeout(TimeSpan.FromMilliseconds(500)));

            var result = healthChecker.Check();

            result.Status.ShouldBe(HealthCheckStatus.NotOkay);
            result.Results.Length.ShouldBe(1);
            ((FailedIndividualHealthCheckResult)result.Results[0]).FailureReason.ShouldBe("Health check timed out.");
        }
 public EndpointHealthNotifier(IHealthMonitorClient client, ITimeCoordinator timeCoordinator, EndpointDefinition definition, IHealthChecker healthChecker)
 {
     _client = client;
     _timeCoordinator = timeCoordinator;
     _definition = definition;
     _healthChecker = healthChecker;
     _cancelationTokenSource = new CancellationTokenSource();
     _healthCheckInterval = new CachedValue<TimeSpan>(HealthCheckIntervalCacheDuration, GetHealthCheckIntervalAsync);
     _thread = new Thread(HealthLoop) { IsBackground = true, Name = "Health Check loop" };
     _thread.Start();
 }
        public static void RegisterHealthCheck(this RouteCollection routes, IHealthChecker healthChecker, string routeUrl = "healthcheck")
        {
            var constraint  = new ExactMatchConstraint();
            var defaults    = new RouteValueDictionary();
            var constraints = new RouteValueDictionary {
                { routeUrl, constraint }
            };

            var route = new Route("healthcheck", defaults, constraints, new HealthCheckRouteHandler(healthChecker));

            routes.Add(route);
        }
        public SynchronizerEngine
        (
            IWatchdogThread watchdogThread,
            IControllerFactory controllerFactory,
            IConfigurationReader configurationReader,

            IHealthChecker healthChecker
        )
            : base(watchdogThread, controllerFactory)
        {
            _configurationReader = configurationReader;
            _healthChecker       = healthChecker;
        }
Esempio n. 13
0
        public IHttpActionResult HealthCheck()
        {
            HealthCheckResponse response = new HealthCheckResponse();

            HealthCheckerContainer container = TrendyolApp.Instance.DataStore.GetData <HealthCheckerContainer>(Constants.HealthCheckerContainerDataKey);

            if (container == null || container.HealthCheckers.IsEmpty())
            {
                return(Ok(response));
            }

            IHealthCheckerActivator healthCheckerActivator = TrendyolApp.Instance.GetHealthCheckerActivator();

            response.Results = new List <HealthCheckResult>();
            foreach (HealthChecker checker in container.HealthCheckers)
            {
                IHealthChecker checkerInstance = healthCheckerActivator.CreateHealthCheckerInstance(checker.HealthCheckerType);

                if (checkerInstance == null)
                {
                    throw new ConfigurationErrorsException($"There was a problem while creating healthchecker instance for type:{checker.HealthCheckerType.FullName}. Check if your type implements IHealthChecker interface.");
                }

                HealthCheckResult result = new HealthCheckResult();
                result.Key        = checkerInstance.Key;
                result.IsCtirical = checkerInstance.IsCritical;

                try
                {
                    result.Success = checkerInstance.CheckHealth();
                }
                catch (Exception ex)
                {
                    Logger.Error(ex);

                    result.Message = ex.Message;
                    result.Success = false;
                }

                response.Results.Add(result);
            }

            HttpStatusCode statusCode = HttpStatusCode.OK;

            if (response.Results.HasElements() && response.Results.Any(r => r.IsCtirical && r.Success == false))
            {
                statusCode = HttpStatusCode.InternalServerError;
            }

            return(Content(statusCode, response));
        }
Esempio n. 14
0
 public PeerService(IUdpServerEventLoopGroupFactory udpServerEventLoopGroupFactory,
                    IUdpServerChannelFactory serverChannelFactory,
                    IPeerDiscovery peerDiscovery,
                    IEnumerable <IP2PMessageObserver> messageHandlers,
                    IPeerSettings peerSettings,
                    ILogger logger,
                    IHealthChecker healthChecker)
     : base(serverChannelFactory, logger, udpServerEventLoopGroupFactory)
 {
     _messageHandlers = messageHandlers;
     _peerSettings    = peerSettings;
     _healthChecker   = healthChecker;
     Discovery        = peerDiscovery;
 }
Esempio n. 15
0
 public EndpointHealthNotifier(IHealthMonitorClient client, ITimeCoordinator timeCoordinator, EndpointDefinition definition, IHealthChecker healthChecker)
 {
     _client                 = client;
     _timeCoordinator        = timeCoordinator;
     _definition             = definition;
     _healthChecker          = healthChecker;
     _cancelationTokenSource = new CancellationTokenSource();
     _healthCheckInterval    = new CachedValue <TimeSpan>(HealthCheckIntervalCacheDuration, GetHealthCheckIntervalAsync);
     _thread                 = new Thread(HealthLoop)
     {
         IsBackground = true, Name = "Health Check loop"
     };
     _thread.Start();
 }
 public HealthCheckMessageHandler(IHealthChecker healthChecker)
 {
     _healthChecker = healthChecker;
 }
 public HealthCheckHttpHandler(IHealthChecker healthChecker)
 {
     _healthChecker = healthChecker;
 }
 public NodeViewModel(IHealthChecker healthChecker, INetworkResolver networkResolver)
 {
     _healthChecker   = healthChecker;
     _networkResolver = networkResolver;
     _healthChecker.OnPropertyChanged += (s, e) => OnPropertyChanged?.Invoke(s, e);
 }
        public HealthCheckMiddlewareTests()
        {
            _healthChecker = HealthCheckerTests.GetHealthChecker(b => b.WithHealthChecks(() => new[] { new ApplicationIsRunning() }));

            _failingHealthChecker = HealthCheckerTests.GetHealthChecker(b => b.WithHealthChecks(() => new[] { new FailingHealthCheck() }));
        }
Esempio n. 20
0
 public SynchronizerController(IHealthChecker healthChecker)
     : base(healthChecker)
 {
 }
 public HealthCheckMessageHandler(IHealthChecker healthChecker)
 {
     _healthChecker = healthChecker;
 }
 public void SetUp()
 {
     _healthMonitor = new Mock <IHealthMonitor>();
     _logger        = new Mock <ILogger <HealthChecker> >();
     _healthChecker = new HealthChecker(_healthMonitor.Object, _logger.Object);
 }
Esempio n. 23
0
 public HealthController(IOptions <List <string> > urls, IHealthChecker healthChecker)
 {
     _urls          = urls;
     _healthChecker = healthChecker;
 }
Esempio n. 24
0
        public async Task <IActionResult> HealthCheck()
        {
            using (var scope = _scopeFactory.CreateScope())
            {
                HealthCheckResponse response = new HealthCheckResponse();

                response.DockerImageName = Environment.GetEnvironmentVariable("Sillycore.DockerImageName");

                if (SillycoreApp.Instance.DataStore.Get <bool>(Constants.IsShuttingDown))
                {
                    response.AddErrorMessage("Shutting down...");
                    return(StatusCode(503, response));
                }

                HealthCheckerContainer container = SillycoreApp.Instance.DataStore.Get <HealthCheckerContainer>(Constants.HealthCheckerContainerDataKey);

                if (container != null && container.HealthCheckers.HasElements())
                {
                    response.Results = new List <HealthCheckResult>();

                    foreach (HealthChecker checker in container.HealthCheckers)
                    {
                        IHealthChecker checkerInstance = (IHealthChecker)scope.ServiceProvider.GetService(checker.HealthCheckerType);

                        if (checkerInstance == null)
                        {
                            throw new ApplicationException($"There was a problem while creating healthchecker instance for type:{checker.HealthCheckerType.FullName}. Check if your type implements IHealthChecker interface.");
                        }

                        HealthCheckResult result = new HealthCheckResult();
                        result.Key        = checkerInstance.Key;
                        result.IsCtirical = checkerInstance.IsCritical;

                        try
                        {
                            result.Success = await checkerInstance.CheckHealth();
                        }
                        catch (Exception ex)
                        {
                            _logger.LogError(ex, $"There was a problem while running healthcheckher:{checker.HealthCheckerType.FullName}");

                            result.Message = ex.Message;
                            result.Success = false;
                        }

                        response.Results.Add(result);
                    }
                }

                HttpStatusCode statusCode = HttpStatusCode.OK;

                if (response.Results.HasElements() && response.Results.Any(r => r.IsCtirical && r.Success == false))
                {
                    statusCode = HttpStatusCode.InternalServerError;
                }

                if (_backgroundJobManager.IsActive)
                {
                    response.BackgroundJobManager = _backgroundJobManager;

                    if (response.BackgroundJobManager.JobTimers.Any(t => t.Status == BackgroundJobStatus.Failing))
                    {
                        statusCode = HttpStatusCode.InternalServerError;
                        response.AddErrorMessage("At least one of background jobs is failing.");
                    }
                }

                return(StatusCode((int)statusCode, response));
            }
        }
 public HealthCheckRouteHandler(IHealthChecker healthChecker)
 {
     _healthChecker = healthChecker;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="HealthCheckController"/> class.
 /// </summary>
 /// <param name="healthChecker">The health checker.</param>
 public HealthCheckController(IHealthChecker healthChecker)
 {
     this.healthChecker = healthChecker;
 }
Esempio n. 27
0
 public NodeController(IHealthChecker healthChecker, IRestExecutor restExecutor)
     : base(healthChecker)
 {
     _restExecutor = restExecutor;
 }
 public HealthCheckRouteHandler(IHealthChecker healthChecker)
 {
     _healthChecker = healthChecker;
 }
Esempio n. 29
0
 public HealthMonitorPushClient WithHealthCheck(IHealthChecker healthChecker)
 {
     _healthChecker = healthChecker;
     return(this);
 }
Esempio n. 30
0
 public WebSocketConnector(IHealthChecker healthChecker)
 {
     this.healthChecker = healthChecker;
 }
        public HealthCheckNancyModule(IHealthChecker healthChecker)
        {
            _healthChecker = healthChecker;

            Get[EndpointName] = _ => ExecuteHealthChecks();
        }
 public HealthMonitorPushClient WithHealthCheck(IHealthChecker healthChecker)
 {
     _healthChecker = healthChecker;
     return this;
 }
Esempio n. 33
0
 public CheckStatusUseCase(IHealthChecker healthChecker)
 {
     _HealthChecker = healthChecker;
 }
Esempio n. 34
0
 public HealthCheckHttpHandler(IHealthChecker healthChecker)
 {
     _healthChecker = healthChecker;
 }