예제 #1
0
        public HystrixCommandOptions(
            IHystrixCommandKey key,
            IHystrixCommandOptions defaults = null,
            IHystrixDynamicOptions dynamic  = null)
            : this(defaults, dynamic)
        {
            CommandKey            = key;
            CircuitBreakerEnabled = GetBoolean(HYSTRIX_COMMAND_PREFIX, key.Name, "circuitBreaker.enabled", Default_CircuitBreakerEnabled, defaults?.CircuitBreakerEnabled);
            CircuitBreakerRequestVolumeThreshold    = GetInteger(HYSTRIX_COMMAND_PREFIX, key.Name, "circuitBreaker:requestVolumeThreshold", Default_CircuitBreakerRequestVolumeThreshold, defaults?.CircuitBreakerRequestVolumeThreshold);
            CircuitBreakerSleepWindowInMilliseconds = GetInteger(HYSTRIX_COMMAND_PREFIX, key.Name, "circuitBreaker:sleepWindowInMilliseconds", Default_CircuitBreakerSleepWindowInMilliseconds, defaults?.CircuitBreakerSleepWindowInMilliseconds);
            CircuitBreakerErrorThresholdPercentage  = GetInteger(HYSTRIX_COMMAND_PREFIX, key.Name, "circuitBreaker:errorThresholdPercentage", Default_CircuitBreakerErrorThresholdPercentage, defaults?.CircuitBreakerErrorThresholdPercentage);
            CircuitBreakerForceOpen        = GetBoolean(HYSTRIX_COMMAND_PREFIX, key.Name, "circuitBreaker:forceOpen", Default_CircuitBreakerForceOpen, defaults?.CircuitBreakerForceOpen);
            CircuitBreakerForceClosed      = GetBoolean(HYSTRIX_COMMAND_PREFIX, key.Name, "circuitBreaker:forceClosed", Default_CircuitBreakerForceClosed, defaults?.CircuitBreakerForceClosed);
            ExecutionIsolationStrategy     = GetIsolationStrategy(key);
            ExecutionTimeoutInMilliseconds = GetInteger(HYSTRIX_COMMAND_PREFIX, key.Name, "execution:isolation:thread:timeoutInMilliseconds", Default_ExecutionTimeoutInMilliseconds, defaults?.ExecutionTimeoutInMilliseconds);
            ExecutionTimeoutEnabled        = GetBoolean(HYSTRIX_COMMAND_PREFIX, key.Name, "execution:timeout:enabled", Default_ExecutionTimeoutEnabled, defaults?.ExecutionTimeoutEnabled);
            ExecutionIsolationSemaphoreMaxConcurrentRequests = GetInteger(HYSTRIX_COMMAND_PREFIX, key.Name, "execution:isolation:semaphore:maxConcurrentRequests", Default_ExecutionIsolationSemaphoreMaxConcurrentRequests, defaults?.ExecutionIsolationSemaphoreMaxConcurrentRequests);
            FallbackIsolationSemaphoreMaxConcurrentRequests  = GetInteger(HYSTRIX_COMMAND_PREFIX, key.Name, "fallback:isolation:semaphore:maxConcurrentRequests", Default_FallbackIsolationSemaphoreMaxConcurrentRequests, defaults?.FallbackIsolationSemaphoreMaxConcurrentRequests);
            FallbackEnabled = GetBoolean(HYSTRIX_COMMAND_PREFIX, key.Name, "fallback:enabled", Default_FallbackEnabled, defaults?.FallbackEnabled);

            MetricsRollingStatisticalWindowInMilliseconds = GetInteger(HYSTRIX_COMMAND_PREFIX, key.Name, "metrics:rollingStats:timeInMilliseconds", Default_MetricsRollingStatisticalWindow, defaults?.MetricsRollingStatisticalWindowInMilliseconds);
            MetricsRollingStatisticalWindowBuckets        = GetInteger(HYSTRIX_COMMAND_PREFIX, key.Name, "metrics:rollingStats:numBuckets", Default_MetricsRollingStatisticalWindowBuckets, defaults?.MetricsRollingStatisticalWindowBuckets);
            MetricsRollingPercentileEnabled = GetBoolean(HYSTRIX_COMMAND_PREFIX, key.Name, "metrics:rollingPercentile:enabled", Default_MetricsRollingPercentileEnabled, defaults?.MetricsRollingPercentileEnabled);
            MetricsRollingPercentileWindowInMilliseconds = GetInteger(HYSTRIX_COMMAND_PREFIX, key.Name, "metrics:rollingPercentile:timeInMilliseconds", Default_MetricsRollingPercentileWindow, defaults?.MetricsRollingPercentileWindowInMilliseconds);
            MetricsRollingPercentileWindowBuckets        = GetInteger(HYSTRIX_COMMAND_PREFIX, key.Name, "metrics:rollingPercentile:numBuckets", Default_MetricsRollingPercentileWindowBuckets, defaults?.MetricsRollingPercentileWindowBuckets);
            MetricsRollingPercentileBucketSize           = GetInteger(HYSTRIX_COMMAND_PREFIX, key.Name, "metrics:rollingPercentile:bucketSize", Default_MetricsRollingPercentileBucketSize, defaults?.MetricsRollingPercentileBucketSize);
            MetricsHealthSnapshotIntervalInMilliseconds  = GetInteger(HYSTRIX_COMMAND_PREFIX, key.Name, "metrics:healthSnapshot:intervalInMilliseconds", Default_MetricsHealthSnapshotIntervalInMilliseconds, defaults?.MetricsHealthSnapshotIntervalInMilliseconds);

            RequestCacheEnabled = GetBoolean(HYSTRIX_COMMAND_PREFIX, key.Name, "requestCache:enabled", Default_RequestCacheEnabled, defaults?.RequestCacheEnabled);
            RequestLogEnabled   = GetBoolean(HYSTRIX_COMMAND_PREFIX, key.Name, "requestLog:enabled", Default_RequestLogEnabled, defaults?.RequestLogEnabled);

            ExecutionIsolationThreadPoolKeyOverride = GetThreadPoolKeyOverride(HYSTRIX_COMMAND_PREFIX, key.Name, "threadPoolKeyOverride", null, defaults?.ExecutionIsolationThreadPoolKeyOverride);
        }
예제 #2
0
        internal HystrixCommandOptions(IHystrixCommandOptions defaults = null, IHystrixDynamicOptions dynamic = null)
            : base(dynamic)
        {
            this.defaults         = defaults;
            CommandKey            = null;
            CircuitBreakerEnabled = Default_CircuitBreakerEnabled;
            CircuitBreakerRequestVolumeThreshold    = Default_CircuitBreakerRequestVolumeThreshold;
            CircuitBreakerSleepWindowInMilliseconds = Default_CircuitBreakerSleepWindowInMilliseconds;
            CircuitBreakerErrorThresholdPercentage  = Default_CircuitBreakerErrorThresholdPercentage;
            CircuitBreakerForceOpen    = Default_CircuitBreakerForceOpen;
            CircuitBreakerForceClosed  = Default_CircuitBreakerForceClosed;
            ExecutionIsolationStrategy = Default_IsolationStrategy;

            ExecutionTimeoutInMilliseconds = Default_ExecutionTimeoutInMilliseconds;
            ExecutionTimeoutEnabled        = Default_ExecutionTimeoutEnabled;
            ExecutionIsolationSemaphoreMaxConcurrentRequests = Default_ExecutionIsolationSemaphoreMaxConcurrentRequests;
            FallbackIsolationSemaphoreMaxConcurrentRequests  = Default_FallbackIsolationSemaphoreMaxConcurrentRequests;
            FallbackEnabled = Default_FallbackEnabled;
            MetricsRollingStatisticalWindowInMilliseconds = Default_MetricsRollingStatisticalWindow;
            MetricsRollingStatisticalWindowBuckets        = Default_MetricsRollingStatisticalWindowBuckets;
            MetricsRollingPercentileEnabled = Default_MetricsRollingPercentileEnabled;
            MetricsRollingPercentileWindowInMilliseconds = Default_MetricsRollingPercentileWindow;
            MetricsRollingPercentileWindowBuckets        = Default_MetricsRollingPercentileWindowBuckets;
            MetricsRollingPercentileBucketSize           = Default_MetricsRollingPercentileBucketSize;
            MetricsHealthSnapshotIntervalInMilliseconds  = Default_MetricsHealthSnapshotIntervalInMilliseconds;
            RequestCacheEnabled = Default_RequestCacheEnabled;
            RequestLogEnabled   = Default_RequestLogEnabled;
        }
예제 #3
0
 public SetColorCommand(IHystrixCommandOptions options, string lifxKey, string newColor, double?duration = null) :
     base(options)
 {
     _lifxClient = new LifxApi(lifxKey);
     _newColor   = newColor;
     _duration   = duration ?? 1;
 }
 public ClientServiceCommand(IHystrixCommandOptions options, IClientService clientService,
                             ILogger <ClientServiceCommand> logger) : base(options)
 {
     _clientService        = clientService;
     _logger               = logger;
     IsFallbackUserDefined = true;
 }
 public ProductService(IHystrixCommandOptions options, IDiscoveryClient client, ILogger <ProductService> logger) :
     base(options)
 {
     _logger  = logger;
     _handler = new DiscoveryHttpClientHandler(client);
     IsFallbackUserDefined = true;
 }
예제 #6
0
 private static HystrixCommandConfiguration SampleCommandConfiguration(
     IHystrixCommandKey commandKey,
     IHystrixThreadPoolKey threadPoolKey,
     IHystrixCommandGroupKey groupKey,
     IHystrixCommandOptions commandProperties)
 {
     return(HystrixCommandConfiguration.Sample(commandKey, threadPoolKey, groupKey, commandProperties));
 }
예제 #7
0
 public FortuneServiceCommand(IHystrixCommandOptions options,
                              IFortuneService fortuneService,
                              ILogger <FortuneServiceCommand> logger) : base(options)
 {
     _fortuneService       = fortuneService;
     _logger               = logger;
     IsFallbackUserDefined = true;
 }
예제 #8
0
 public FortuneService(IHystrixCommandOptions options, IDiscoveryClient client, ILoggerFactory logFactory) : base(options)
 {
     _handler = new DiscoveryHttpClientHandler(client, logFactory.CreateLogger <DiscoveryHttpClientHandler>());
     // Remove comment to use SSL communications with Self-Signed Certs
     // _handler.ServerCertificateCustomValidationCallback = (a,b,c,d) => {return true;};
     IsFallbackUserDefined = true;
     this._logger          = logFactory.CreateLogger <FortuneService>();
 }
예제 #9
0
        public GetDevicesGuidCommand(IHystrixCommandOptions options, ILogger <GetDevicesGuidCommand> logger, IGeoLocalisationService service, IMemoryCache cache) : base(options)
        {
            _service = service;
            _logger  = logger;
            _cache   = cache;

            IsFallbackUserDefined = true;
        }
예제 #10
0
 public DeleteCommand(IHystrixCommandOptions options,
                      IOptions <Configuration> configSettings, IGatewayService <string> service)
     : base(options)
 {
     this._config        = configSettings.Value;
     this.apiBase        = this._config.GatewayUrl;
     this.gatewayService = service;
 }
 public HystrixCommandCacheEntry(HystrixCommandFactoryDelegate hystrixCommandFactory, LateBoundMethod methodInvoker, LateBoundMethod fallbackMethodInvoker, LateBoundMethod executeInvoker, IHystrixCommandOptions options)
 {
     HystrixCommandFactory = hystrixCommandFactory;
     MethodInvoker         = methodInvoker;
     ExecuteInvoker        = executeInvoker;
     Options = options;
     FallbackMethodInvoker = fallbackMethodInvoker;
 }
예제 #12
0
 public HystrixCommandOptions(
     IHystrixCommandGroupKey groupKey,
     IHystrixCommandKey key,
     IHystrixCommandOptions defaults = null,
     IHystrixDynamicOptions dynamic  = null)
     : this(key, defaults, dynamic)
 {
     GroupKey = groupKey;
 }
 public HystrixCommandBase(IHystrixCommandOptions commandOptions, Delegate primary, Delegate fallback, object[] arguments, ILoggerFactory loggerFactory) :
     base(commandOptions: commandOptions, logger: loggerFactory.CreateLogger <HystrixCommandAsyncBase>())
 {
     _primaryDelegate        = primary;
     _fallbackDelegate       = fallback;
     _arguments              = arguments;
     options.FallbackEnabled = fallback != null;
     IsFallbackUserDefined   = fallback != null;
 }
예제 #14
0
 public GetHeadlinesCommand(IHystrixCommandOptions options, IHttpClientFactory httpClientFactory, IMemoryCache memoryCache,
                            ILogger <GetHeadlinesCommand> logger)
     : base(options)
 {
     _httpClientFactory    = httpClientFactory;
     _cache                = memoryCache;
     _logger               = logger;
     IsFallbackUserDefined = true;
 }
        public GetProductCommand(IHystrixCommandOptions options, IProductService productService, ILogger <GetProductCommand> logger, IDistributedCache cache)
            : base(options)
        {
            _productService = productService;
            _logger         = logger;
            _cache          = cache;

            IsFallbackUserDefined = true;
        }
예제 #16
0
 public StudentServiceHystrixCommand(
     IHystrixCommandOptions options,
     IStudentService service,
     ILogger <StudentServiceHystrixCommand> logger
     ) : base(options)
 {
     this._service = service;
     this._logger  = logger;
     this.IsFallbackUserDefined = true;
 }
예제 #17
0
 public FortuneServiceCommand(IHystrixCommandOptions options,
                              IFortuneService fortuneService,
                              ILogger <FortuneServiceCommand> logger,
                              IConfiguration configuration) : base(options)
 {
     _fortuneService       = fortuneService;
     _logger               = logger;
     IsFallbackUserDefined = true;
     fallbackText          = configuration.GetValue <string>("fallbackFortune");
 }
예제 #18
0
 public GetOrderDetailsHystrixCommand(
     IHystrixCommandOptions options,
     IOrderService service,
     ILogger <GetOrderDetailsHystrixCommand> logger
     ) : base(options)
 {
     this._service = service;
     this._logger  = logger;
     this.IsFallbackUserDefined = true;
 }
예제 #19
0
        public static HealthCountsStream GetInstance(IHystrixCommandKey commandKey, IHystrixCommandOptions properties)
        {
            int healthCountBucketSizeInMs = properties.MetricsHealthSnapshotIntervalInMilliseconds;

            if (healthCountBucketSizeInMs == 0)
            {
                throw new ArgumentOutOfRangeException("You have set the bucket size to 0ms.  Please set a positive number, so that the metric stream can be properly consumed");
            }
            int numHealthCountBuckets = properties.MetricsRollingStatisticalWindowInMilliseconds / healthCountBucketSizeInMs;

            return(GetInstance(commandKey, numHealthCountBuckets, healthCountBucketSizeInMs));
        }
예제 #20
0
 public GetAlbum(
     IHystrixCommandOptions options,
     IMusicStore storeService,
     IMemoryCache cache,
     IOptions <AppSettings> appsettings,
     ILogger <GetAlbum> logger
     ) : base(options)
 {
     _storeService = storeService;
     _cache        = cache;
     _appSettings  = appsettings.Value;
     _logger       = logger;
     this.IsFallbackUserDefined = true;
 }
        HystrixCommandMetrics(IHystrixCommandKey key, IHystrixCommandGroupKey commandGroup, IHystrixThreadPoolKey threadPoolKey, IHystrixCommandOptions properties, HystrixEventNotifier eventNotifier) : base(null)
        {
            this.key           = key;
            this.group         = commandGroup;
            this.threadPoolKey = threadPoolKey;
            this.properties    = properties;

            healthCountsStream = HealthCountsStream.GetInstance(key, properties);
            rollingCommandEventCounterStream    = RollingCommandEventCounterStream.GetInstance(key, properties);
            cumulativeCommandEventCounterStream = CumulativeCommandEventCounterStream.GetInstance(key, properties);

            rollingCommandLatencyDistributionStream     = RollingCommandLatencyDistributionStream.GetInstance(key, properties);
            rollingCommandUserLatencyDistributionStream = RollingCommandUserLatencyDistributionStream.GetInstance(key, properties);
            rollingCommandMaxConcurrencyStream          = RollingCommandMaxConcurrencyStream.GetInstance(key, properties);
        }
예제 #22
0
        public HystrixCommand(IHystrixCommandGroupKey group, IHystrixCommandKey key, IHystrixThreadPoolKey threadPoolKey, IHystrixCircuitBreaker circuitBreaker, IHystrixThreadPool threadPool,
                              IHystrixCommandOptions commandOptionsDefaults, IHystrixThreadPoolOptions threadPoolOptionsDefaults, HystrixCommandMetrics metrics, SemaphoreSlim fallbackSemaphore, SemaphoreSlim executionSemaphore,
                              HystrixOptionsStrategy optionsStrategy, HystrixCommandExecutionHook executionHook, Action run, Action fallback, ILogger logger = null) :
            base(group, key, threadPoolKey, circuitBreaker, threadPool, commandOptionsDefaults, threadPoolOptionsDefaults, metrics, fallbackSemaphore, executionSemaphore, optionsStrategy, executionHook, null, null, logger)
        {
            if (run == null)
            {
                _run = () => Run();
            }
            else
            {
                _run = run;
            }

            if (fallback == null)
            {
                _fallback = () => RunFallback();
            }
            else
            {
                _fallback = fallback;
            }
        }
예제 #23
0
        public static HystrixCommandConfiguration Sample(
            IHystrixCommandKey commandKey,
            IHystrixThreadPoolKey threadPoolKey,
            IHystrixCommandGroupKey groupKey,
            IHystrixCommandOptions commandProperties)
        {
            var executionConfig = new HystrixCommandExecutionConfig(
                commandProperties.ExecutionIsolationSemaphoreMaxConcurrentRequests,
                commandProperties.ExecutionIsolationStrategy,
                false,
                commandProperties.ExecutionIsolationThreadPoolKeyOverride,
                commandProperties.ExecutionTimeoutEnabled,
                commandProperties.ExecutionTimeoutInMilliseconds,
                commandProperties.FallbackEnabled,
                commandProperties.FallbackIsolationSemaphoreMaxConcurrentRequests,
                commandProperties.RequestCacheEnabled,
                commandProperties.RequestLogEnabled);

            var circuitBreakerConfig = new HystrixCommandCircuitBreakerConfig(
                commandProperties.CircuitBreakerEnabled,
                commandProperties.CircuitBreakerErrorThresholdPercentage,
                commandProperties.CircuitBreakerForceClosed,
                commandProperties.CircuitBreakerForceOpen,
                commandProperties.CircuitBreakerRequestVolumeThreshold,
                commandProperties.CircuitBreakerSleepWindowInMilliseconds);

            var metricsConfig = new HystrixCommandMetricsConfig(
                commandProperties.MetricsHealthSnapshotIntervalInMilliseconds,
                commandProperties.MetricsRollingPercentileEnabled,
                commandProperties.MetricsRollingPercentileWindowBuckets,
                commandProperties.MetricsRollingPercentileWindowInMilliseconds,
                commandProperties.MetricsRollingStatisticalWindowBuckets,
                commandProperties.MetricsRollingStatisticalWindowInMilliseconds);

            return(new HystrixCommandConfiguration(
                       commandKey, threadPoolKey, groupKey, executionConfig, circuitBreakerConfig, metricsConfig));
        }
        public HystrixDefinition(IHystrixCommandOptions commandOptions, MethodInfo methodInfo, object target)
        {
            HystrixCommandOptions = commandOptions ?? throw new ArgumentNullException(nameof(commandOptions));
            HystrixMethodInfo     = methodInfo ?? throw new ArgumentNullException(nameof(methodInfo));
            if (target == null)
            {
                throw new ArgumentNullException(nameof(target));
            }

            if (methodInfo.ReturnType.IsGenericType)
            {
                IsTypeOfTask = methodInfo.ReturnType.GetGenericTypeDefinition() == typeof(Task <>) ||
                               methodInfo.ReturnType.GetGenericTypeDefinition() == typeof(Task);
            }

            if (methodInfo.ReturnType == typeof(Task))
            {
                IsTypeOfTask = true;
            }

            HystrixBaseType         = DefineHystrixBaseType();
            PrimaryDelegateContext  = new DelegateContext(methodInfo);
            FallbackDelegateContext = new DelegateContext(methodInfo, typeof(HystrixFallback));
        }
예제 #25
0
 public override IHystrixMetricsPublisherCommand GetMetricsPublisherForCommand(IHystrixCommandKey commandKey, IHystrixCommandGroupKey commandGroupKey, HystrixCommandMetrics metrics, IHystrixCircuitBreaker circuitBreaker, IHystrixCommandOptions properties)
 {
     return(commandToReturn);
 }
예제 #26
0
 public override IHystrixMetricsPublisherCommand GetMetricsPublisherForCommand(IHystrixCommandKey commandKey, IHystrixCommandGroupKey commandOwner, HystrixCommandMetrics metrics, IHystrixCircuitBreaker circuitBreaker, IHystrixCommandOptions properties)
 {
     return(new MyHystrixMetricsPublisherCommand(commandCounter));
 }
예제 #27
0
        public static RollingCommandMaxConcurrencyStream GetInstance(IHystrixCommandKey commandKey, IHystrixCommandOptions properties)
        {
            int counterMetricWindow   = properties.MetricsRollingStatisticalWindowInMilliseconds;
            int numCounterBuckets     = properties.MetricsRollingStatisticalWindowBuckets;
            int counterBucketSizeInMs = counterMetricWindow / numCounterBuckets;

            return(GetInstance(commandKey, numCounterBuckets, counterBucketSizeInMs));
        }
예제 #28
0
 public SimpleCommand(ITestOutputHelper output, IHystrixCommandOptions opts)
     : base(opts)
 {
     this.output = output;
 }
예제 #29
0
        public static RollingCommandLatencyDistributionStream GetInstance(IHystrixCommandKey commandKey, IHystrixCommandOptions properties)
        {
            int percentileMetricWindow   = properties.MetricsRollingPercentileWindowInMilliseconds;
            int numPercentileBuckets     = properties.MetricsRollingPercentileWindowBuckets;
            int percentileBucketSizeInMs = percentileMetricWindow / numPercentileBuckets;

            return(GetInstance(commandKey, numPercentileBuckets, percentileBucketSizeInMs));
        }
예제 #30
0
        public static IHystrixCommandOptions GetCommandOptions(IHystrixCommandKey key, IHystrixCommandOptions builder)
        {
            var hystrixPropertiesStrategy = HystrixPlugins.OptionsStrategy;
            var cacheKey = hystrixPropertiesStrategy.GetCommandOptionsCacheKey(key, builder);

            if (cacheKey != null)
            {
                return(CommandProperties.GetOrAddEx(cacheKey, (k) => hystrixPropertiesStrategy.GetCommandOptions(key, builder)));
            }
            else
            {
                // no cacheKey so we generate it with caching
                return(hystrixPropertiesStrategy.GetCommandOptions(key, builder));
            }
        }