public async Task WorkloadMetricsCalledOnce()
        {
            var args = new ServiceArguments(ServiceStartupMode.CommandLineNonInteractive,
                                            ConsoleOutputMode.Disabled,
                                            SiloClusterMode.PrimaryNode,
                                            DisposablePort.GetPort().Port, initTimeOutSec: 10);
            IWorkloadMetrics workloadMetricsFake = Substitute.For <IWorkloadMetrics>();


            var srvHost =
                new ServiceHostFake <IWorkloadMetrics>(
                    workloadMetricsFake,
                    new HostEnvironment(new TestHostEnvironmentSource()))
            {
                FailServiceStartOnConfigError = false
            };;

            Task.Run(() => srvHost.Run(args));
            await srvHost.WaitForServiceStartedAsync();

            srvHost.Dispose();

            workloadMetricsFake.Received(1).Init();
            workloadMetricsFake.Received().Dispose();
        }
        public void Setup()
        {
            Metric.ShutdownContext("Workload");
            Metric.ShutdownContext("Silo");
            _serviceArguments = new ServiceArguments();
            _dateTimeFake     = new DateTimeFake {
                UtcNow = DateTime.UtcNow
            };

            _kernel = new TestingKernel <ConsoleLog>(k =>
            {
                k.Rebind <IHealthMonitor>().To <HealthMonitor>();
                k.Rebind <ServiceArguments>().ToMethod(c => _serviceArguments);
                k.Rebind <IDateTime>().ToMethod(c => _dateTimeFake);
            });

            _kernel.Get <Ninject.SystemInitializer.SystemInitializer>().Init();
            _config = _kernel.Get <Func <WorkloadMetricsConfig> >()();
            _config.ReadPerformanceCounters = true;
            _config.MinUnhealthyDuration    = MinUnhealthyDuration;

            SetupOrleansQueueLength();

            _workloadMetrics = _kernel.Get <IWorkloadMetrics>();
        }
示例#3
0
        /// <summary>
        /// Used to initialize service dependencies. This method is called before OnInitialize(),
        /// and should include common behavior for a family of services.
        /// When overridden on the family services base, it is recommended to mark it as sealed,
        /// to prevent concrete services from overriding the common behavior.
        /// </summary>
        /// <param name="kernel"></param>
        protected virtual void PreInitialize(IKernel kernel)
        {
            Kernel.Get <SystemInitializer.SystemInitializer>().Init();
            CrashHandler = kernel.Get <Func <Action, CrashHandler> >()(OnCrash);

            IWorkloadMetrics workloadMetrics = kernel.Get <IWorkloadMetrics>();

            workloadMetrics.Init();

            var metricsInitializer = kernel.Get <IMetricsInitializer>();

            metricsInitializer.Init();
        }
示例#4
0
        public async Task WorkloadMetricsCalledOnce()
        {
            IWorkloadMetrics workloadMetricsFake       = Substitute.For <IWorkloadMetrics>();
            ServiceHostFake <IWorkloadMetrics> srvHost = new ServiceHostFake <IWorkloadMetrics>(workloadMetricsFake);

            Task.Run(() => srvHost.Run());

            await srvHost.WaitForHostInitialized();

            await srvHost.StopHost();

            workloadMetricsFake.Received(1).Init();
            workloadMetricsFake.Received().Dispose();
        }
示例#5
0
        protected override void OnStart()
        {
            Kernel = new StandardKernel(new NinjectSettings {
                ActivationCacheDisabled = true
            });

            var env = HostEnvironment.CreateDefaultEnvironment(ServiceName, InfraVersion, Arguments);

            Kernel.Bind <IEnvironment>().ToConstant(env).InSingletonScope();
            Kernel.Bind <CurrentApplicationInfo>().ToConstant(env.ApplicationInfo).InSingletonScope();

            this.PreConfigure(Kernel, Arguments);
            this.Configure(Kernel);

            Kernel.Get <SystemInitializer>().Init();

            CrashHandler = Kernel.Get <ICrashHandler>();
            CrashHandler.Init(OnCrash);

            IWorkloadMetrics workloadMetrics = Kernel.Get <IWorkloadMetrics>();

            workloadMetrics.Init();

            var metricsInitializer = Kernel.Get <IMetricsInitializer>();

            metricsInitializer.Init();

            if (PerSiloGrainType != null)
            {
                Kernel.Get <OrleansConfigurationBuilder>().GetBuilder()
                .ConfigureServices(service => service.AddGrainService(PerSiloGrainType).AddSingleton(typeof(IPerSiloGrain), PerSiloGrainType));
            }

            this.PreInitialize(Kernel);

            this.OnInitilize(Kernel);

            VerifyConfigurationsIfNeeded(Kernel.Get <MicrodotHostingConfig>(), Kernel.Get <ConfigurationVerificator>());

            this.Warmup(Kernel);

            //don't move up the get should be after all the binding are done
            var log = Kernel.Get <ILog>();

            this.requestListener = Kernel.Get <IRequestListener>();
            this.requestListener.Listen();

            log.Info(_ => _("start getting traffic", unencryptedTags: new { siloName = CurrentApplicationInfo.HostName }));
        }