コード例 #1
0
ファイル: ConsulClient.cs プロジェクト: maniacs-sfa/microdot
        public ConsulClient(string serviceName, Func <ConsulConfig> getConfig,
                            ISourceBlock <ConsulConfig> configChanged, IEnvironmentVariableProvider environmentVariableProvider,
                            ILog log, IDateTime dateTime, Func <string, AggregatingHealthStatus> getAggregatedHealthStatus)
        {
            _serviceName = serviceName;
            GetConfig    = getConfig;
            _dateTime    = dateTime;
            Log          = log;
            DataCenter   = environmentVariableProvider.DataCenter;

            _waitForConfigChange = new TaskCompletionSource <bool>();
            configChanged.LinkTo(new ActionBlock <ConsulConfig>(ConfigChanged));

            var address = environmentVariableProvider.ConsulAddress ?? $"{CurrentApplicationInfo.HostName}:8500";

            ConsulAddress = new Uri($"http://{address}");
            _httpClient   = new HttpClient {
                BaseAddress = ConsulAddress, Timeout = getConfig().HttpTimeout
            };
            _aggregatedHealthStatus = getAggregatedHealthStatus("ConsulClient");

            _resultChanged      = new BufferBlock <EndPointsResult>();
            _initializedVersion = new TaskCompletionSource <bool>();
            ShutdownToken       = new CancellationTokenSource();
            Task.Run(LoadVersionLoop);
            Task.Run(LoadEndpointsLoop);
        }
コード例 #2
0
        public NewServiceDiscovery(string serviceName,
                                   ReachabilityCheck reachabilityCheck,
                                   IEnvironment environment,
                                   ISourceBlock <DiscoveryConfig> configListener,
                                   Func <DiscoveryConfig> discoveryConfigFactory,
                                   ILog log,
                                   IDiscovery discovery,
                                   Func <string, AggregatingHealthStatus> getAggregatingHealthStatus)
        {
            Log          = log;
            _discovery   = discovery;
            _serviceName = serviceName;

            _originatingEnvironmentDeployment = new DeploymentIdentifier(serviceName, environment.DeploymentEnvironment, environment);
            _masterDeployment = new DeploymentIdentifier(serviceName, MASTER_ENVIRONMENT, environment);

            _reachabilityCheck = reachabilityCheck;
            GetConfig          = discoveryConfigFactory;

            _initTask        = Task.Run(() => ReloadRemoteHost(discoveryConfigFactory()));
            _configBlockLink = configListener.LinkTo(new ActionBlock <DiscoveryConfig>(ReloadRemoteHost));

            AggregatingHealthStatus = getAggregatingHealthStatus("Discovery");
            _healthCheck            = AggregatingHealthStatus.RegisterCheck(_serviceName, () => new ValueTask <HealthCheckResult>(_getHealthStatus()));
            _getHealthStatus        = () => HealthCheckResult.Healthy("Initializing. Service was not discovered yet");
        }
コード例 #3
0
ファイル: ConsulClient.cs プロジェクト: zhrjin/microdot
        public ConsulClient(string serviceName, Func <ConsulConfig> getConfig,
                            ISourceBlock <ConsulConfig> configChanged, IEnvironment environment,
                            ILog log, IDateTime dateTime, Func <string, AggregatingHealthStatus> getAggregatedHealthStatus)
        {
            _serviceName       = serviceName;
            _serviceNameOrigin = serviceName;

            GetConfig = getConfig;
            _dateTime = dateTime;
            Log       = log;
            Zone      = environment.Zone;

            _waitForConfigChange = new TaskCompletionSource <bool>();
            configChanged.LinkTo(new ActionBlock <ConsulConfig>(ConfigChanged));

            var address = environment.ConsulAddress ?? $"{CurrentApplicationInfo.HostName}:8500";

            ConsulAddress = new Uri($"http://{address}");
            _httpClient   = new HttpClient {
                BaseAddress = ConsulAddress, Timeout = TimeSpan.FromMinutes(100)
            };                                                                                                 // timeout will be implemented using cancellationToken when calling httpClient
            _aggregatedHealthStatus = getAggregatedHealthStatus("ConsulClient");

            _resultChanged      = new BufferBlock <EndPointsResult>();
            _initializedVersion = new TaskCompletionSource <bool>();
            ShutdownToken       = new CancellationTokenSource();
            _healthCheck        = _aggregatedHealthStatus.RegisterCheck(_serviceNameOrigin, () => _getHealthStatus());
        }
コード例 #4
0
ファイル: WorkloadMetrics.cs プロジェクト: zxw-ing/microdot
 public WorkloadMetrics(Func <string, AggregatingHealthStatus> getAggregatingHealthStatus, Func <WorkloadMetricsConfig> getConfig, IDateTime dateTime, ILog log)
 {
     Log                   = log;
     _getConfig            = getConfig;
     _dateTime             = dateTime;
     _healthStatus         = getAggregatingHealthStatus("Workload");
     _processorTimePercent = new CpuUsageCounterByProcess();
 }
コード例 #5
0
 public ConfigObjectCreator(Type objectType, ConfigCache configCache, UsageTracking usageTracking, ILog log, Func <string, AggregatingHealthStatus> getAggregatedHealthCheck)
 {
     UsageTracking = usageTracking;
     Log           = log;
     ObjectType    = objectType;
     ConfigCache   = configCache;
     ConfigPath    = GetConfigPath();
     healthStatus  = getAggregatedHealthCheck("Configuration");
     Validator     = new DataAnnotationsValidator.DataAnnotationsValidator();
 }
コード例 #6
0
        public ConfigObjectCreator(Type objectType, ConfigCache configCache, UsageTracking usageTracking, ILog log, Func <string, AggregatingHealthStatus> getAggregatedHealthCheck)
        {
            UsageTracking = usageTracking;
            Log           = log;
            ObjectType    = objectType;
            ConfigCache   = configCache;
            ConfigPath    = GetConfigPath();
            Validator     = new DataAnnotationsValidator.DataAnnotationsValidator();

            Create();
            ConfigCache.ConfigChanged.LinkTo(new ActionBlock <ConfigItemsCollection>(c => Create()));
            InitializeBroadcast();
            healthStatus = getAggregatedHealthCheck("Configuration");
            healthStatus.RegisterCheck(ObjectType.Name, HealthCheck);
        }