예제 #1
0
        static int Main(string[] args)
        {
            if (args.Length != 2)
            {
                Console.WriteLine("Bad arguments provided.");
                PrintHelp();
                return(1);
            }

            string openApiDocFilePath      = args[0];
            string outputEndpointsFilePath = args[1];

            if (!ValidateArguments(openApiDocFilePath, outputEndpointsFilePath))
            {
                PrintHelp();
                return(1);
            }

            OpenApiDocument openApiDocument = OpenApiDocumentParser.ParseOpenApiDocument(openApiDocFilePath);
            List <Endpoint> endpoints       = EndpointParser.ParseAllEndpoints(openApiDocument);
            string          json            = JsonConvert.SerializeObject(endpoints, Formatting.Indented);

            File.WriteAllText(outputEndpointsFilePath, json);

            return(0);
        }
예제 #2
0
    public void CanUseDefaultPort()
    {
        var success = EndpointParser.TryParse("127.0.0.1", 7051, out var hostPort);

        Assert.True(success);
        Assert.Equal("127.0.0.1", hostPort.Host);
        Assert.Equal(7051, hostPort.Port);
    }
예제 #3
0
    public void CanParseEndpoint(string endpoint, string expectedHost, int expectedPort)
    {
        var success = EndpointParser.TryParse(endpoint, 0, out var hostPort);

        Assert.True(success);
        Assert.Equal(expectedHost, hostPort.Host);
        Assert.Equal(expectedPort, hostPort.Port);
    }
예제 #4
0
        public void DocumentWithTwoPathsEachHavingSingleResponseShouldReturnTwoEndpoints()
        {
            AddTwoTestingPaths();

            List <Endpoint> endpoints = EndpointParser.ParseAllEndpoints(_document);

            Assert.AreEqual(2, endpoints.Count);
        }
예제 #5
0
        private static IEndPointSource ResolveEndPointSource(IServiceProvider provider)
        {
            var config = provider.GetRequiredService <StatsDConfiguration>();

            return(EndpointParser.MakeEndPointSource(
                       config.Host,
                       config.Port,
                       config.DnsLookupInterval));
        }
예제 #6
0
        public void AMetricCanBeSentWithoutAnExceptionBeingThrown()
        {
            // Arrange
            var endPointSource = EndpointParser.MakeEndPointSource(
                UdpListeners.EndpointA,
                null);

            using (var target = new SocketTransport(endPointSource, SocketProtocol.Udp))
            {
                // Act and Assert
                target.Send("mycustommetric");
            }
        }
예제 #7
0
        public void Setup()
        {
            var config = new StatsDConfiguration
            {
                Host = "127.0.0.1",
            };

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

            _pooledTransport   = new PooledUdpTransport(endpointSource);
            _unpooledTransport = new UdpTransport(endpointSource);
        }
        /// <summary>
        /// Registers the TypedRest OpenAPI extension parser.
        /// </summary>
        /// <param name="settings">The settings to register the extension parser in.</param>
        /// <param name="endpointRegistry">A list of all known <see cref="IEndpoint"/> kinds; leave <c>null</c> for default.</param>
        /// <seealso cref="OpenApiDocumentExtensions.GetTypedRest"/>
        public static OpenApiReaderSettings AddTypedRest(this OpenApiReaderSettings settings, EndpointRegistry?endpointRegistry = null)
        {
            var parser = new EndpointParser(endpointRegistry ?? EndpointRegistry.Default);

            settings.ExtensionParsers.Add(OpenApiDocumentExtensions.TypedRestKey, (data, _) =>
            {
                if (!(data is OpenApiObject objData))
                {
                    throw new FormatException($"{OpenApiDocumentExtensions.TypedRestKey} is not an object.");
                }

                var entryEndpoint = new EntryEndpoint();
                entryEndpoint.Parse(objData, parser);
                return(entryEndpoint);
            });
예제 #9
0
        public void MultipleMetricsCanBeSentWithoutAnExceptionBeingThrownParallel()
        {
            // Arrange
            var endPointSource = EndpointParser.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");
                });
            }
        }
예제 #10
0
        public StatsDPublisher(StatsDConfiguration configuration)
        {
            if (configuration == null)
            {
                throw new ArgumentNullException(nameof(configuration));
            }

            if (string.IsNullOrWhiteSpace(configuration.Host))
            {
                throw new ArgumentNullException(nameof(configuration.Host));
            }

            _formatter = new StatsDMessageFormatter(configuration.Culture, configuration.Prefix);

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

            _transport = new UdpTransport(endpointSource);
        }
예제 #11
0
        private static void Main(string[] args)
        {
            var iterations = Enumerable.Range(1, 500000);
            var endpoint   = EndpointParser.MakeEndPointSource("localhost", 3128, null);
            var client     = new UdpTransport(endpoint);
            var formatter  = new StatsDMessageFormatter(CultureInfo.InvariantCulture);
            var watch      = new Stopwatch();

            Console.WriteLine("To start - hit ENTER.");
            Console.ReadLine();
            Console.WriteLine("start");
            watch.Start();

            Parallel.ForEach(iterations, x => client.Send(formatter.Gauge(x, "bucket_sample" + "number-of-messages-to-be-sent")));

            watch.Stop();
            Console.WriteLine("end - " + watch.ElapsedMilliseconds);
            Console.ReadLine();
        }
예제 #12
0
        public static void EndpointSwitchShouldNotCauseExceptionsSequential()
        {
            // Arrange
            var endPointSource1 = EndpointParser.MakeEndPointSource(
                UdpListeners.EndpointA,
                null);

            var endPointSource2 = EndpointParser.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");
                }
            }
        }
예제 #13
0
        public static void EndpointSwitchShouldNotCauseExceptionsParallel()
        {
            // Arrange
            var endPointSource1 = EndpointParser.MakeEndPointSource(
                UdpListeners.EndpointA,
                null);

            var endPointSource2 = EndpointParser.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 void Setup()
        {
            var config = new StatsDConfiguration
            {
                Host = "127.0.0.1",
            };

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

            var endpointSource2 = EndpointParser.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);
        }
예제 #15
0
        public void Setup()
        {
            var config = new StatsDConfiguration
            {
                // if you want verify that stats are recevied,
                // you will need the IP of suitable local test stats server
                Host   = "127.0.0.1",
                Prefix = "testmetric"
            };

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

            var udpTransport = new UdpTransport(endpointSource);
            var ipTransport  = new IpTransport(endpointSource);

            _udpSender = new StatsDPublisher(config, udpTransport);
            _udpSender.Increment("startup.ud");

            _ipSender = new StatsDPublisher(config, ipTransport);
            _udpSender.Increment("startup.ip");
        }
예제 #16
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 = EndpointParser.MakeEndPointSource(
                configuration.Host, configuration.Port, configuration.DnsLookupInterval);

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

            _transport        = transport;
            _disposeTransport = true;

            _inner = new BufferBasedStatsDPublisher(configuration, transport);
        }
        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 = EndpointParser.MakeEndPointSource(
                config.Host,
                config.Port,
                config.DnsLookupInterval);

            _transport = new SocketTransport(endpointSource, SocketProtocol.Udp);

            _adaptedStatsDPublisher = new StatsDPublisher(config);
            _adaptedStatsDPublisher.Increment("startup.ud");

            _udpSender = new BufferBasedStatsDPublisher(config, _transport);
            _udpSender.Increment("startup.ud");
        }
예제 #18
0
        public void DocumentWithoutAnyPathsShouldReturnEmptyList()
        {
            List <Endpoint> endpoints = EndpointParser.ParseAllEndpoints(_document);

            Assert.IsEmpty(endpoints);
        }