private static IEndPointSource ResolveEndPointSource(IServiceProvider provider)
        {
            var config = provider.GetRequiredService <StatsDConfiguration>();

            return(EndPointFactory.MakeEndPointSource(
                       config.Host,
                       config.Port,
                       config.DnsLookupInterval));
        }
        public void AMetricCanBeSentWithoutAnExceptionBeingThrown()
        {
            // Arrange
            var endPointSource = EndPointFactory.MakeEndPointSource(
                UdpListeners.EndpointA,
                null);

            using var target = new SocketTransport(endPointSource, SocketProtocol.Udp);

            // Act and Assert
            target.Send("mycustommetric");
        }
        public void MultipleMetricsCanBeSentWithoutAnExceptionBeingThrownParallel()
        {
            // Arrange
            var endPointSource = EndPointFactory.MakeEndPointSource(
                UdpListeners.EndpointA,
                null);

            using var target = new SocketTransport(endPointSource, SocketProtocol.Udp);

            Parallel.For(0, 10_000, _ =>
            {
                // Act and Assert
                target.Send("mycustommetric:1|c");
            });
        }
        public void MultipleMetricsCanBeSentWithoutAnExceptionBeingThrownSerial()
        {
            // Arrange
            var endPointSource = EndPointFactory.MakeEndPointSource(
                UdpListeners.EndpointA,
                null);

            using (var target = new SocketTransport(endPointSource, SocketProtocol.Udp))
            {
                for (int i = 0; i < 10_000; i++)
                {
                    // Act and Assert
                    target.Send("mycustommetric:1|c");
                }
            }
        }
        public static void EndpointSwitchShouldNotCauseExceptionsParallel()
        {
            // Arrange
            var endPointSource1 = EndPointFactory.MakeEndPointSource(
                UdpListeners.EndpointA,
                null);

            var endPointSource2 = EndPointFactory.MakeEndPointSource(
                UdpListeners.EndpointB,
                null);

            using var target = new SocketTransport(new MillisecondSwitcher(endPointSource2, endPointSource1), SocketProtocol.Udp);

            Parallel.For(0, 10_000, _ =>
            {
                // Act and Assert
                target.Send("mycustommetric");
            });
        }
        public static void EndpointSwitchShouldNotCauseExceptionsSequential()
        {
            // Arrange
            var endPointSource1 = EndPointFactory.MakeEndPointSource(
                UdpListeners.EndpointA,
                null);

            var endPointSource2 = EndPointFactory.MakeEndPointSource(
                UdpListeners.EndpointB,
                null);

            using var target = new SocketTransport(new MillisecondSwitcher(endPointSource2, endPointSource1), SocketProtocol.Udp);

            for (int i = 0; i < 10_000; i++)
            {
                // Act and Assert
                target.Send("mycustommetric:1|c");
            }
        }
示例#7
0
        public void Setup()
        {
            var config = new StatsDConfiguration
            {
                // if you want to verify that stats are received,
                // you will need the IP of suitable local test stats server
                Host   = "127.0.0.1",
                Prefix = "testmetric"
            };

            var endpointSource = EndPointFactory.MakeEndPointSource(
                config.Host, config.Port, config.DnsLookupInterval);

            _ipTransport = new SocketTransport(endpointSource, SocketProtocol.IP);
            _ipSender    = new BufferBasedStatsDPublisher(config, _ipTransport);
            _ipSender.Increment("startup.i");

            _udpTransport = new SocketTransport(endpointSource, SocketProtocol.Udp);
            _udpSender    = new BufferBasedStatsDPublisher(config, _udpTransport);
            _udpSender.Increment("startup.u");
        }
        public void Setup()
        {
            var config = new StatsDConfiguration
            {
                Host = "127.0.0.1",
            };

            var endpointSource1 = EndPointFactory.MakeEndPointSource(
                config.Host,
                config.Port,
                config.DnsLookupInterval);

            var endpointSource2 = EndPointFactory.MakeEndPointSource(
                config.Host,
                config.Port + 1,
                config.DnsLookupInterval);

            var switcher = new MillisecondSwitcher(endpointSource1, endpointSource2);

            _transport         = new SocketTransport(endpointSource1, SocketProtocol.Udp);
            _transportSwitched = new SocketTransport(switcher, SocketProtocol.Udp);
        }
示例#9
0
        /// <summary>
        /// Initializes a new instance of the <see cref="StatsDPublisher"/> class using the default transport.
        /// </summary>
        /// <param name="configuration">The StatsD configuration to use.</param>
        /// <exception cref="ArgumentNullException">
        /// <paramref name="configuration"/> is <see langword="null"/>.
        /// </exception>
        /// <exception cref="ArgumentException">
        /// <paramref name="configuration"/> is invalid, such as an invalid hostname or IP address.
        /// </exception>
        public StatsDPublisher(StatsDConfiguration configuration)
        {
            if (configuration == null)
            {
                throw new ArgumentNullException(nameof(configuration));
            }

            if (string.IsNullOrWhiteSpace(configuration.Host))
            {
                throw new ArgumentException("No hostname or IP address is set.", nameof(configuration));
            }

            var endpointSource = EndPointFactory.MakeEndPointSource(
                configuration.Host, configuration.Port, configuration.DnsLookupInterval);

            var transport = new SocketTransport(endpointSource, configuration.SocketProtocol);

            _transport        = transport;
            _disposeTransport = true;

            _inner = new BufferBasedStatsDPublisher(configuration, transport);
        }