public void Setup()
 {
     _udp = MockRepository.GenerateMock<IStatsdUDP>();
     _randomGenerator = MockRepository.GenerateMock<IRandomGenerator>();
     _randomGenerator.Stub(x => x.ShouldSend(Arg<double>.Is.Anything)).Return(true);
     _stopwatch = MockRepository.GenerateMock<IStopWatchFactory>();
 }
 public void Setup()
 {
     _udp             = Substitute.For <IStatsdClient>();
     _stopwatch       = Substitute.For <IStopWatchFactory>();
     _randomGenerator = Substitute.For <IRandomGenerator>();
     _randomGenerator.ShouldSend(0).ReturnsForAnyArgs(true);
 }
Exemple #3
0
        internal Statsd(
            IStatsdUDP udp,
            IRandomGenerator randomGenerator,
            IStopWatchFactory stopwatchFactory,
            string prefix,
            string[] constantTags,
            Telemetry optionalTelemetry)
        {
            StopwatchFactory = stopwatchFactory;
            Udp                = udp;
            RandomGenerator    = randomGenerator;
            _prefix            = prefix;
            _optionalTelemetry = optionalTelemetry;

            string entityId = Environment.GetEnvironmentVariable(StatsdConfig.DD_ENTITY_ID_ENV_VAR);

            if (string.IsNullOrEmpty(entityId))
            {
                // copy array to prevent changes, coalesce to empty array
                _constantTags = constantTags?.ToArray() ?? EmptyStringArray;
            }
            else
            {
                var entityIdTags = new[] { $"{_entityIdInternalTagKey}:{entityId}" };
                _constantTags = constantTags == null ? entityIdTags : constantTags.Concat(entityIdTags).ToArray();
            }
        }
Exemple #4
0
 public Statsd(IStatsdClient statsdClient, IRandomGenerator randomGenerator, IStopWatchFactory stopwatchFactory, ReadOnlyMemory <char> prefix)
 {
     StopwatchFactory = stopwatchFactory;
     StatsdClient     = statsdClient;
     RandomGenerator  = randomGenerator;
     _prefix          = prefix;
 }
Exemple #5
0
 public void Setup()
 {
     udp = MockRepository.GenerateMock <IStatsdUDP>();
     _randomGenerator = MockRepository.GenerateMock <IRandomGenerator>();
     _randomGenerator.Stub(x => x.ShouldSend(Arg <double> .Is.Anything)).Return(true);
     _stopwatch = MockRepository.GenerateMock <IStopWatchFactory>();
 }
 public Statsd(IStatsdUDP udp, IRandomGenerator randomGenerator, IStopWatchFactory stopwatchFactory, string prefix)
 {
     StopwatchFactory = stopwatchFactory;
     Udp             = udp;
     RandomGenerator = randomGenerator;
     _prefix         = prefix;
 }
Exemple #7
0
 public void Setup()
 {
     _udp             = Mock.Of <IStatsdUDP>();
     _randomGenerator = Mock.Of <IRandomGenerator>();
     Mock.Get(_randomGenerator).Setup(x => x.ShouldSend(It.IsAny <double>())).Returns(true);
     _stopwatch = Mock.Of <IStopWatchFactory>();
 }
Exemple #8
0
 public Statsd(IStatsdUDP udp, IRandomGenerator randomGenerator, IStopWatchFactory stopwatchFactory, string prefix)
 {
     Commands         = new List <string>();
     StopwatchFactory = stopwatchFactory;
     Udp             = udp;
     RandomGenerator = randomGenerator;
     _prefix         = prefix;
 }
Exemple #9
0
 public Statsd(IStatsdClient statsdClient, IRandomGenerator randomGenerator, IStopWatchFactory stopwatchFactory, string prefix)
 {
     Commands         = new List <string>();
     StopwatchFactory = stopwatchFactory;
     StatsdClient     = statsdClient;
     RandomGenerator  = randomGenerator;
     _prefix          = prefix;
 }
 public Statsd(
     IStatsdUDP udp,
     IRandomGenerator randomGenerator,
     IStopWatchFactory stopwatchFactory,
     string prefix,
     string[] constantTags)
     : this(udp, randomGenerator, stopwatchFactory, prefix, constantTags, null)
 {
 }
        internal Statsd(
            IStatsdUDP udp,
            IRandomGenerator randomGenerator,
            IStopWatchFactory stopwatchFactory,
            string prefix,
            string[] constantTags,
            Telemetry optionalTelemetry)
        {
            StopwatchFactory = stopwatchFactory;
            Udp                = udp;
            RandomGenerator    = randomGenerator;
            _prefix            = prefix;
            _optionalTelemetry = optionalTelemetry;

            var environmentTags = new List <string>();

            string entityId = Environment.GetEnvironmentVariable(StatsdConfig.DD_ENTITY_ID_ENV_VAR);

            if (!string.IsNullOrEmpty(entityId))
            {
                environmentTags.Add($"{_entityIdInternalTagKey}:{entityId}");
            }

            string service = Environment.GetEnvironmentVariable(StatsdConfig.ServiceEnvVar);

            if (!string.IsNullOrEmpty(service))
            {
                environmentTags.Add($"{StatsdConfig.ServiceTagKey}:{service}");
            }

            string env = Environment.GetEnvironmentVariable(StatsdConfig.EnvironmentEnvVar);

            if (!string.IsNullOrEmpty(env))
            {
                environmentTags.Add($"{StatsdConfig.EnvironmentTagKey}:{env}");
            }

            string version = Environment.GetEnvironmentVariable(StatsdConfig.VersionEnvVar);

            if (!string.IsNullOrEmpty(version))
            {
                environmentTags.Add($"{StatsdConfig.VersionTagKey}:{version}");
            }

            if (environmentTags.Count == 0)
            {
                // copy array to prevent changes, coalesce to empty array
                _constantTags = constantTags?.ToArray() ?? EmptyStringArray;
            }
            else
            {
                _constantTags = constantTags == null?environmentTags.ToArray() : constantTags.Concat(environmentTags).ToArray();
            }
        }
Exemple #12
0
 internal MetricsSender(
     StatsBufferize statsBufferize,
     IRandomGenerator randomGenerator,
     IStopWatchFactory stopwatchFactory,
     Serializers serializers,
     Telemetry optionalTelemetry,
     bool truncateIfTooLong)
 {
     _stopwatchFactory  = stopwatchFactory;
     _statsBufferize    = statsBufferize;
     _randomGenerator   = randomGenerator;
     _optionalTelemetry = optionalTelemetry;
     _serializers       = serializers;
     _truncateIfTooLong = truncateIfTooLong;
 }
 internal MetricsSender(
     StatsBufferize statsBufferize,
     IRandomGenerator randomGenerator,
     IStopWatchFactory stopwatchFactory,
     Telemetry optionalTelemetry,
     bool truncateIfTooLong,
     int poolMaxAllocation)
 {
     _stopwatchFactory  = stopwatchFactory;
     _statsBufferize    = statsBufferize;
     _randomGenerator   = randomGenerator;
     _optionalTelemetry = optionalTelemetry;
     _truncateIfTooLong = truncateIfTooLong;
     _pool = new Pool <Stats>(pool => new Stats(pool), poolMaxAllocation);
 }
 public Statsd(IStatsdUDP udp, IRandomGenerator randomGenerator, IStopWatchFactory stopwatchFactory)
     : this(udp, randomGenerator, stopwatchFactory, string.Empty)
 {
 }
 public Statsd(IStatsdUDP udp, IRandomGenerator randomGenerator, IStopWatchFactory stopwatchFactory, string prefix)
     : this(udp, randomGenerator, stopwatchFactory, prefix, null)
 {
 }
Exemple #16
0
 public Statsd(IStatsdClient statsdClient, IRandomGenerator randomGenerator, IStopWatchFactory stopwatchFactory)
     : this(statsdClient, randomGenerator, stopwatchFactory, ReadOnlyMemory <char> .Empty)
 {
 }
Exemple #17
0
 public Statsd(IStatsdClient statsdClient, IRandomGenerator randomGenerator, IStopWatchFactory stopwatchFactory)
     : this(statsdClient, randomGenerator, stopwatchFactory, string.Empty)
 {
 }