public void HealthEventsFilter_ReportsFor_None_ReportHealthEvents_IsSetTo_Never() { var configData = new ServiceConfigurationData(); configData.ReportHealthEvents = "Never"; configData.ApplicationsThatReportHealthEvents = "fabric:/System,fabric:/Monitoring"; var filterRepo = new EntityFilterRepository(configData); Assert.IsFalse(filterRepo.HealthEventsFilter.IsEntityEnabled("fabric:/System")); Assert.IsFalse(filterRepo.HealthEventsFilter.IsEntityEnabled("fabric:/Monitoring")); Assert.IsFalse(filterRepo.HealthEventsFilter.IsEntityEnabled("fabric:/TestApp")); Assert.IsFalse(filterRepo.HealthEventsFilter.IsEntityEnabled(string.Empty)); Assert.IsFalse(filterRepo.HealthEventsFilter.IsEntityEnabled(null)); Assert.IsFalse(filterRepo.HealthEventsFilter.IsEntityEnabled("System")); Assert.IsFalse(filterRepo.HealthEventsFilter.IsEntityEnabled("All")); configData.ApplicationsThatReportHealthEvents = "All"; var filterRepo2 = new EntityFilterRepository(configData); Assert.IsFalse(filterRepo2.HealthEventsFilter.IsEntityEnabled("fabric:/System")); Assert.IsFalse(filterRepo2.HealthEventsFilter.IsEntityEnabled("fabric:/Monitoring")); Assert.IsFalse(filterRepo2.HealthEventsFilter.IsEntityEnabled("fabric:/TestApp")); Assert.IsFalse(filterRepo2.HealthEventsFilter.IsEntityEnabled(string.Empty)); Assert.IsFalse(filterRepo2.HealthEventsFilter.IsEntityEnabled(null)); Assert.IsFalse(filterRepo2.HealthEventsFilter.IsEntityEnabled("System")); Assert.IsFalse(filterRepo2.HealthEventsFilter.IsEntityEnabled("All")); }
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)); }
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); }
internal ClusterEntity( FabricHealthClientWrapper healthClient, HealthDataConsumer consumer, TraceWriterWrapper traceWriter, IServiceConfiguration config, EntityFilterRepository filterRepository) : base(healthClient, consumer, traceWriter, config, filterRepository) { this.ClusterName = Guard.IsNotNullOrEmpty(this.Config.ClusterName, nameof(this.Config.ClusterName)); }
internal HealthDataService( HealthDataProducer producer, TraceWriterWrapper traceWriter, IServiceConfiguration config, EntityFilterRepository filterRepository) { this.Producer = Guard.IsNotNull(producer, nameof(producer)); this.Trace = Guard.IsNotNull(traceWriter, nameof(traceWriter)); this.Config = Guard.IsNotNull(config, nameof(config)); this.FilterRepository = Guard.IsNotNull(filterRepository, nameof(filterRepository)); }
public void ServiceFilter_ReportsFor_AllHealthStates_When_ReportServiceHealth_IsSetTo_Always() { var configData = new ServiceConfigurationData(); configData.ReportServiceHealth = "Always"; var filterRepo = new EntityFilterRepository(configData); Assert.IsTrue(filterRepo.ServiceHealthFilter.IsEntityEnabled(HealthState.Ok)); Assert.IsTrue(filterRepo.ServiceHealthFilter.IsEntityEnabled(HealthState.Error)); Assert.IsTrue(filterRepo.ServiceHealthFilter.IsEntityEnabled(HealthState.Warning)); }
public void PartitionFilter_ReportsFor_WarningOrError_HealthStates_When_ReportPartitionHealth_IsSetTo_OnWarningOrError() { var configData = new ServiceConfigurationData(); configData.ReportPartitionHealth = "OnWarningOrError"; var filterRepo = new EntityFilterRepository(configData); Assert.IsFalse(filterRepo.PartitionHealthFilter.IsEntityEnabled(HealthState.Ok)); Assert.IsTrue(filterRepo.PartitionHealthFilter.IsEntityEnabled(HealthState.Error)); Assert.IsTrue(filterRepo.PartitionHealthFilter.IsEntityEnabled(HealthState.Warning)); }
public void HealthEventsFilter_ReportsFor_None_When_ReportHealthEvents_IsSetTo_Never() { var configData = new ServiceConfigurationData(); configData.ReportHealthEvents = "Never"; var filterRepo = new EntityFilterRepository(configData); Assert.IsFalse(filterRepo.HealthEventsFilter.IsEntityEnabled(HealthState.Ok)); Assert.IsFalse(filterRepo.HealthEventsFilter.IsEntityEnabled(HealthState.Error)); Assert.IsFalse(filterRepo.HealthEventsFilter.IsEntityEnabled(HealthState.Warning)); }
public void ReplicaFilter_Never_Reports_HealthStates_When_ReportReplicaHealth_IsSetTo_Never() { var configData = new ServiceConfigurationData(); configData.ReportReplicaHealth = "Never"; var filterRepo = new EntityFilterRepository(configData); Assert.IsFalse(filterRepo.ReplicaHealthFilter.IsEntityEnabled(HealthState.Ok)); Assert.IsFalse(filterRepo.ReplicaHealthFilter.IsEntityEnabled(HealthState.Error)); Assert.IsFalse(filterRepo.ReplicaHealthFilter.IsEntityEnabled(HealthState.Warning)); }
internal ApplicationEntity( FabricHealthClientWrapper healthClient, HealthDataConsumer consumer, string clusterName, Uri applicationUri, TraceWriterWrapper traceWriter, IServiceConfiguration config, EntityFilterRepository filterRepository) : base(healthClient, consumer, traceWriter, config, filterRepository) { this.ClusterName = Guard.IsNotNullOrEmpty(clusterName, nameof(clusterName)); this.applicationUri = Guard.IsNotNull(applicationUri, nameof(applicationUri)); }
protected Entity( FabricHealthClientWrapper healthClient, HealthDataConsumer consumer, TraceWriterWrapper traceWriter, IServiceConfiguration config, EntityFilterRepository filters) { this.HealthClient = Guard.IsNotNull(healthClient, nameof(healthClient)); this.Consumer = Guard.IsNotNull(consumer, nameof(consumer)); this.TraceWriter = Guard.IsNotNull(traceWriter, nameof(traceWriter)); this.Config = Guard.IsNotNull(config, nameof(config)); this.Filters = Guard.IsNotNull(filters, nameof(filters)); }
internal HealthDataProducer( FabricHealthClientWrapper healthClient, HealthDataConsumer consumer, TraceWriterWrapper traceWriter, IServiceConfiguration config, EntityFilterRepository filterRepository) { this.healthClient = Guard.IsNotNull(healthClient, nameof(healthClient)); this.consumer = Guard.IsNotNull(consumer, nameof(consumer)); this.traceWriter = Guard.IsNotNull(traceWriter, nameof(traceWriter)); this.config = Guard.IsNotNull(config, nameof(config)); this.filterRepository = Guard.IsNotNull(filterRepository, nameof(filterRepository)); this.stopwatch = new Stopwatch(); this.stack = new Stack <IEntity>(); }
public void HealthEventsFilter_Throws_ForInvalidValueOf_ReportHealthEvents() { try { var configData = new ServiceConfigurationData(); configData.ReportHealthEvents = "OnError"; var filterRepo = new EntityFilterRepository(configData); } catch (ConfigurationErrorsException) { return; } Assert.Fail("Invalid value for ReportHealthEvents. Expected ConfigurationErrorsException was not thrown."); }
public void PartitionFilter_MustBe_SetTo_Never_When_ServiceFilter_IsSetTo_Never() { try { var configData = new ServiceConfigurationData(); configData.ReportServiceHealth = "Never"; configData.ReportPartitionHealth = "Always"; var filterRepo = new EntityFilterRepository(configData); } catch (ConfigurationErrorsException) { return; } Assert.Fail("Partition filter must be subset of Service filter. Expected ConfigurationErrorsException was not thrown."); }
public void HealthEventsFilter_ReportsFor_NoneButSystemApp_WhenWhitelist_IsNull() { var configData = new ServiceConfigurationData(); configData.ReportHealthEvents = "Always"; configData.ApplicationsThatReportHealthEvents = null; var filterRepo = new EntityFilterRepository(configData); Assert.IsTrue(filterRepo.HealthEventsFilter.IsEntityEnabled("fabric:/System")); Assert.IsFalse(filterRepo.HealthEventsFilter.IsEntityEnabled("fabric:/Monitoring")); Assert.IsFalse(filterRepo.HealthEventsFilter.IsEntityEnabled("fabric:/TestApp")); Assert.IsFalse(filterRepo.HealthEventsFilter.IsEntityEnabled(string.Empty)); Assert.IsFalse(filterRepo.HealthEventsFilter.IsEntityEnabled(null)); Assert.IsFalse(filterRepo.HealthEventsFilter.IsEntityEnabled("System")); Assert.IsFalse(filterRepo.HealthEventsFilter.IsEntityEnabled("All")); }
public void ReplicaFilter_ReportsFor_WhitelistedApps() { var configData = new ServiceConfigurationData(); configData.ReportReplicaHealth = "Always"; configData.ApplicationsThatReportReplicaHealth = "fabric:/System,fabric:/Monitoring"; var filterRepo = new EntityFilterRepository(configData); Assert.IsTrue(filterRepo.ReplicaHealthFilter.IsEntityEnabled("fabric:/System")); Assert.IsTrue(filterRepo.ReplicaHealthFilter.IsEntityEnabled("fabric:/Monitoring")); Assert.IsFalse(filterRepo.ReplicaHealthFilter.IsEntityEnabled("fabric:/TestApp")); Assert.IsFalse(filterRepo.ReplicaHealthFilter.IsEntityEnabled(string.Empty)); Assert.IsFalse(filterRepo.ReplicaHealthFilter.IsEntityEnabled(null)); Assert.IsFalse(filterRepo.ReplicaHealthFilter.IsEntityEnabled("System")); Assert.IsFalse(filterRepo.ReplicaHealthFilter.IsEntityEnabled("All")); }
internal DeployedServicePackageEntity( FabricHealthClientWrapper healthClient, HealthDataConsumer consumer, string clusterName, Uri applicationUri, string serviceManifestName, string nodeName, TraceWriterWrapper traceWriter, IServiceConfiguration config, EntityFilterRepository filterRepository) : base(healthClient, consumer, traceWriter, config, filterRepository) { this.ClusterName = Guard.IsNotNullOrEmpty(clusterName, nameof(clusterName)); this.NodeName = Guard.IsNotNullOrEmpty(nodeName, nameof(nodeName)); this.applicationUri = Guard.IsNotNull(applicationUri, nameof(applicationUri)); this.ServiceManifestName = Guard.IsNotNullOrEmpty(serviceManifestName, nameof(serviceManifestName)); }
public void ServiceFilter_ReportsFor_AllApps_WhenWhitelist_IsSetTo_All() { var configData = new ServiceConfigurationData(); configData.ReportServiceHealth = "Always"; configData.ApplicationsThatReportServiceHealth = "All"; var filterRepo = new EntityFilterRepository(configData); Assert.IsTrue(filterRepo.ServiceHealthFilter.IsEntityEnabled("fabric:/System")); Assert.IsTrue(filterRepo.ServiceHealthFilter.IsEntityEnabled("fabric:/Monitoring")); Assert.IsTrue(filterRepo.ServiceHealthFilter.IsEntityEnabled("fabric:/TestApp")); Assert.IsTrue(filterRepo.ServiceHealthFilter.IsEntityEnabled(string.Empty)); Assert.IsTrue(filterRepo.ServiceHealthFilter.IsEntityEnabled(null)); Assert.IsTrue(filterRepo.ServiceHealthFilter.IsEntityEnabled("System")); Assert.IsTrue(filterRepo.ServiceHealthFilter.IsEntityEnabled("All")); }
internal PartitionEntity( FabricHealthClientWrapper healthClient, HealthDataConsumer consumer, string clusterName, string applicationName, string serviceName, Guid partitionId, TraceWriterWrapper traceWriter, IServiceConfiguration config, EntityFilterRepository filterRepository) : base(healthClient, consumer, traceWriter, config, filterRepository) { this.ClusterName = Guard.IsNotNullOrEmpty(clusterName, nameof(clusterName)); this.ApplicationName = Guard.IsNotNullOrEmpty(applicationName, nameof(applicationName)); this.ServiceName = Guard.IsNotNullOrEmpty(serviceName, nameof(serviceName)); this.PartitionId = partitionId; }
public void PartitionFilter_ReportsFor_NoneButSystemApp_WhenWhitelist_IsEmpty() { var configData = new ServiceConfigurationData(); configData.ReportServiceHealth = "Always"; configData.ReportPartitionHealth = "Always"; configData.ReportReplicaHealth = "Never"; configData.ApplicationsThatReportPartitionHealth = string.Empty; var filterRepo = new EntityFilterRepository(configData); Assert.IsTrue(filterRepo.PartitionHealthFilter.IsEntityEnabled("fabric:/System")); Assert.IsFalse(filterRepo.PartitionHealthFilter.IsEntityEnabled("fabric:/Monitoring")); Assert.IsFalse(filterRepo.PartitionHealthFilter.IsEntityEnabled("fabric:/TestApp")); Assert.IsFalse(filterRepo.PartitionHealthFilter.IsEntityEnabled(string.Empty)); Assert.IsFalse(filterRepo.PartitionHealthFilter.IsEntityEnabled(null)); Assert.IsFalse(filterRepo.PartitionHealthFilter.IsEntityEnabled("System")); Assert.IsFalse(filterRepo.PartitionHealthFilter.IsEntityEnabled("All")); }
public void PartitionFilter_Whitelist_MustBe_SubsetOf_ServiceFilter() { try { var configData = new ServiceConfigurationData(); configData.ReportServiceHealth = "Always"; configData.ReportPartitionHealth = "Always"; configData.ApplicationsThatReportServiceHealth = "fabric:/System,fabric:/Monitoring"; configData.ApplicationsThatReportPartitionHealth = "All"; var filterRepo = new EntityFilterRepository(configData); } catch (ConfigurationErrorsException) { return; } Assert.Fail("Partition filter must be subset of Service filter. Expected ConfigurationErrorsException was not thrown."); }
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()); }
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(); }