ShouldSend() public method

public ShouldSend ( double sampleRate ) : bool
sampleRate double
return bool
Exemplo n.º 1
0
 public void Send <TCommandType, T>(string name, T value, double sampleRate = 1.0, string[] tags = null) where TCommandType : Metric
 {
     if (RandomGenerator.ShouldSend(sampleRate))
     {
         Send(Metric.GetCommand <TCommandType, T>(_prefix, name, value, sampleRate, tags));
     }
 }
Exemplo n.º 2
0
 public void Add <TCommandType>(string name, int value, double sampleRate) where TCommandType : IAllowsInteger, IAllowsSampleRate
 {
     if (RandomGenerator.ShouldSend(sampleRate))
     {
         Commands.Add(GetCommand(name, value.ToString(CultureInfo.InvariantCulture), _commandToUnit[typeof(TCommandType)], sampleRate));
     }
 }
Exemplo n.º 3
0
 public void Add(string name, int value, double sampleRate)
 {
     if (RandomGenerator.ShouldSend(sampleRate))
     {
         _commands.Add(GetCommand(name, value, _commandToUnit[typeof(Counting)], sampleRate));
     }
 }
Exemplo n.º 4
0
 public void Send <TCommandType>(string name, int value, double sampleRate) where TCommandType : ICommandType
 {
     if (RandomGenerator.ShouldSend(sampleRate))
     {
         Send(GetCommand(name, value, _commandToUnit[typeof(TCommandType)], sampleRate));
     }
 }
Exemplo n.º 5
0
 public Task SendAsync <TCommandType, T>(string name, T value, double sampleRate = 1.0, string[] tags = null) where TCommandType : Metric
 {
     if (RandomGenerator.ShouldSend(sampleRate))
     {
         return(SendAsync(Metric.GetCommand <TCommandType, T>(_prefix, name, value, sampleRate, _constantTags, tags)));
     }
     return(Task.FromResult((object)null));
 }
 public void If_sample_rate_is_1_then_always_true()
 {
     RandomGenerator randomGenerator = new RandomGenerator();
     for (int i = 0; i < NumberOfTestsRan; i++)
     {
         Assert.True(randomGenerator.ShouldSend(1));
     }
 }
Exemplo n.º 7
0
 public void Send <TCommandType>(string name, int value, double sampleRate, IDictionary <String, String> dimensions = null) where TCommandType : IAllowsInteger, IAllowsSampleRate
 {
     if (RandomGenerator.ShouldSend(sampleRate))
     {
         Commands = new List <string> {
             GetCommand(name, value.ToString(CultureInfo.InvariantCulture), _commandToUnit[typeof(TCommandType)], sampleRate, dimensions)
         };
         Send();
     }
 }
Exemplo n.º 8
0
        public void Send <TCommandType>(string name, int value, double sampleRate) where TCommandType : IAllowsInteger, IAllowsSampleRate
        {
            if (!RandomGenerator.ShouldSend(sampleRate))
            {
                return;
            }

            var command = GetCommand(name, value.ToString(CultureInfo.InvariantCulture), _commandToUnit[typeof(TCommandType)], sampleRate);

            SendSingle(command);
        }
        public void If_sample_rate_is_0_5_then_have_half_true()
        {
            int numberOfTrues = 0;
            RandomGenerator randomGenerator = new RandomGenerator();
            for (int i = 0; i < NumberOfTestsRan; i++)
            {
                if (randomGenerator.ShouldSend(0.5))
                {
                    numberOfTrues++;
                }
            }

            Assert.That( Math.Round(numberOfTrues/(double)NumberOfTestsRan,1),Is.EqualTo(0.5));
        }
        public void If_sample_rate_is_one_tenth_of_pct_then_have_one_tenth_of_pct()
        {
            int numberOfTrues = 0;
            RandomGenerator randomGenerator = new RandomGenerator();
            const int sampleRate = 1/1000;
            for (int i = 0; i < NumberOfTestsRan; i++)
            {
                if (randomGenerator.ShouldSend(sampleRate))
                {
                    numberOfTrues++;
                }
            }

            Assert.That(Math.Round(numberOfTrues / (double)NumberOfTestsRan, 1), Is.EqualTo(sampleRate));
        }
        public void If_sample_rate_is_one_quarter_then_have_one_quarter_true()
        {
            var numberOfTrues = 0;
            var randomGenerator = new RandomGenerator();
            const int sampleRate = 1/4;

            for (var i = 0; i < NumberOfTestsToRun; i++)
            {
                if (randomGenerator.ShouldSend(sampleRate))
                {
                    numberOfTrues++;
                }
            }

            Assert.That(Math.Round(numberOfTrues / (double)NumberOfTestsToRun, 1), Is.EqualTo(sampleRate));
        }
Exemplo n.º 12
0
        public void Send(Action actionToTime, string statName, double sampleRate = 1)
        {
            var stopwatch = StopwatchFactory.Get();

            try
            {
                stopwatch.Start();
                actionToTime();
            }
            finally
            {
                stopwatch.Stop();
                if (RandomGenerator.ShouldSend(sampleRate))
                {
                    Send <Timing>(statName, stopwatch.ElapsedMilliseconds());
                }
            }
        }
Exemplo n.º 13
0
        public void Add(Action actionToTime, string statName, double sampleRate = 1, IDictionary <String, String> dimensions = null)
        {
            var stopwatch = StopwatchFactory.Get();

            try
            {
                stopwatch.Start();
                actionToTime();
            }
            finally
            {
                stopwatch.Stop();
                if (RandomGenerator.ShouldSend(sampleRate))
                {
                    Add <Timing>(statName, stopwatch.ElapsedMilliseconds(), dimensions);
                }
            }
        }
Exemplo n.º 14
0
        private void HandleTiming(Action actionToTime, string statName, double sampleRate, Action <string, int> actionToStore)
        {
            var stopwatch = StopwatchFactory.Get();

            try
            {
                stopwatch.Start();
                actionToTime();
            }
            finally
            {
                stopwatch.Stop();
                if (RandomGenerator.ShouldSend(sampleRate))
                {
                    actionToStore(statName, stopwatch.ElapsedMilliseconds);
                }
            }
        }