예제 #1
0
        protected override async Task RunAsync(CancellationToken cancellationToken)
        {
            if (this.healthDataService == null)
            {
                // compose the HealthDataService instance with all the dependencies.
                var config           = new ServiceConfiguration(this.serviceContext.CodePackageActivationContext, TraceWriter);
                var filterRepository = new EntityFilterRepository(config);

                var healthClient = new FabricHealthClientWrapper(
                    TraceWriter,
                    this.serviceContext.ServiceTypeName,
                    this.serviceContext.PartitionId,
                    this.serviceContext.ReplicaId);

                var eventWriter    = new MonitoringEventWriter();
                var metricsEmitter = new MetricsEmitter(config, TraceWriter);
                var consumer       = new IfxHealthDataConsumer(eventWriter, metricsEmitter);
                var producer       = new HealthDataProducer(healthClient, consumer, TraceWriter, config, filterRepository);
                this.healthDataService = new HealthDataService(producer, TraceWriter, config, filterRepository);

                this.TraceInfo("Service.RunAsync: Composed new HealthDataService instance");
            }

            this.TraceInfo("Service.RunAsync: Invoking HealthDataService.RunAsync");
            await this.healthDataService.RunAsync(cancellationToken).ConfigureAwait(false);
        }
예제 #2
0
        public void HealthDataService_HandlesExceptions_ThrownBy_GetHealthAsync()
        {
            var tokenSource       = new CancellationTokenSource();
            var cancellationToken = tokenSource.Token;
            var traceWriterMock   = TraceWriterMock.Create_Verifible();

            var configData = new ServiceConfigurationData();

            var fabricClientMock = new FabricClientMock(cancellationToken, traceWriterMock);

            fabricClientMock.Mock
            .Setup(mock => mock.DoGetHealthAsync <FabricHealth.ClusterHealth>(
                       It.IsAny <Func <Task <FabricHealth.ClusterHealth> > >()))
            .Throws <TimeoutException>();

            var eventWriterMock = new Mock <MonitoringEventWriter>(MockBehavior.Strict);

            var metricsEmitterMock = new Mock <MetricsEmitter>(MockBehavior.Strict, configData, traceWriterMock.Object);

            var filterRepo = new EntityFilterRepository(configData);
            var consumer   = new IfxHealthDataConsumer(eventWriterMock.Object, metricsEmitterMock.Object);
            var producer   = new HealthDataProducer(fabricClientMock.Mock.Object, consumer, traceWriterMock.Object, configData, filterRepo);

            Mock <HealthDataService> healthServiceMock = new Mock <HealthDataService>(producer, traceWriterMock.Object, configData, filterRepo)
            {
                CallBase = true
            };

            healthServiceMock.Cancel_AfterFirstReadPass(tokenSource, cancellationToken);

            healthServiceMock.Object.RunAsync(cancellationToken).Wait(timeout: TimeSpan.FromMilliseconds(300));
        }
예제 #3
0
        private void ProcessAsync <TEntityHealth>(
            Func <FabricHealthClientWrapper, HealthDataConsumer,
                  TraceWriterWrapper, ServiceConfigurationData,
                  EntityFilterRepository, IEntity> getEntity)
            where TEntityHealth : FabricHealth.EntityHealth
        {
            var tokenSource       = new CancellationTokenSource();
            var cancellationToken = tokenSource.Token;
            var traceWriterMock   = TraceWriterMock.Create_Verifible();

            var configData = new ServiceConfigurationData();

            var fabricClientMock = new Mock <FabricHealthClientWrapper>(
                traceWriterMock.Object,
                "FabricMonitoringServiceType",
                Guid.Empty,
                1)
            {
                CallBase = true
            };

            fabricClientMock
            .Setup(mock => mock.DoGetHealthAsync <TEntityHealth>(
                       It.IsAny <Func <Task <TEntityHealth> > >()))
            .Throws <TimeoutException>();

            var eventWriterMock = new Mock <MonitoringEventWriter>(MockBehavior.Strict);

            var metricsEmitterMock = new Mock <MetricsEmitter>(MockBehavior.Strict, configData, traceWriterMock.Object);

            var filterRepo = new EntityFilterRepository(configData);
            var consumer   = new IfxHealthDataConsumer(eventWriterMock.Object, metricsEmitterMock.Object);
            var producer   = new HealthDataProducer(fabricClientMock.Object, consumer, traceWriterMock.Object, configData, filterRepo);

            IEntity entity = getEntity(fabricClientMock.Object, consumer, traceWriterMock.Object, configData, filterRepo);
            var     result = entity.ProcessAsync(cancellationToken).GetAwaiter().GetResult();

            Assert.IsNotNull(result);
            Assert.AreEqual(0, result.Count());
        }
예제 #4
0
        public void HealthDataService_InHealthyCluster_LogsHealthToEventSource_AndEmitsMetrics()
        {
            var tokenSource       = new CancellationTokenSource();
            var cancellationToken = tokenSource.Token;
            var traceWriterMock   = TraceWriterMock.Create_TraceWriterMock_ThrowsOnWarningOrError();

            var clusterName = "unit-test-cluster";
            var configData  = new ServiceConfigurationData();

            var clusterManagerServicePartitionId = new Guid("00000000-0000-0000-0000-000000000001");
            var infraServicePartitionId          = new Guid("00000000-0000-0000-0000-000000000002");
            var infraServicePartitionId2         = new Guid("00000000-0000-0000-0000-000000000003");
            var monsvcPartitionId   = new Guid("00000000-0000-0000-0000-000000000004");
            var mdsAgentPartitionId = new Guid("00000000-0000-0000-0000-000000000005");

            // setup the cluster health data
            var clusterNode = new TreeNode(new ClusterHealth(FabricHealth.HealthState.Ok))
            {
                new TreeNode(new ApplicationHealth(new Uri("fabric:/System"), FabricHealth.HealthState.Ok))
                {
                    new TreeNode(new ServiceHealth(
                                     new Uri("fabric:/System/ClusterManagerService"),
                                     FabricHealth.HealthState.Ok,
                                     this.GetMockServiceHealthEvents("CMSvc"),
                                     new List <FabricHealth.HealthEvaluation>()))
                    {
                        new TreeNode(new PartitionHealth(clusterManagerServicePartitionId, FabricHealth.HealthState.Ok))
                        {
                            new TreeNode(new ReplicaHealth(clusterManagerServicePartitionId, 1, FabricHealth.HealthState.Ok)),
                            new TreeNode(new ReplicaHealth(clusterManagerServicePartitionId, 2, FabricHealth.HealthState.Ok))
                        }
                    },
                    new TreeNode(new ServiceHealth(
                                     new Uri("fabric:/System/InfrastructureService"),
                                     FabricHealth.HealthState.Ok,
                                     this.GetMockServiceHealthEvents("InfraSvc"),
                                     new List <FabricHealth.HealthEvaluation>()))
                    {
                        new TreeNode(new PartitionHealth(infraServicePartitionId, FabricHealth.HealthState.Ok))
                        {
                            new TreeNode(new ReplicaHealth(infraServicePartitionId, 1, FabricHealth.HealthState.Ok)),
                            new TreeNode(new ReplicaHealth(infraServicePartitionId, 2, FabricHealth.HealthState.Ok))
                        },
                        new TreeNode(new PartitionHealth(infraServicePartitionId2, FabricHealth.HealthState.Ok))
                        {
                            new TreeNode(new ReplicaHealth(infraServicePartitionId2, 3, FabricHealth.HealthState.Ok)),
                            new TreeNode(new ReplicaHealth(infraServicePartitionId2, 4, FabricHealth.HealthState.Ok))
                        }
                    },
                },
                new TreeNode(new ApplicationHealth(new Uri("fabric:/Monitoring"), FabricHealth.HealthState.Ok))
                {
                    new TreeNode(new ServiceHealth(new Uri("fabric:/Monitoring/MonitoringService"), FabricHealth.HealthState.Ok))
                    {
                        new TreeNode(new PartitionHealth(monsvcPartitionId, FabricHealth.HealthState.Ok))
                        {
                            new TreeNode(new ReplicaHealth(monsvcPartitionId, 5, FabricHealth.HealthState.Ok)),
                            new TreeNode(new ReplicaHealth(monsvcPartitionId, 8, FabricHealth.HealthState.Ok)),
                        }
                    },
                    new TreeNode(new ServiceHealth(new Uri("fabric:/Monitoring/MonitoringAgentService"), FabricHealth.HealthState.Ok))
                    {
                        new TreeNode(new PartitionHealth(mdsAgentPartitionId, FabricHealth.HealthState.Ok))
                        {
                            new TreeNode(new ReplicaHealth(mdsAgentPartitionId, 1, FabricHealth.HealthState.Ok)),
                            new TreeNode(new ReplicaHealth(mdsAgentPartitionId, 9, FabricHealth.HealthState.Ok)),
                        }
                    },
                },
                new TreeNode(new NodeHealth("_Node_0", FabricHealth.HealthState.Ok)),
                new TreeNode(new NodeHealth("_Node_1", FabricHealth.HealthState.Ok)),
                new TreeNode(new NodeHealth("_Node_2", FabricHealth.HealthState.Ok)),
                new TreeNode(new NodeHealth("_Node_3", FabricHealth.HealthState.Ok)),
                new TreeNode(new NodeHealth("_Node_4", FabricHealth.HealthState.Ok)),
            };

            var fabricClientMock = new FabricClientMock(cancellationToken, traceWriterMock);

            fabricClientMock.Setup(clusterName, clusterNode);

            var eventWriterMock = new EventWriterMock();

            eventWriterMock.Setup_Assertions(clusterName, clusterNode);

            var metricsEmitterMock = new MetricsEmitterMock(traceWriterMock, configData);

            metricsEmitterMock.Setup(clusterName, clusterNode);

            var filterRepo = new EntityFilterRepository(configData);
            var consumer   = new IfxHealthDataConsumer(eventWriterMock.Mock.Object, metricsEmitterMock.Mock.Object);
            var producer   = new HealthDataProducer(fabricClientMock.Mock.Object, consumer, traceWriterMock.Object, configData, filterRepo);

            Mock <HealthDataService> healthServiceMock = new Mock <HealthDataService>(producer, traceWriterMock.Object, configData, filterRepo)
            {
                CallBase = true
            };

            healthServiceMock.Cancel_AfterFirstReadPass(tokenSource, cancellationToken);

            healthServiceMock.Object.RunAsync(cancellationToken).Wait(timeout: TimeSpan.FromMilliseconds(300));

            eventWriterMock.Verify_CallCount();
            metricsEmitterMock.Verify_CallCount();
        }