internal EventCounts Plus(HystrixEventType eventType, int count) { BitArray newBitSet = new BitArray(events); int localNumEmits = numEmissions; int localNumFallbackEmits = numFallbackEmissions; int localNumCollapsed = numCollapsed; switch (eventType) { case HystrixEventType.EMIT: newBitSet.Set((int)HystrixEventType.EMIT, true); localNumEmits += count; break; case HystrixEventType.FALLBACK_EMIT: newBitSet.Set((int)HystrixEventType.FALLBACK_EMIT, true); localNumFallbackEmits += count; break; case HystrixEventType.COLLAPSED: newBitSet.Set((int)HystrixEventType.COLLAPSED, true); localNumCollapsed += count; break; default: newBitSet.Set((int)eventType, true); break; } return(new EventCounts(newBitSet, localNumEmits, localNumFallbackEmits, localNumCollapsed)); }
public static Command From(IHystrixCommandGroupKey groupKey, IHystrixCommandKey key, HystrixEventType desiredEventType, int latency, ExecutionIsolationStrategy isolationStrategy, HystrixEventType desiredFallbackEventType, int fallbackLatency) { HystrixThreadPoolOptions topts = new HystrixThreadPoolOptions() { CoreSize = 10, MaxQueueSize = -1, ThreadPoolKey = HystrixThreadPoolKeyDefault.AsKey(groupKey.Name) }; HystrixCommandOptions setter = new HystrixCommandOptions() { GroupKey = groupKey, CommandKey = key, ExecutionTimeoutInMilliseconds = 600, ExecutionIsolationStrategy = isolationStrategy, CircuitBreakerEnabled = true, CircuitBreakerRequestVolumeThreshold = 3, MetricsHealthSnapshotIntervalInMilliseconds = 100, MetricsRollingStatisticalWindowInMilliseconds = 1000, MetricsRollingStatisticalWindowBuckets = 10, RequestCacheEnabled = true, RequestLogEnabled = true, FallbackIsolationSemaphoreMaxConcurrentRequests = 5, ThreadPoolKey = HystrixThreadPoolKeyDefault.AsKey(groupKey.Name), ThreadPoolOptions = topts }; String uniqueArg; switch (desiredEventType) { case HystrixEventType.SUCCESS: uniqueArg = uniqueId.IncrementAndGet() + ""; return(new Command(setter, HystrixEventType.SUCCESS, latency, uniqueArg, desiredFallbackEventType, 0)); case HystrixEventType.FAILURE: uniqueArg = uniqueId.IncrementAndGet() + ""; return(new Command(setter, HystrixEventType.FAILURE, latency, uniqueArg, desiredFallbackEventType, fallbackLatency)); case HystrixEventType.TIMEOUT: uniqueArg = uniqueId.IncrementAndGet() + ""; return(new Command(setter, HystrixEventType.SUCCESS, 1000, uniqueArg, desiredFallbackEventType, fallbackLatency)); case HystrixEventType.BAD_REQUEST: uniqueArg = uniqueId.IncrementAndGet() + ""; return(new Command(setter, HystrixEventType.BAD_REQUEST, latency, uniqueArg, desiredFallbackEventType, 0)); case HystrixEventType.RESPONSE_FROM_CACHE: String arg = uniqueId.Value + ""; return(new Command(setter, HystrixEventType.SUCCESS, 0, arg, desiredFallbackEventType, 0)); default: throw new Exception("not supported yet"); } }
public static HystrixRollingNumberEvent ToHystrixRollingNumberEvent(this HystrixEventType eventType) { switch (eventType) { case HystrixEventType.Success: return(HystrixRollingNumberEvent.Success); case HystrixEventType.Failure: return(HystrixRollingNumberEvent.Failure); case HystrixEventType.Timeout: return(HystrixRollingNumberEvent.Timeout); case HystrixEventType.ShortCircuited: return(HystrixRollingNumberEvent.ShortCircuited); case HystrixEventType.ThreadPoolRejected: return(HystrixRollingNumberEvent.ThreadPoolRejected); case HystrixEventType.SemaphoreRejected: return(HystrixRollingNumberEvent.SemaphoreRejected); case HystrixEventType.FallbackSuccess: return(HystrixRollingNumberEvent.FallbackSuccess); case HystrixEventType.FallbackFailure: return(HystrixRollingNumberEvent.FallbackFailure); case HystrixEventType.FallbackRejection: return(HystrixRollingNumberEvent.FallbackRejection); case HystrixEventType.ExceptionThrown: return(HystrixRollingNumberEvent.ExceptionThrown); case HystrixEventType.ResponseFromCache: return(HystrixRollingNumberEvent.ResponseFromCache); case HystrixEventType.Collapsed: return(HystrixRollingNumberEvent.Collapsed); default: throw new Exception("Unknown HystrixEventType : " + eventType); } }
static HystrixEventTypeHelper() { EXCEPTION_PRODUCING_EVENT_TYPES.Add(HystrixEventType.BAD_REQUEST); EXCEPTION_PRODUCING_EVENT_TYPES.Add(HystrixEventType.FALLBACK_FAILURE); EXCEPTION_PRODUCING_EVENT_TYPES.Add(HystrixEventType.FALLBACK_MISSING); EXCEPTION_PRODUCING_EVENT_TYPES.Add(HystrixEventType.FALLBACK_REJECTION); foreach (string evName in Enum.GetNames(typeof(HystrixEventType))) { HystrixEventType e = (HystrixEventType)Enum.Parse(typeof(HystrixEventType), evName); if (e.IsTerminal()) { TERMINAL_EVENT_TYPES.Add(e); } } valueList.Add(HystrixEventType.EMIT); valueList.Add(HystrixEventType.SUCCESS); valueList.Add(HystrixEventType.FAILURE); valueList.Add(HystrixEventType.TIMEOUT); valueList.Add(HystrixEventType.BAD_REQUEST); valueList.Add(HystrixEventType.SHORT_CIRCUITED); valueList.Add(HystrixEventType.THREAD_POOL_REJECTED); valueList.Add(HystrixEventType.SEMAPHORE_REJECTED); valueList.Add(HystrixEventType.FALLBACK_EMIT); valueList.Add(HystrixEventType.FALLBACK_SUCCESS); valueList.Add(HystrixEventType.FALLBACK_FAILURE); valueList.Add(HystrixEventType.FALLBACK_REJECTION); valueList.Add(HystrixEventType.FALLBACK_MISSING); valueList.Add(HystrixEventType.EXCEPTION_THROWN); valueList.Add(HystrixEventType.RESPONSE_FROM_CACHE); valueList.Add(HystrixEventType.CANCELLED); valueList.Add(HystrixEventType.COLLAPSED); }
static HystrixEventTypeHelper() { ExceptionProducingEventTypes.Add(HystrixEventType.BAD_REQUEST); ExceptionProducingEventTypes.Add(HystrixEventType.FALLBACK_FAILURE); ExceptionProducingEventTypes.Add(HystrixEventType.FALLBACK_MISSING); ExceptionProducingEventTypes.Add(HystrixEventType.FALLBACK_REJECTION); foreach (string evName in Enum.GetNames(typeof(HystrixEventType))) { HystrixEventType e = (HystrixEventType)Enum.Parse(typeof(HystrixEventType), evName); if (e.IsTerminal()) { TerminalEventTypes.Add(e); } } Values.Add(HystrixEventType.EMIT); Values.Add(HystrixEventType.SUCCESS); Values.Add(HystrixEventType.FAILURE); Values.Add(HystrixEventType.TIMEOUT); Values.Add(HystrixEventType.BAD_REQUEST); Values.Add(HystrixEventType.SHORT_CIRCUITED); Values.Add(HystrixEventType.THREAD_POOL_REJECTED); Values.Add(HystrixEventType.SEMAPHORE_REJECTED); Values.Add(HystrixEventType.FALLBACK_EMIT); Values.Add(HystrixEventType.FALLBACK_SUCCESS); Values.Add(HystrixEventType.FALLBACK_FAILURE); Values.Add(HystrixEventType.FALLBACK_REJECTION); Values.Add(HystrixEventType.FALLBACK_MISSING); Values.Add(HystrixEventType.EXCEPTION_THROWN); Values.Add(HystrixEventType.RESPONSE_FROM_CACHE); Values.Add(HystrixEventType.CANCELLED); Values.Add(HystrixEventType.COLLAPSED); }
public static bool IsTerminal(this HystrixEventType evType) { switch (evType) { case HystrixEventType.EMIT: return(false); case HystrixEventType.SUCCESS: return(false); case HystrixEventType.FAILURE: return(false); case HystrixEventType.TIMEOUT: return(false); case HystrixEventType.BAD_REQUEST: return(false); case HystrixEventType.SHORT_CIRCUITED: return(false); case HystrixEventType.THREAD_POOL_REJECTED: return(false); case HystrixEventType.SEMAPHORE_REJECTED: return(false); case HystrixEventType.FALLBACK_EMIT: return(false); case HystrixEventType.FALLBACK_SUCCESS: return(false); case HystrixEventType.FALLBACK_FAILURE: return(false); case HystrixEventType.FALLBACK_REJECTION: return(false); case HystrixEventType.FALLBACK_MISSING: return(false); case HystrixEventType.EXCEPTION_THROWN: return(false); case HystrixEventType.RESPONSE_FROM_CACHE: return(false); case HystrixEventType.CANCELLED: return(false); case HystrixEventType.COLLAPSED: return(false); default: throw new ArgumentOutOfRangeException(); } }
public static Command From( IHystrixCommandGroupKey groupKey, IHystrixCommandKey key, HystrixEventType desiredEventType, int latency, ExecutionIsolationStrategy isolationStrategy) { return(From(groupKey, key, desiredEventType, latency, isolationStrategy, HystrixEventType.FALLBACK_SUCCESS, 0)); }
public static Command From( IHystrixCommandGroupKey groupKey, IHystrixCommandKey key, HystrixEventType desiredEventType, int latency, HystrixEventType desiredFallbackEventType) { return(From(groupKey, key, desiredEventType, latency, ExecutionIsolationStrategy.THREAD, desiredFallbackEventType)); }
public static HystrixRollingNumberEvent From(HystrixEventType eventType) { switch (eventType) { case HystrixEventType.BAD_REQUEST: return(HystrixRollingNumberEvent.BAD_REQUEST); case HystrixEventType.COLLAPSED: return(HystrixRollingNumberEvent.COLLAPSED); case HystrixEventType.EMIT: return(HystrixRollingNumberEvent.EMIT); case HystrixEventType.EXCEPTION_THROWN: return(HystrixRollingNumberEvent.EXCEPTION_THROWN); case HystrixEventType.FAILURE: return(HystrixRollingNumberEvent.FAILURE); case HystrixEventType.FALLBACK_EMIT: return(HystrixRollingNumberEvent.FALLBACK_EMIT); case HystrixEventType.FALLBACK_FAILURE: return(HystrixRollingNumberEvent.FALLBACK_FAILURE); case HystrixEventType.FALLBACK_MISSING: return(HystrixRollingNumberEvent.FALLBACK_MISSING); case HystrixEventType.FALLBACK_REJECTION: return(HystrixRollingNumberEvent.FALLBACK_REJECTION); case HystrixEventType.FALLBACK_SUCCESS: return(HystrixRollingNumberEvent.FALLBACK_SUCCESS); case HystrixEventType.RESPONSE_FROM_CACHE: return(HystrixRollingNumberEvent.RESPONSE_FROM_CACHE); case HystrixEventType.SEMAPHORE_REJECTED: return(HystrixRollingNumberEvent.SEMAPHORE_REJECTED); case HystrixEventType.SHORT_CIRCUITED: return(HystrixRollingNumberEvent.SHORT_CIRCUITED); case HystrixEventType.SUCCESS: return(HystrixRollingNumberEvent.SUCCESS); case HystrixEventType.THREAD_POOL_REJECTED: return(HystrixRollingNumberEvent.THREAD_POOL_REJECTED); case HystrixEventType.TIMEOUT: return(HystrixRollingNumberEvent.TIMEOUT); default: throw new ArgumentOutOfRangeException("Unknown HystrixEventType : " + eventType); } }
public int GetCount(HystrixEventType eventType) { return(eventType switch { HystrixEventType.EMIT => _numEmissions, HystrixEventType.FALLBACK_EMIT => _numFallbackEmissions, HystrixEventType.EXCEPTION_THROWN => ContainsAnyOf(EXCEPTION_PRODUCING_EVENTS) ? 1 : 0, HystrixEventType.COLLAPSED => _numCollapsed, _ => Contains(eventType) ? 1 : 0, });
private Command(HystrixCommandOptions setter, HystrixEventType executionResult, int executionLatency, String arg, HystrixEventType fallbackExecutionResult, int fallbackExecutionLatency) : base(setter) { this.executionResult = executionResult; this.executionLatency = executionLatency; this.fallbackExecutionResult = fallbackExecutionResult; this.fallbackExecutionLatency = fallbackExecutionLatency; this.arg = arg; this._isFallbackUserDefined = true; }
public ExecutionResult AddEvent(HystrixEventType eventType) { return(new ExecutionResult( Eventcounts.Plus(eventType), StartTimestamp, ExecutionLatency, UserThreadLatency, Exception, ExecutionException, ExecutionOccurred, IsExecutedInThread, CollapserKey)); }
public ExecutionResult AddEvent(HystrixEventType eventType) { return(new ExecutionResult( eventCounts.Plus(eventType), startTimestamp, executionLatency, userThreadLatency, failedExecutionException, executionException, executionOccurred, isExecutedInThread, collapserKey)); }
public ExecutionResult AddEvent(int executionLatency, HystrixEventType eventType) { if (startTimestamp >= 0 && !IsResponseRejected) { return(new ExecutionResult(eventCounts.Plus(eventType), startTimestamp, executionLatency, userThreadLatency, failedExecutionException, executionException, executionOccurred, isExecutedInThread, collapserKey)); } else { return(AddEvent(eventType)); } }
public int GetCount(HystrixEventType eventType) { switch (eventType) { case HystrixEventType.EMIT: return(numEmissions); case HystrixEventType.FALLBACK_EMIT: return(numFallbackEmissions); case HystrixEventType.EXCEPTION_THROWN: return(ContainsAnyOf(EXCEPTION_PRODUCING_EVENTS) ? 1 : 0); case HystrixEventType.COLLAPSED: return(numCollapsed); default: return(Contains(eventType) ? 1 : 0); } }
public void SendSyncSLAErrorResponse(HystrixEventType hystrixEvent) { _executedSynchronously = true; // indicating this is executed synchronously _slaErrorSent = true; _startTime = DateTime.Now; _httpRequest.InputStream.Close(); // do not care var message = "服务端发生了熔断,并进入了自我保护状态,服务端恢复后此错误会自动消失!"; _executionResult.ExceptionCaught = new Exception(message); if (this._endpointHandler != null) { _endpointHandler.SendSyncSLAErrorResponse(_httpRequest, _httpResponse, hystrixEvent); } }
private static bool DidExecutionOccur(HystrixEventType eventType) { switch (eventType) { case HystrixEventType.SUCCESS: return(true); case HystrixEventType.FAILURE: return(true); case HystrixEventType.BAD_REQUEST: return(true); case HystrixEventType.TIMEOUT: return(true); case HystrixEventType.CANCELLED: return(true); default: return(false); } }
public ExecutionResult AddEvent(int executionLatency, HystrixEventType eventType) { if (StartTimestamp >= 0 && !IsResponseRejected) { return(new ExecutionResult( Eventcounts.Plus(eventType), StartTimestamp, executionLatency, UserThreadLatency, Exception, ExecutionException, ExecutionOccurred, IsExecutedInThread, CollapserKey)); } else { return(AddEvent(eventType)); } }
public static HystrixRollingNumberEvent From(HystrixEventType eventType) { return(eventType switch { HystrixEventType.BAD_REQUEST => HystrixRollingNumberEvent.BAD_REQUEST, HystrixEventType.COLLAPSED => HystrixRollingNumberEvent.COLLAPSED, HystrixEventType.EMIT => HystrixRollingNumberEvent.EMIT, HystrixEventType.EXCEPTION_THROWN => HystrixRollingNumberEvent.EXCEPTION_THROWN, HystrixEventType.FAILURE => HystrixRollingNumberEvent.FAILURE, HystrixEventType.FALLBACK_EMIT => HystrixRollingNumberEvent.FALLBACK_EMIT, HystrixEventType.FALLBACK_FAILURE => HystrixRollingNumberEvent.FALLBACK_FAILURE, HystrixEventType.FALLBACK_MISSING => HystrixRollingNumberEvent.FALLBACK_MISSING, HystrixEventType.FALLBACK_REJECTION => HystrixRollingNumberEvent.FALLBACK_REJECTION, HystrixEventType.FALLBACK_SUCCESS => HystrixRollingNumberEvent.FALLBACK_SUCCESS, HystrixEventType.RESPONSE_FROM_CACHE => HystrixRollingNumberEvent.RESPONSE_FROM_CACHE, HystrixEventType.SEMAPHORE_REJECTED => HystrixRollingNumberEvent.SEMAPHORE_REJECTED, HystrixEventType.SHORT_CIRCUITED => HystrixRollingNumberEvent.SHORT_CIRCUITED, HystrixEventType.SUCCESS => HystrixRollingNumberEvent.SUCCESS, HystrixEventType.THREAD_POOL_REJECTED => HystrixRollingNumberEvent.THREAD_POOL_REJECTED, HystrixEventType.TIMEOUT => HystrixRollingNumberEvent.TIMEOUT, _ => throw new ArgumentOutOfRangeException("Unknown HystrixEventType : " + eventType), });
public static bool IsTerminal(this HystrixEventType evType) { return(evType switch { HystrixEventType.EMIT => false, HystrixEventType.SUCCESS => false, HystrixEventType.FAILURE => false, HystrixEventType.TIMEOUT => false, HystrixEventType.BAD_REQUEST => false, HystrixEventType.SHORT_CIRCUITED => false, HystrixEventType.THREAD_POOL_REJECTED => false, HystrixEventType.SEMAPHORE_REJECTED => false, HystrixEventType.FALLBACK_EMIT => false, HystrixEventType.FALLBACK_SUCCESS => false, HystrixEventType.FALLBACK_FAILURE => false, HystrixEventType.FALLBACK_REJECTION => false, HystrixEventType.FALLBACK_MISSING => false, HystrixEventType.EXCEPTION_THROWN => false, HystrixEventType.RESPONSE_FROM_CACHE => false, HystrixEventType.CANCELLED => false, HystrixEventType.COLLAPSED => false, _ => throw new ArgumentOutOfRangeException(), });
public static ThreadPoolEventType From(this HystrixEventType eventType) { switch (eventType) { case HystrixEventType.SUCCESS: return(ThreadPoolEventType.EXECUTED); case HystrixEventType.FAILURE: return(ThreadPoolEventType.EXECUTED); case HystrixEventType.TIMEOUT: return(ThreadPoolEventType.EXECUTED); case HystrixEventType.BAD_REQUEST: return(ThreadPoolEventType.EXECUTED); case HystrixEventType.THREAD_POOL_REJECTED: return(ThreadPoolEventType.REJECTED); default: return(ThreadPoolEventType.UNKNOWN); } }
/// <summary> /// Create SLA Error response /// </summary> /// <param name="hystrixEvent">the hystrix event caused the error</param> /// <param name="responseType">target response type</param> /// <returns></returns> public static object CreateSLAErrorResponse(HystrixEventType hystrixEvent, Type responseType) { var error = new ErrorDataType(); if (hystrixEvent == HystrixEventType.ShortCircuited) { error.Message = "Server entered into self-protecting mode"; error.ErrorCode = hystrixEvent.ToString(); } if (hystrixEvent == HystrixEventType.ThreadPoolRejected) { error.Message = "Server entered into rate-limiting mode"; error.ErrorCode = hystrixEvent.ToString(); } error.SeverityCode = SeverityCodeType.Error; error.ErrorClassification = ErrorClassificationCodeType.SLAError; var errors = new List <ErrorDataType>() { error }; var errorResponse = CreateErrorResponseDto(errors, responseType); if (HostContext.Instance.Request != null) { var metadata = EndpointHost.MetadataMap[HostContext.Instance.Request.ServicePath]; var additionalData = new Dictionary <string, string>(); additionalData.Add("Service", metadata.FullServiceName); additionalData.Add("Operation", HostContext.Instance.Request.OperationName); additionalData.Add("ErrorCode", "FXD300005"); Log.Error("SLA error occurred: Circuit Breaker is open.", additionalData); } return(errorResponse); }
public virtual void MarkEvent(HystrixEventType eventType, HystrixCommandKey key) { // do nothing }
public override void SendSyncSLAErrorResponse(IHttpRequest request, IHttpResponse response, HystrixEventType hystrixEvent) { this.SetResponseContentTypeFromRouteContentTypeExtension(request); base.SendSyncSLAErrorResponse(request, response, hystrixEvent); }
internal EventCounts Plus(HystrixEventType eventType) { return(Plus(eventType, 1)); }
public bool Contains(HystrixEventType eventType) { return(events.Get((int)eventType)); }
public long GetRollingCount(HystrixEventType eventType) { return(_rollingCommandEventCounterStream.GetLatest(eventType)); }
public long GetCumulativeCount(HystrixEventType eventType) { return(_cumulativeCommandEventCounterStream.GetLatest(eventType)); }
public static Command From(IHystrixCommandGroupKey groupKey, IHystrixCommandKey key, HystrixEventType desiredEventType) { return(From(groupKey, key, desiredEventType, 0)); }
public virtual void SendSyncSLAErrorResponse(IHttpRequest request, IHttpResponse response, HystrixEventType hystrixEvent) { Type responseType = EndpointHost.Config.MetadataMap[ServicePath].GetResponseTypeByOpName(request.OperationName); var errorResponse = ErrorUtils.CreateSLAErrorResponse(hystrixEvent, responseType); response.WriteToResponse(request, errorResponse); }
public long GetLatest(HystrixEventType eventType) { return(Latest[(int)eventType]); }