Beispiel #1
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));
        }
Beispiel #2
0
        public void TestIncrementInSingleBucket()
        {
            MockedTime time = new MockedTime();

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

                // Increment
                counter.Increment(HystrixRollingNumberEvent.SUCCESS);
                counter.Increment(HystrixRollingNumberEvent.SUCCESS);
                counter.Increment(HystrixRollingNumberEvent.SUCCESS);
                counter.Increment(HystrixRollingNumberEvent.SUCCESS);
                counter.Increment(HystrixRollingNumberEvent.FAILURE);
                counter.Increment(HystrixRollingNumberEvent.FAILURE);
                counter.Increment(HystrixRollingNumberEvent.TIMEOUT);

                // we should have 1 bucket
                Assert.Equal(1, counter._buckets.Size);

                // the count should be 4
                Assert.Equal(4, counter._buckets.Last.GetAdder(HystrixRollingNumberEvent.SUCCESS).Sum());
                Assert.Equal(2, counter._buckets.Last.GetAdder(HystrixRollingNumberEvent.FAILURE).Sum());
                Assert.Equal(1, counter._buckets.Last.GetAdder(HystrixRollingNumberEvent.TIMEOUT).Sum());
            }
            catch (Exception e)
            {
                output.WriteLine(e.ToString());
                Assert.True(false, "Exception: " + e.Message);
            }
        }
Beispiel #3
0
        public void RollingNumber_EmptyBucketsFillIn()
        {
            MockedTime time = new MockedTime();

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

                // add 1
                counter.Increment(HystrixRollingNumberEvent.Success);

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

                // wait past 3 bucket time periods (the 1st bucket then 2 empty ones)
                time.Increment(counter.BucketSizeInMilliseconds * 3);

                // add another
                counter.Increment(HystrixRollingNumberEvent.Success);

                // we should have 4 (1 + 2 empty + 1 new one) buckets
                Assert.AreEqual(4, counter.Buckets.Size);
            }
            catch (Exception e)
            {
                TestContext.WriteLine(e.ToString());
                Assert.Fail("Exception: " + e.Message);
            }
        }
Beispiel #4
0
        public void RollingNumber_ResetBuckets()
        {
            MockedTime time = new MockedTime();

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

                // we start out with 0 buckets in the queue
                Assert.AreEqual(0, counter.Buckets.Size);

                // add 1
                counter.Increment(HystrixRollingNumberEvent.Success);

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

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

                // add 1
                counter.Increment(HystrixRollingNumberEvent.Success);

                // we should now have a single bucket with no values in it instead of 2 or more buckets
                Assert.AreEqual(1, counter.Buckets.Size);
            }
            catch (Exception e)
            {
                TestContext.WriteLine(e.ToString());
                Assert.Fail("Exception: " + e.Message);
            }
        }
Beispiel #5
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);
            }
        }
Beispiel #6
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));
        }
Beispiel #7
0
        public void RollingNumber_CreatesBuckets()
        {
            MockedTime time = new MockedTime();

            try
            {
                HystrixRollingNumber counter = new HystrixRollingNumber(time, 200, 10);
                // confirm the initial settings
                Assert.AreEqual(200, counter.TimeInMilliseconds);
                Assert.AreEqual(10, counter.NumberOfBuckets);
                Assert.AreEqual(20, counter.BucketSizeInMilliseconds);

                // we start out with 0 buckets in the queue
                Assert.AreEqual(0, counter.Buckets.Size);

                // add a success in each interval which should result in all 10 buckets being created with 1 success in each
                for (int i = 0; i < counter.NumberOfBuckets; i++)
                {
                    counter.Increment(HystrixRollingNumberEvent.Success);
                    time.Increment(counter.BucketSizeInMilliseconds);
                }

                // confirm we have all 10 buckets
                Assert.AreEqual(10, counter.Buckets.Size);

                // add 1 more and we should still only have 10 buckets since that's the max
                counter.Increment(HystrixRollingNumberEvent.Success);
                Assert.AreEqual(10, counter.Buckets.Size);
            }
            catch (Exception e)
            {
                TestContext.WriteLine(e.ToString());
                Assert.Fail("Exception: " + e.Message);
            }
        }
Beispiel #8
0
        public void RollingNumber_IncrementInSingleBucket()
        {
            MockedTime time = new MockedTime();

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

                // increment
                counter.Increment(HystrixRollingNumberEvent.Success);
                counter.Increment(HystrixRollingNumberEvent.Success);
                counter.Increment(HystrixRollingNumberEvent.Success);
                counter.Increment(HystrixRollingNumberEvent.Success);
                counter.Increment(HystrixRollingNumberEvent.Failure);
                counter.Increment(HystrixRollingNumberEvent.Failure);
                counter.Increment(HystrixRollingNumberEvent.Timeout);

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

                // the count should be 4
                Assert.AreEqual(4, counter.Buckets.GetLast().GetAdder(HystrixRollingNumberEvent.Success).Sum());
                Assert.AreEqual(2, counter.Buckets.GetLast().GetAdder(HystrixRollingNumberEvent.Failure).Sum());
                Assert.AreEqual(1, counter.Buckets.GetLast().GetAdder(HystrixRollingNumberEvent.Timeout).Sum());
            }
            catch (Exception e)
            {
                TestContext.WriteLine(e.ToString());
                Assert.Fail("Exception: " + e.Message);
            }
        }
Beispiel #9
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);
            }
        }
Beispiel #10
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);
            }
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="HystrixThreadPoolMetrics"/> class.
 /// </summary>
 /// <param name="threadPoolKey">The key of the parent thread pool.</param>
 /// <param name="threadPool">The <see cref="ThreadPoolExecutor"/> of the parent thread pool.</param>
 /// <param name="properties">The properties of the parent thread pool.</param>
 private HystrixThreadPoolMetrics(HystrixThreadPoolKey threadPoolKey, ThreadPoolExecutor threadPool, IHystrixThreadPoolProperties properties)
 {
     this.threadPoolKey = threadPoolKey;
     this.threadPool    = threadPool;
     this.properties    = properties;
     this.counter       = new HystrixRollingNumber(properties.MetricsRollingStatisticalWindowInMilliseconds, properties.MetricsRollingStatisticalWindowBuckets);
 }
        public void TestEmptyBucketsFillIn()
        {
            var time = new MockedTime();

            try
            {
                var counter = new HystrixRollingNumber(time, 200, 10);

                // add 1
                counter.Increment(HystrixRollingNumberEvent.SUCCESS);

                // we should have 1 bucket
                Assert.Equal(1, counter._buckets.Size);

                // wait past 3 bucket time periods (the 1st bucket then 2 empty ones)
                time.Increment(counter._bucketSizeInMillseconds * 3);

                // add another
                counter.Increment(HystrixRollingNumberEvent.SUCCESS);

                // we should have 4 (1 + 2 empty + 1 new one) buckets
                Assert.Equal(4, counter._buckets.Size);
            }
            catch (Exception e)
            {
                output.WriteLine(e.ToString());
                Assert.True(false, "Exception: " + e.Message);
            }
        }
        public void TestResetBuckets()
        {
            var time = new MockedTime();

            try
            {
                var counter = new HystrixRollingNumber(time, 200, 10);

                // we start out with 0 buckets in the queue
                Assert.Equal(0, counter._buckets.Size);

                // add 1
                counter.Increment(HystrixRollingNumberEvent.SUCCESS);

                // confirm we have 1 bucket
                Assert.Equal(1, counter._buckets.Size);

                // confirm we still have 1 bucket
                Assert.Equal(1, counter._buckets.Size);

                // add 1
                counter.Increment(HystrixRollingNumberEvent.SUCCESS);

                // we should now have a single bucket with no values in it instead of 2 or more buckets
                Assert.Equal(1, counter._buckets.Size);
            }
            catch (Exception e)
            {
                output.WriteLine(e.ToString());
                Assert.True(false, "Exception: " + e.Message);
            }
        }
        public void TestRolling()
        {
            var time    = new MockedTime();
            var type    = HystrixRollingNumberEvent.THREAD_MAX_ACTIVE;
            var counter = new HystrixRollingNumber(time, 20, 2);

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

                Assert.Equal(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);
            }
        }
Beispiel #15
0
        internal HystrixCommandMetrics(string opName, string serviceName, string fullServiceName, string metricPrefix, IHystrixCommandProperties properties)
        {
            this.serviceName     = serviceName;
            this.opName          = opName;
            this.properties      = properties;
            this.fullServiceName = fullServiceName;
            this.counter         = new HystrixRollingNumber(properties.MetricsRollingStatisticalWindowInMilliseconds, properties.MetricsRollingStatisticalWindowBuckets);

            this.successCounter            = new LongAdder();
            this.frameworkErrorCounter     = new LongAdder();
            this.validationErrorCounter    = new LongAdder();
            this.serviceErrorCounter       = new LongAdder();
            this.shortCircuitCounter       = new LongAdder();
            this.threadPoolRejectedCounter = new LongAdder();
            this.timeoutCounter            = new LongAdder();

            int timeWindowInSeconds       = properties.MetricsIntegerBufferTimeWindowInSeconds.Get();
            int bucketTimeWindowInSeconds = properties.MetricsIntegerBufferBucketTimeWindowInSeconds.Get();
            int bucketSizeLimit           = properties.MetricsIntegerBufferBucketSizeLimit.Get();

            this.executionOperationLatencyBuffer = new HystrixIntegerCircularBuffer(timeWindowInSeconds, bucketTimeWindowInSeconds, bucketSizeLimit);
            this.requestLatencyBuffer            = new HystrixIntegerCircularBuffer(timeWindowInSeconds, bucketTimeWindowInSeconds, bucketSizeLimit);

            MetricNameEventDistribution        = metricPrefix + ".event.distribution";
            MetricNameConcurrentExecutionCount = metricPrefix + ".execution.concurrency";
            MetricNameRequestCount             = metricPrefix + ".request.count";
            MetricNameLatency             = metricPrefix + ".request.latency";
            MetricNameLatencyDistribution = metricPrefix + ".request.latency.distribution";
            MetricNameLatencyPercentile   = metricPrefix + ".request.latency.percentile";
        }
        public void TestEmptyMax()
        {
            var time    = new MockedTime();
            var type    = HystrixRollingNumberEvent.THREAD_MAX_ACTIVE;
            var counter = new HystrixRollingNumber(time, 200, 10);

            Assert.Equal(0, counter.GetRollingMaxValue(type));
        }
Beispiel #17
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));
        }
Beispiel #18
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));
        }
Beispiel #19
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));
        }
Beispiel #20
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));
        }
Beispiel #21
0
            public void Returns_Zero_If_No_Values_Have_Been_Added_Yet_For_Specific_Counter()
            {
                var rollingNumber = new HystrixRollingNumber(10000, 10);

                // Act
                long valueOfLatestBucket = rollingNumber.GetValueOfLatestBucket(HystrixRollingNumberEvent.Success);

                Assert.Equal(0L, valueOfLatestBucket);
            }
Beispiel #22
0
            public void NotImplemented()
            {
                var rollingNumber = new HystrixRollingNumber(10000, 10);

                // Act
                long cumulativeSum = rollingNumber.GetCumulativeSum(HystrixRollingNumberEvent.Success);

                Assert.Equal(0L, cumulativeSum);
            }
Beispiel #23
0
            public void NotImplemented()
            {
                var rollingNumber = new HystrixRollingNumber(10000, 10);

                // Act
                long value = rollingNumber.GetRollingSum(HystrixRollingNumberEvent.Success);

                Assert.Equal(0, value);
            }
Beispiel #24
0
            public void Returns_Values_For_All_Buckets()
            {
                var rollingNumber = new HystrixRollingNumber(10000, 10);

                // Act
                long[] values = rollingNumber.GetValues(HystrixRollingNumberEvent.Success);

                Assert.Equal(1, values.Length);
            }
Beispiel #25
0
            public void Returns_Zero_If_No_Values_Have_Been_Recorded()
            {
                var rollingNumber = new HystrixRollingNumber(10000, 10);

                // Act
                long rollingMaxValue = rollingNumber.GetRollingMaxValue(HystrixRollingNumberEvent.Success);

                Assert.Equal(0L, rollingMaxValue);
            }
Beispiel #26
0
            public void Calculates_BucketSizeInMillseconds_From_TimeInMilliseconds_Divided_By_NumberOfBuckets()
            {
                var timeInMilliseconds = 10000;
                var numberOfBuckets    = 10;

                // Act
                var rollingNumber = new HystrixRollingNumber(timeInMilliseconds, numberOfBuckets);

                Assert.Equal(1000, rollingNumber.BucketSizeInMillseconds);
            }
Beispiel #27
0
            public void Returns_Values_For_All_Buckets()
            {
                var dateTimeProvider = new Mock <IDateTimeProvider>();
                var rollingNumber    = new HystrixRollingNumber(dateTimeProvider.Object, 10000, 10);

                // Act
                long[] values = rollingNumber.GetValues(HystrixRollingNumberEvent.Success);

                Assert.Equal(1, values.Length);
            }
Beispiel #28
0
            public void Returns_Zero_If_No_Values_Have_Been_Recorded()
            {
                var dateTimeProvider = new Mock <IDateTimeProvider>();
                var rollingNumber    = new HystrixRollingNumber(dateTimeProvider.Object, 10000, 10);

                // Act
                long rollingMaxValue = rollingNumber.GetRollingMaxValue(HystrixRollingNumberEvent.Success);

                Assert.Equal(0L, rollingMaxValue);
            }
 internal HystrixCommandMetrics(HystrixCommandKey key, HystrixCommandGroupKey commandGroup, IHystrixCommandProperties properties, IHystrixEventNotifier eventNotifier)
 {
     this.key                 = key;
     this.group               = commandGroup;
     this.properties          = properties;
     this.counter             = new HystrixRollingNumber(properties.MetricsRollingStatisticalWindowInMilliseconds, properties.MetricsRollingStatisticalWindowBuckets);
     this.percentileExecution = new HystrixRollingPercentile(properties.MetricsRollingPercentileWindowInMilliseconds, properties.MetricsRollingPercentileWindowBuckets, properties.MetricsRollingPercentileBucketSize, properties.MetricsRollingPercentileEnabled);
     this.percentileTotal     = new HystrixRollingPercentile(properties.MetricsRollingPercentileWindowInMilliseconds, properties.MetricsRollingPercentileWindowBuckets, properties.MetricsRollingPercentileBucketSize, properties.MetricsRollingPercentileEnabled);
     this.eventNotifier       = eventNotifier;
 }
Beispiel #30
0
            public void NotImplemented()
            {
                var dateTimeProvider = new Mock <IDateTimeProvider>();
                var rollingNumber    = new HystrixRollingNumber(dateTimeProvider.Object, 10000, 10);

                // Act
                long value = rollingNumber.GetRollingSum(HystrixRollingNumberEvent.Success);

                Assert.Equal(0, value);
            }