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(); }
public void Constructor_SetsupStream() { var stream = HystrixDashboardStream.GetInstance(); var controller = new HystrixMetricsStreamController(stream); Assert.NotNull(controller.SampleStream); }
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); }
public static void AddHystrixMetricsStream(this IServiceCollection services, IConfiguration config) { if (services == null) { throw new ArgumentNullException(nameof(services)); } services.AddSingleton <HystrixDashboardStream>(HystrixDashboardStream.GetInstance()); }
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>(); }
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(); }
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(); }
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()) { }
public HystrixDashboardStreamTest(ITestOutputHelper output) : base() { stream = HystrixDashboardStream.GetNonSingletonInstanceOnlyUsedInUnitTests(10); this.output = output; }
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>(); }
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(); }