Ejemplo n.º 1
0
        public void TestMaxValue()
        {
            MockedTime time = new MockedTime();

            try
            {
                HystrixRollingNumberEvent type = HystrixRollingNumberEvent.THREAD_MAX_ACTIVE;

                HystrixRollingNumber counter = new HystrixRollingNumber(time, 200, 10);

                counter.UpdateRollingMax(type, 10);

                // sleep to get to a new bucket
                time.Increment(counter._bucketSizeInMillseconds);

                counter.UpdateRollingMax(type, 30);

                // sleep to get to a new bucket
                time.Increment(counter._bucketSizeInMillseconds);

                counter.UpdateRollingMax(type, 40);

                // sleep to get to a new bucket
                time.Increment(counter._bucketSizeInMillseconds);

                counter.UpdateRollingMax(type, 15);

                Assert.Equal(40, counter.GetRollingMaxValue(type));
            }
            catch (Exception e)
            {
                output.WriteLine(e.ToString());
                Assert.True(false, "Exception: " + e.Message);
            }
        }
Ejemplo n.º 2
0
 public long GetCumulativeSum(HystrixRollingNumberEvent type)
 {
     // this isn't 100% atomic since multiple threads can be affecting latestBucket & cumulativeSum independently
     // but that's okay since the count is always a moving target and we're accepting a "point in time" best attempt
     // we are however putting 'getValueOfLatestBucket' first since it can have side-affects on cumulativeSum whereas the inverse is not true
     return(GetValueOfLatestBucket(type) + _cumulativeSum.Get(type));
 }
Ejemplo n.º 3
0
        public void RollingNumber_MaxValue()
        {
            MockedTime time = new MockedTime();

            try
            {
                HystrixRollingNumberEvent type = HystrixRollingNumberEvent.ThreadMaxActive;

                HystrixRollingNumber counter = new HystrixRollingNumber(time, 200, 10);

                counter.UpdateRollingMax(type, 10);

                // sleep to get to a new bucket
                time.Increment(counter.BucketSizeInMilliseconds);

                counter.UpdateRollingMax(type, 30);

                // sleep to get to a new bucket
                time.Increment(counter.BucketSizeInMilliseconds);

                counter.UpdateRollingMax(type, 40);

                // sleep to get to a new bucket
                time.Increment(counter.BucketSizeInMilliseconds);

                counter.UpdateRollingMax(type, 15);

                Assert.AreEqual(40, counter.GetRollingMaxValue(type));
            }
            catch (Exception e)
            {
                TestContext.WriteLine(e.ToString());
                Assert.Fail("Exception: " + e.Message);
            }
        }
Ejemplo n.º 4
0
        public void RollingNumber_CumulativeCounterAfterRolling()
        {
            MockedTime time = new MockedTime();
            HystrixRollingNumberEvent type    = HystrixRollingNumberEvent.Success;
            HystrixRollingNumber      counter = new HystrixRollingNumber(time, 20, 2);

            Assert.AreEqual(0, counter.GetCumulativeSum(type));

            // iterate over 20 buckets on a queue sized for 2
            for (int i = 0; i < 20; i++)
            {
                // first bucket
                counter.Increment(type);
                try
                {
                    time.Increment(counter.BucketSizeInMilliseconds);
                }
                catch (Exception)
                {
                    // ignore
                }

                Assert.AreEqual(2, counter.GetValues(type).Length);

                counter.GetValueOfLatestBucket(type);
            }

            // cumulative count should be 20 (for the number of loops above) regardless of buckets rolling
            Assert.AreEqual(20, counter.GetCumulativeSum(type));
        }
Ejemplo n.º 5
0
        public void RollingNumber_Rolling()
        {
            MockedTime time = new MockedTime();
            HystrixRollingNumberEvent type    = HystrixRollingNumberEvent.ThreadMaxActive;
            HystrixRollingNumber      counter = new HystrixRollingNumber(time, 20, 2);

            // iterate over 20 buckets on a queue sized for 2
            for (int i = 0; i < 20; i++)
            {
                // first bucket
                counter.GetCurrentBucket();
                try
                {
                    time.Increment(counter.BucketSizeInMilliseconds);
                }
                catch (Exception)
                {
                    // ignore
                }

                Assert.AreEqual(2, counter.GetValues(type).Length);

                counter.GetValueOfLatestBucket(type);

                // System.out.println("Head: " + counter.Buckets.state.Get().head);
                // System.out.println("Tail: " + counter.Buckets.state.Get().tail);
            }
        }
Ejemplo n.º 6
0
        public void RollingNumber_CumulativeCounterAfterRollingAndReset3()
        {
            MockedTime time = new MockedTime();
            HystrixRollingNumberEvent type    = HystrixRollingNumberEvent.Success;
            HystrixRollingNumber      counter = new HystrixRollingNumber(time, 20, 2);

            Assert.AreEqual(0, counter.GetCumulativeSum(type));

            counter.Increment(type);
            counter.Increment(type);
            counter.Increment(type);

            // iterate over 20 buckets on a queue sized for 2
            for (int i = 0; i < 20; i++)
            {
                try
                {
                    time.Increment(counter.BucketSizeInMilliseconds);
                }
                catch (Exception)
                {
                    // ignore
                }
            }

            // since we are rolling over the buckets it should reset naturally

            // no increments during the loop, just some before and after
            counter.Increment(type);
            counter.Increment(type);

            // cumulative count should be 5 regardless of buckets rolling
            Assert.AreEqual(5, counter.GetCumulativeSum(type));
        }
        public static bool IsCounter(HystrixRollingNumberEvent @event)
        {
            switch (@event)
            {
            case HystrixRollingNumberEvent.SUCCESS:
            case HystrixRollingNumberEvent.FAILURE:
            case HystrixRollingNumberEvent.TIMEOUT:
            case HystrixRollingNumberEvent.SHORT_CIRCUITED:
            case HystrixRollingNumberEvent.THREAD_POOL_REJECTED:
            case HystrixRollingNumberEvent.SEMAPHORE_REJECTED:
            case HystrixRollingNumberEvent.BAD_REQUEST:
            case HystrixRollingNumberEvent.FALLBACK_SUCCESS:
            case HystrixRollingNumberEvent.FALLBACK_FAILURE:
            case HystrixRollingNumberEvent.FALLBACK_REJECTION:
            case HystrixRollingNumberEvent.FALLBACK_MISSING:
            case HystrixRollingNumberEvent.EXCEPTION_THROWN:
            case HystrixRollingNumberEvent.EMIT:
            case HystrixRollingNumberEvent.FALLBACK_EMIT:
            case HystrixRollingNumberEvent.THREAD_EXECUTION:
            case HystrixRollingNumberEvent.COLLAPSED:
            case HystrixRollingNumberEvent.RESPONSE_FROM_CACHE:
            case HystrixRollingNumberEvent.COLLAPSER_REQUEST_BATCHED:
            case HystrixRollingNumberEvent.COLLAPSER_BATCH:
                return(true);

            default:
                return(false);
            }
        }
Ejemplo n.º 8
0
        public long[] GetValues(HystrixRollingNumberEvent type)
        {
            Bucket lastBucket = GetCurrentBucket();

            if (lastBucket == null)
            {
                return(new long[0]);
            }

            // get buckets as an array (which is a copy of the current state at this point in time)
            Bucket[] bucketArray = _buckets.Array;

            // we have bucket data so we'll return an array of values for all buckets
            long[] values = new long[bucketArray.Length];
            int    i      = 0;

            foreach (Bucket bucket in bucketArray)
            {
                if (HystrixRollingNumberEventHelper.IsCounter(type))
                {
                    values[i++] = bucket.GetAdder(type).Sum();
                }
                else if (HystrixRollingNumberEventHelper.IsMaxUpdater(type))
                {
                    values[i++] = bucket.GetMaxUpdater(type).Max;
                }
            }

            return(values);
        }
 public LongAdder GetAdder(HystrixRollingNumberEvent type)
 {
     if (!HystrixRollingNumberEventHelper.IsCounter(type))
     {
         throw new InvalidOperationException("Type is not a Counter: " + type.ToString());
     }
     return(adderForCounterType[(int)type]);
 }
Ejemplo n.º 10
0
 public LongMaxUpdater GetMaxUpdater(HystrixRollingNumberEvent type)
 {
     if (!type.IsMaxUpdater())
     {
         throw new InvalidOperationException("Type is not a MaxUpdater: " + type);
     }
     return(updaterForCounterType[(int)type]);
 }
Ejemplo n.º 11
0
        public void RollingNumber_EmptyLatestValue()
        {
            MockedTime time = new MockedTime();
            HystrixRollingNumberEvent type    = HystrixRollingNumberEvent.ThreadMaxActive;
            HystrixRollingNumber      counter = new HystrixRollingNumber(time, 200, 10);

            Assert.AreEqual(0, counter.GetValueOfLatestBucket(type));
        }
Ejemplo n.º 12
0
        private static bool HasAttribute <T>(HystrixRollingNumberEvent hystrixRollingNumberEvent)
        {
            var type       = typeof(HystrixRollingNumberEvent);
            var memInfo    = type.GetMember(hystrixRollingNumberEvent.ToString());
            var attributes = memInfo[0].GetCustomAttributes(typeof(T), false);

            return(attributes.Length > 0);
        }
Ejemplo n.º 13
0
 public static ThreadPoolEventType From(this HystrixRollingNumberEvent @event)
 {
     return(@event switch
     {
         HystrixRollingNumberEvent.THREAD_EXECUTION => ThreadPoolEventType.EXECUTED,
         HystrixRollingNumberEvent.THREAD_POOL_REJECTED => ThreadPoolEventType.REJECTED,
         _ => throw new ArgumentOutOfRangeException("Not an event that can be converted to HystrixEventType.ThreadPool : " + @event),
     });
Ejemplo n.º 14
0
        public void RollingNumber_EmptySum()
        {
            MockedTime time = new MockedTime();
            HystrixRollingNumberEvent type    = HystrixRollingNumberEvent.Collapsed;
            HystrixRollingNumber      counter = new HystrixRollingNumber(time, 200, 10);

            Assert.AreEqual(0, counter.GetRollingSum(type));
        }
Ejemplo n.º 15
0
        public void TestEmptySum()
        {
            MockedTime time = new MockedTime();
            HystrixRollingNumberEvent type    = HystrixRollingNumberEvent.COLLAPSED;
            HystrixRollingNumber      counter = new HystrixRollingNumber(time, 200, 10);

            Assert.Equal(0, counter.GetRollingSum(type));
        }
Ejemplo n.º 16
0
        public void TestEmptyLatestValue()
        {
            MockedTime time = new MockedTime();
            HystrixRollingNumberEvent type    = HystrixRollingNumberEvent.THREAD_MAX_ACTIVE;
            HystrixRollingNumber      counter = new HystrixRollingNumber(time, 200, 10);

            Assert.Equal(0, counter.GetValueOfLatestBucket(type));
        }
Ejemplo n.º 17
0
            public LongMaxUpdater GetMaxUpdater(HystrixRollingNumberEvent type)
            {
                if (!HystrixRollingNumberEventHelper.IsMaxUpdater(type))
                {
                    throw new InvalidOperationException("Type is not a MaxUpdater: " + type.ToString());
                }

                return _updaterForCounterType[(int)type];
            }
Ejemplo n.º 18
0
 public static CollapserEventType From(this HystrixRollingNumberEvent @event)
 {
     return(@event switch
     {
         HystrixRollingNumberEvent.COLLAPSER_BATCH => CollapserEventType.BATCH_EXECUTED,
         HystrixRollingNumberEvent.COLLAPSER_REQUEST_BATCHED => CollapserEventType.ADDED_TO_BATCH,
         HystrixRollingNumberEvent.RESPONSE_FROM_CACHE => CollapserEventType.RESPONSE_FROM_CACHE,
         _ => throw new ArgumentOutOfRangeException("Not an event that can be converted to HystrixEventType.Collapser : " + @event),
     });
Ejemplo n.º 19
0
            /// <summary>
            /// Gets the <see cref="LongMaxUpdater"/> instance for the specified event.
            /// </summary>
            /// <param name="type">The specified event.</param>
            /// <returns>The <see cref="LongMaxUpdater"/> instance for the specified event.</returns>
            public LongMaxUpdater GetMaxUpdater(HystrixRollingNumberEvent type)
            {
                if (!type.IsMaxUpdater())
                {
                    throw new ArgumentException(string.Format("Type is not a MaxUpdater: {0}", type), "type");
                }

                return(this.updaterForCounterType[(int)type]);
            }
Ejemplo n.º 20
0
        public static HystrixEventType From(this HystrixRollingNumberEvent @event)
        {
            switch (@event)
            {
            case HystrixRollingNumberEvent.EMIT:
                return(HystrixEventType.EMIT);

            case HystrixRollingNumberEvent.SUCCESS:
                return(HystrixEventType.SUCCESS);

            case HystrixRollingNumberEvent.FAILURE:
                return(HystrixEventType.FAILURE);

            case HystrixRollingNumberEvent.TIMEOUT:
                return(HystrixEventType.TIMEOUT);

            case HystrixRollingNumberEvent.SHORT_CIRCUITED:
                return(HystrixEventType.SHORT_CIRCUITED);

            case HystrixRollingNumberEvent.THREAD_POOL_REJECTED:
                return(HystrixEventType.THREAD_POOL_REJECTED);

            case HystrixRollingNumberEvent.SEMAPHORE_REJECTED:
                return(HystrixEventType.SEMAPHORE_REJECTED);

            case HystrixRollingNumberEvent.FALLBACK_EMIT:
                return(HystrixEventType.FALLBACK_EMIT);

            case HystrixRollingNumberEvent.FALLBACK_SUCCESS:
                return(HystrixEventType.FALLBACK_SUCCESS);

            case HystrixRollingNumberEvent.FALLBACK_FAILURE:
                return(HystrixEventType.FALLBACK_FAILURE);

            case HystrixRollingNumberEvent.FALLBACK_REJECTION:
                return(HystrixEventType.FALLBACK_REJECTION);

            case HystrixRollingNumberEvent.FALLBACK_MISSING:
                return(HystrixEventType.FALLBACK_MISSING);

            case HystrixRollingNumberEvent.EXCEPTION_THROWN:
                return(HystrixEventType.EXCEPTION_THROWN);

            case HystrixRollingNumberEvent.RESPONSE_FROM_CACHE:
                return(HystrixEventType.RESPONSE_FROM_CACHE);

            case HystrixRollingNumberEvent.COLLAPSED:
                return(HystrixEventType.COLLAPSED);

            case HystrixRollingNumberEvent.BAD_REQUEST:
                return(HystrixEventType.BAD_REQUEST);

            default:
                throw new ArgumentOutOfRangeException("Not an event that can be converted to HystrixEventType : " + @event);
            }
        }
Ejemplo n.º 21
0
        public long GetRollingMaxValue(HystrixRollingNumberEvent type)
        {
            long[] values = GetValues(type);
            if (values.Length == 0)
            {
                return(0);
            }

            Array.Sort(values);
            return(values[values.Length - 1]);
        }
        /**
         * Get the value of the latest (current) bucket in the rolling counter for the given {@link HystrixRollingNumberEvent} type.
         * <p>
         * The {@link HystrixRollingNumberEvent} must be a "counter" type <code>HystrixRollingNumberEvent.isCounter() == true</code>.
         *
         * @param type
         *            HystrixRollingNumberEvent defining which counter to retrieve value from
         * @return
         *         value from latest bucket for given {@link HystrixRollingNumberEvent} counter type
         */
        public long GetValueOfLatestBucket(HystrixRollingNumberEvent type)
        {
            Bucket lastBucket = GetCurrentBucket();

            if (lastBucket == null)
            {
                return(0);
            }
            // we have bucket data so we'll return the lastBucket
            return(lastBucket.Get(type));
        }
        public static bool IsMaxUpdater(HystrixRollingNumberEvent @event)
        {
            switch (@event)
            {
            case HystrixRollingNumberEvent.COMMAND_MAX_ACTIVE:
            case HystrixRollingNumberEvent.THREAD_MAX_ACTIVE:
                return(true);

            default:
                return(false);
            }
        }
 public long Get(HystrixRollingNumberEvent type)
 {
     if (HystrixRollingNumberEventHelper.IsCounter(type))
     {
         return(adderForCounterType[(int)type].Sum());
     }
     if (HystrixRollingNumberEventHelper.IsMaxUpdater(type))
     {
         return(updaterForCounterType[(int)type].Max);
     }
     throw new InvalidOperationException("Unknown type of event: " + type.ToString());
 }
Ejemplo n.º 25
0
        public long Get(HystrixRollingNumberEvent type)
        {
            if (type.IsCounter())
            {
                return(adderForCounterType[(int)type].GetValue());
            }
            if (type.IsMaxUpdater())
            {
                return(updaterForCounterType[(int)type].Max());
            }

            throw new InvalidOperationException("Unknown type of event: " + type);
        }
Ejemplo n.º 26
0
        public static ThreadPoolEventType From(this HystrixRollingNumberEvent @event)
        {
            switch (@event)
            {
            case HystrixRollingNumberEvent.THREAD_EXECUTION:
                return(ThreadPoolEventType.EXECUTED);

            case HystrixRollingNumberEvent.THREAD_POOL_REJECTED:
                return(ThreadPoolEventType.REJECTED);

            default:
                throw new ArgumentOutOfRangeException("Not an event that can be converted to HystrixEventType.ThreadPool : " + @event);
            }
        }
Ejemplo n.º 27
0
            public void Throws_InvalidOperationException_For_All_Hystrix_RollingNumberEvent_Items_That_Are_Not_MaxUpdaters()
            {
                var bucket     = new RollingNumberBucket(DateTime.UtcNow.Ticks / TimeSpan.TicksPerMillisecond);
                var enumValues = Enum.GetValues(typeof(HystrixRollingNumberEvent)).Cast <HystrixRollingNumberEvent>();

                foreach (var enumValue in enumValues)
                {
                    if (!enumValue.IsMaxUpdater())
                    {
                        HystrixRollingNumberEvent value = enumValue;
                        Assert.Throws <InvalidOperationException>(() => bucket.GetMaxUpdater(value));
                    }
                }
            }
Ejemplo n.º 28
0
            /// <summary>
            /// Gets the value for the specified <see cref="HystrixRollingNumberEvent"/> in this bucket.
            /// (Returns <see cref="LongAdder.Sum()"/> for Counter types and <see cref="LongMaxUpdater.Max()"/> for MaxUpdater types.)
            /// </summary>
            /// <param name="type">The specified event.</param>
            /// <returns>The value for the specified event in this bucket.</returns>
            public long Get(HystrixRollingNumberEvent type)
            {
                if (type.IsCounter())
                {
                    return(this.adderForCounterType[(int)type].Sum());
                }

                if (type.IsMaxUpdater())
                {
                    return(this.updaterForCounterType[(int)type].Max());
                }

                throw new ArgumentException(string.Format("Unknown type of event: {0}", type), "type");
            }
Ejemplo n.º 29
0
        /// <summary>
        /// Get the sum of all buckets in the rolling counter for the given <see cref="HystrixRollingNumberEvent"/> type.
        /// The <see cref="HystrixRollingNumberEvent"/> must be a "Counter" type (HystrixRollingNumberEvent.IsCounter() == true).
        /// </summary>
        /// <param name="type">defining which counter to retrieve values from</param>
        /// <returns>Value from the given <see cref="HystrixRollingNumberEvent"/> counter type.</returns>
        public long GetRollingSum(HystrixRollingNumberEvent type)
        {
            if (this.GetCurrentBucket() == null)
            {
                return(0);
            }

            long sum = 0;

            foreach (Bucket b in this.buckets)
            {
                sum += b.GetAdder(type).Sum();
            }

            return(sum);
        }
Ejemplo n.º 30
0
        public static CollapserEventType From(this HystrixRollingNumberEvent @event)
        {
            switch (@event)
            {
            case HystrixRollingNumberEvent.COLLAPSER_BATCH:
                return(CollapserEventType.BATCH_EXECUTED);

            case HystrixRollingNumberEvent.COLLAPSER_REQUEST_BATCHED:
                return(CollapserEventType.ADDED_TO_BATCH);

            case HystrixRollingNumberEvent.RESPONSE_FROM_CACHE:
                return(CollapserEventType.RESPONSE_FROM_CACHE);

            default:
                throw new ArgumentOutOfRangeException("Not an event that can be converted to HystrixEventType.Collapser : " + @event);
            }
        }
Ejemplo n.º 31
0
        /// <summary>
        /// Get the sum of all buckets in the rolling counter for the given <see cref="HystrixRollingNumberEvent"/> type.
        /// The <see cref="HystrixRollingNumberEvent"/> must be a "Counter" type (HystrixRollingNumberEvent.IsCounter() == true).
        /// </summary>
        /// <param name="type">defining which counter to retrieve values from</param>
        /// <returns>Value from the given <see cref="HystrixRollingNumberEvent"/> counter type.</returns>
        public long GetRollingSum(HystrixRollingNumberEvent type)
        {
            if (this.GetCurrentBucket() == null)
            {
                return 0;
            }

            long sum = 0;
            foreach (Bucket b in this.buckets)
            {
                sum += b.GetAdder(type).Sum();
            }

            return sum;
        }
Ejemplo n.º 32
0
        private void TestCounterType(HystrixRollingNumberEvent type)
        {
            MockedTime time = new MockedTime();
            try
            {
                HystrixRollingNumber counter = new HystrixRollingNumber(time, 200, 10);

                // increment
                counter.Increment(type);

                // we should have 1 bucket
                Assert.AreEqual(1, counter.Buckets.Size);

                // the count should be 1
                Assert.AreEqual(1, counter.Buckets.GetLast().GetAdder(type).Sum());
                Assert.AreEqual(1, counter.GetRollingSum(type));

                // sleep to get to a new bucket
                time.Increment(counter.BucketSizeInMilliseconds * 3);

                // increment again in latest bucket
                counter.Increment(type);

                // we should have 4 buckets
                Assert.AreEqual(4, counter.Buckets.Size);

                // the counts of the last bucket
                Assert.AreEqual(1, counter.Buckets.GetLast().GetAdder(type).Sum());

                // the total counts
                Assert.AreEqual(2, counter.GetRollingSum(type));

            }
            catch (Exception e)
            {
                TestContext.WriteLine(e.ToString());
                Assert.Fail("Exception: " + e.Message);
            }
        }
Ejemplo n.º 33
0
        /// <summary>
        /// Get the value of the latest (current) bucket in the rolling counter for the given <see cref="HystrixRollingNumberEvent"/> type.
        /// The <see cref="HystrixRollingNumberEvent"/> must be a "Counter" type (HystrixRollingNumberEvent.IsCounter() == true).
        /// </summary>
        /// <param name="type">HystrixRollingNumberEvent defining which counter to retrieve value from</param>
        /// <returns>value from latest bucket for given <see cref="HystrixRollingNumberEvent"/> counter type</returns>
        public long GetValueOfLatestBucket(HystrixRollingNumberEvent type)
        {
            Bucket lastBucket = this.GetCurrentBucket();
            if (lastBucket == null)
            {
                return 0;
            }

            // we have bucket data so we'll return the lastBucket
            return lastBucket.Get(type);
        }
Ejemplo n.º 34
0
        /// <summary>
        /// Get an array of values for all buckets in the rolling counter for the given <see cref="HystrixRollingNumberEvent"/> type.
        /// Index 0 is the oldest bucket.
        /// The <see cref="HystrixRollingNumberEvent"/> must be a "Counter" type (HystrixRollingNumberEvent.IsCounter() == true).
        /// </summary>
        /// <param name="type">HystrixRollingNumberEvent defining which counter to retrieve values from</param>
        /// <returns>Array of values from each of the rolling buckets for given <see cref="HystrixRollingNumberEvent"/> counter type</returns>
        public long[] GetValues(HystrixRollingNumberEvent type)
        {
            if (this.GetCurrentBucket() == null)
            {
                return new long[0];
            }

            // get buckets as an array (which is a copy of the current state at this point in time)
            Bucket[] bucketArray = this.buckets.GetArray();

            // we have bucket data so we'll return an array of values for all buckets
            long[] values = new long[bucketArray.Length];
            int i = 0;
            foreach (Bucket bucket in bucketArray)
            {
                if (type.IsCounter())
                {
                    values[i++] = bucket.GetAdder(type).Sum();
                }
                else if (type.IsMaxUpdater())
                {
                    values[i++] = bucket.GetMaxUpdater(type).Max();
                }
            }

            return values;
        }
Ejemplo n.º 35
0
 /// <summary>
 /// Get the max value of values in all buckets for the given <see cref="HystrixRollingNumberEvent"/> type.
 /// The <see cref="HystrixRollingNumberEvent"/> must be a "MaxUpdater" type (HystrixRollingNumberEvent.IsMaxUpdater() == true).
 /// </summary>
 /// <param name="type">HystrixRollingNumberEvent defining which "MaxUpdater" to retrieve values from</param>
 /// <returns>Max value for given <see cref="HystrixRollingNumberEvent"/> type during rolling window</returns>
 public long GetRollingMaxValue(HystrixRollingNumberEvent type)
 {
     long[] values = this.GetValues(type);
     if (values.Length == 0)
     {
         return 0;
     }
     else
     {
         Array.Sort(values);
         return values[values.Length - 1];
     }
 }
Ejemplo n.º 36
0
 /// <summary>
 /// Gets the cumulative value for the specified <see cref="HystrixRollingNumberEvent"/>.
 /// (Returns <see cref="LongAdder.Sum()"/> for Counter types and <see cref="LongMaxUpdater.Max()"/> for MaxUpdater types.)
 /// </summary>
 /// <param name="type">The specified event.</param>
 /// <returns>The cumulative value for the specified event.</returns>
 public long Get(HystrixRollingNumberEvent type)
 {
     if (type.IsCounter())
     {
         return this.adderForCounterType[(int)type].Sum();
     }
     else if (type.IsMaxUpdater())
     {
         return this.updaterForCounterType[(int)type].Max();
     }
     else
     {
         throw new ArgumentException(string.Format("Unknown type of event: {0}", type), "type");
     }
 }
Ejemplo n.º 37
0
 /// <summary>
 /// Get the cumulative sum of all buckets ever since the application started without rolling for the given
 /// <see cref="HystrixRollingNumberEvent"/> type. See <see cref="GetRollingSum(HystrixRollingNumberEvent)"/> for the rolling sum.
 /// </summary>
 /// <param name="type">Must be a "Counter" type (HystrixRollingNumberEvent.IsCounter() == true).</param>
 /// <returns>Cumulative sum of all increments and adds for the given <see cref="HystrixRollingNumberEvent"/> counter type.</returns>
 public long GetCumulativeSum(HystrixRollingNumberEvent type)
 {
     // This isn't 100% atomic since multiple threads can be affecting latestBucket & cumulativeSum independently
     // but that's okay since the count is always a moving target and we're accepting a "point in time" best attempt
     // we are however putting 'GetValueOfLatestBucket' first since it can have side-affects on cumulativeSum whereas the inverse is not true
     return this.GetValueOfLatestBucket(type) + this.cumulativeSum.Get(type);
 }
Ejemplo n.º 38
0
 /// <summary>
 /// Add to the counter in the current bucket for the given <see cref="HystrixRollingNumberEvent"/> type.
 /// </summary>
 /// <param name="type">Defining which counter to add to, must be a "Counter" type (HystrixRollingNumberEvent.IsCounter() == true).</param>
 /// <param name="value">Value to be added to the current bucket.</param>
 public void Add(HystrixRollingNumberEvent type, long value)
 {
     this.GetCurrentBucket().GetAdder(type).Add(value);
 }
Ejemplo n.º 39
0
            /// <summary>
            /// Gets the <see cref="LongMaxUpdater"/> instance for the specified event.
            /// </summary>
            /// <param name="type">The specified event.</param>
            /// <returns>The <see cref="LongMaxUpdater"/> instance for the specified event.</returns>
            public LongMaxUpdater GetMaxUpdater(HystrixRollingNumberEvent type)
            {
                if (!type.IsMaxUpdater())
                {
                    throw new ArgumentException(string.Format("Type is not a MaxUpdater: {0}", type), "type");
                }

                return this.updaterForCounterType[(int)type];
            }
Ejemplo n.º 40
0
 /// <summary>
 /// Increment the counter in the current bucket by one for the given <see cref="HystrixRollingNumberEvent"/> type.
 /// </summary>
 /// <param name="type">Defining which counter to increment, must be a "Counter" type (HystrixRollingNumberEvent.IsCounter() == true).</param>
 public void Increment(HystrixRollingNumberEvent type)
 {
     this.GetCurrentBucket().GetAdder(type).Increment();
 }
Ejemplo n.º 41
0
 /// <summary>
 /// Update a value and retain the max value.
 /// </summary>
 /// <param name="type">Defining which counter to update, must be a "MaxUpdater" type (HystrixRollingNumberEvent.IsMaxUpdater() == true).</param>
 /// <param name="value">Value to be updated to the current bucket</param>
 public void UpdateRollingMax(HystrixRollingNumberEvent type, long value)
 {
     this.GetCurrentBucket().GetMaxUpdater(type).Update(value);
 }