예제 #1
0
        public void ToJsonList_ReturnsExpected()
        {
            var            stream = HystrixDashboardStream.GetInstance();
            CountdownEvent latch  = new CountdownEvent(1);


            List <string> result       = null;
            var           subscription = stream.Observe()
                                         .SubscribeOn(NewThreadScheduler.Default)
                                         .ObserveOn(NewThreadScheduler.Default)
                                         .Subscribe(
                (data) =>
            {
                result = Serialize.ToJsonList(data, null);
                if (result.Count > 0)
                {
                    latch.SignalEx();
                }
            },
                (e) =>
            {
                latch.SignalEx();
            },
                () =>
            {
                latch.SignalEx();
            });


            MyCommand cmd = new MyCommand();

            cmd.Execute();

            latch.Wait(10000);

            Assert.NotNull(result);
            Assert.True(result.Count > 0);

            var jsonObject = result[0];

            var dict = JsonConvert.DeserializeObject <Dictionary <string, object> >(jsonObject);

            Assert.NotNull(dict);

            Assert.NotNull(dict["origin"]);
            Assert.NotNull(dict["data"]);
            JObject cmdData = (JObject)dict["data"];

            Assert.NotNull(cmdData["type"]);
            var type = cmdData["type"].Value <string>();

            Assert.True("HystrixCommand".Equals(type) || "HystrixThreadPool".Equals(type));
            Assert.NotNull(cmdData["name"]);
            var name = cmdData["name"].Value <string>();;

            Assert.True("MyCommand".Equals(name) || "MyCommandGroup".Equals(name));


            subscription.Dispose();
        }
예제 #2
0
        public void Constructor_SetsupStream()
        {
            var stream     = HystrixDashboardStream.GetInstance();
            var controller = new HystrixMetricsStreamController(stream);

            Assert.NotNull(controller.SampleStream);
        }
예제 #3
0
        public static void RegisterHystrixMetricsStream(this ContainerBuilder container, IConfiguration config)
        {
            if (container == null)
            {
                throw new ArgumentNullException(nameof(container));
            }

            Type rabbitFactory = ConnectorHelpers.FindType(rabbitAssemblies, rabbitTypeNames);

            if (rabbitFactory == null)
            {
                throw new ConnectorException("Unable to find ConnectionFactory, are you missing RabbitMQ assembly");
            }
            container.RegisterOptions();
            container.RegisterInstance(HystrixDashboardStream.GetInstance()).SingleInstance();

            HystrixRabbitServiceInfo        info          = config.GetSingletonServiceInfo <HystrixRabbitServiceInfo>();
            HystrixProviderConnectorOptions hystrixConfig = new HystrixProviderConnectorOptions(config);
            HystrixProviderConnectorFactory factory       = new HystrixProviderConnectorFactory(info, hystrixConfig, rabbitFactory);

            container.Register(c => (HystrixConnectionFactory)factory.Create(null)).SingleInstance();

            container.Configure <HystrixMetricsStreamOptions>(config.GetSection(HYSTRIX_STREAM_PREFIX));

            container.RegisterType <HystrixMetricsStreamPublisher>().SingleInstance();
        }
        public void Constructor_SetsupStream()
        {
            var stream  = HystrixDashboardStream.GetInstance();
            var service = new HystrixEventSourceService(stream);

            Assert.NotNull(service.Stream);
        }
예제 #5
0
        public static void AddHystrixMetricsStream(this IServiceCollection services, IConfiguration config)
        {
            if (services == null)
            {
                throw new ArgumentNullException(nameof(services));
            }

            services.AddSingleton <HystrixDashboardStream>(HystrixDashboardStream.GetInstance());
        }
예제 #6
0
        public static void AddHystrixMetricsStream(this IServiceCollection services, IConfiguration config)
        {
            if (services == null)
            {
                throw new ArgumentNullException(nameof(services));
            }

            services.AddSingleton <HystrixDashboardStream>(HystrixDashboardStream.GetInstance());
            services.AddHystrixConnection(config);
            services.Configure <HystrixMetricsStreamOptions>(config.GetSection(HYSTRIX_STREAM_PREFIX));
            services.AddSingleton <RabbitMetricsStreamPublisher>();
        }
예제 #7
0
        public void Constructor_SetsupStream()
        {
            var stream  = HystrixDashboardStream.GetInstance();
            var options = new OptionsWrapper <HystrixMetricsStreamOptions>()
            {
                Value = new HystrixMetricsStreamOptions()
            };
            var publisher = new HystrixMetricsStreamPublisher(options, stream);

            Assert.NotNull(publisher.SampleSubscription);
            publisher.SampleSubscription.Dispose();
        }
예제 #8
0
        public HystrixMetricsStreamPublisher(HystrixDashboardStream stream, HystrixConnectionFactory factory, ILogger <HystrixMetricsStreamPublisher> logger, IDiscoveryClient discoveryClient = null)
        {
            this.discoveryClient = discoveryClient;
            this.logger          = logger;

            observable = stream.Observe().Map((data) => {
                return(Serialize.ToJsonList(data, this.discoveryClient));
            });

            this.factory = factory.ConnectionFactory as ConnectionFactory;

            Task.Factory.StartNew(() => { StartMetricsPublishing(); });
        }
        public static void RegisterHystrixMetricsStream(this ContainerBuilder container, IConfiguration config)
        {
            if (container == null)
            {
                throw new ArgumentNullException(nameof(container));
            }

            Type rabbitFactory = ConnectorHelpers.FindType(rabbitAssemblies, rabbitTypeNames);

            if (rabbitFactory == null)
            {
                throw new ConnectorException("Unable to find ConnectionFactory, are you missing RabbitMQ assembly");
            }

            container.RegisterInstance(HystrixDashboardStream.GetInstance()).SingleInstance();

            container.RegisterHystrixConnection(config).SingleInstance();

            container.RegisterOption <HystrixMetricsStreamOptions>(config.GetSection(HYSTRIX_STREAM_PREFIX));
            container.RegisterType <RabbitMetricsStreamPublisher>().SingleInstance();
        }
예제 #10
0
        public void TestSubscription()
        {
            var stream  = HystrixDashboardStream.GetInstance();
            var service = new HystrixEventSourceService(stream);

            using var listener = new HystrixEventsListener();
            var token = new CancellationTokenSource().Token;

            service.OnNext(GetTestData());

            var i = 0;

            while (i++ < 100 &&
                   listener.CommandEvents.Count <= 0 &&
                   listener.ThreadPoolEvents.Count <= 0 &&
                   listener.CollapserEvents.Count <= 0)
            {
                Thread.Sleep(1000);
            }

            Assert.True(listener.CommandEvents.Count > 0);
        }
 public HystrixMetricsStreamController(HystrixDashboardStream stream)
     : this(stream.Observe())
 {
 }
예제 #12
0
 public HystrixDashboardStreamTest(ITestOutputHelper output)
     : base()
 {
     stream      = HystrixDashboardStream.GetNonSingletonInstanceOnlyUsedInUnitTests(10);
     this.output = output;
 }
예제 #13
0
 public HystrixEventSourceService(HystrixDashboardStream stream)
 {
     Stream = stream;
 }
 public static void AddHystrixMetricsStream(this IServiceCollection services, IConfiguration config)
 {
     services.AddSingleton <HystrixDashboardStream>(HystrixDashboardStream.GetInstance());
     services.AddHystrixConnection(config);
     services.AddSingleton <HystrixMetricsStreamPublisher>();
 }
예제 #15
0
        public HystrixMetricsStreamPublisher(IOptions <HystrixMetricsStreamOptions> options, HystrixDashboardStream stream, HystrixConnectionFactory factory, ILogger <HystrixMetricsStreamPublisher> logger = null, IDiscoveryClient discoveryClient = null)
        {
            this.discoveryClient = discoveryClient;
            this.logger          = logger;
            this.options         = options.Value;

            observable = stream.Observe().Map((data) => {
                return(Serialize.ToJsonList(data, this.discoveryClient));
            });

            this.factory = factory.ConnectionFactory as ConnectionFactory;
            SslOption sslOption = this.factory.Ssl;

            if (sslOption != null && sslOption.Enabled && !this.options.Validate_Certificates)
            {
                logger?.LogInformation("Hystrix Metrics disabling certificate validation");
                sslOption.AcceptablePolicyErrors = SslPolicyErrors.RemoteCertificateChainErrors |
                                                   SslPolicyErrors.RemoteCertificateNameMismatch | SslPolicyErrors.RemoteCertificateNotAvailable;
            }

            StartMetricsPublishing();
        }
        public RabbitMetricsStreamPublisher(IOptions <HystrixMetricsStreamOptions> options, HystrixDashboardStream stream, HystrixConnectionFactory factory, ILogger <RabbitMetricsStreamPublisher> logger = null, IDiscoveryClient discoveryClient = null)
            : base(options, stream, logger, discoveryClient)
        {
            Factory = factory.ConnectionFactory as ConnectionFactory;
            var sslOption = Factory.Ssl;

            if (sslOption != null && sslOption.Enabled)
            {
                logger?.LogInformation("Hystrix Metrics using TLS");
                sslOption.Version = SslProtocols.Tls12 | SslProtocols.Tls13;
                if (!this.options.Validate_Certificates)
                {
                    logger?.LogInformation("Hystrix Metrics disabling certificate validation");
                    sslOption.AcceptablePolicyErrors = SslPolicyErrors.RemoteCertificateChainErrors |
                                                       SslPolicyErrors.RemoteCertificateNameMismatch | SslPolicyErrors.RemoteCertificateNotAvailable;
                }
            }

            StartMetricsPublishing();
        }