/// <summary> /// Initialize method is called after all configuration properties have been loaded from the configuration. /// </summary> /// <param name="configuration">TelemetryConfiguration passed to the module.</param> public void Initialize(TelemetryConfiguration configuration) { if (!this.IsInitialized) { lock (this.moduleInitializationLock) { if (!this.IsInitialized) { QuickPulseEventSource.Log.ModuleIsBeingInitializedEvent( this.QuickPulseServiceEndpoint, this.DisableFullTelemetryItems, this.DisableTopCpuProcesses, this.AuthenticationApiKey); QuickPulseEventSource.Log.TroubleshootingMessageEvent("Validating configuration..."); ValidateConfiguration(configuration); this.config = configuration; QuickPulseEventSource.Log.TroubleshootingMessageEvent("Initializing members..."); this.collectionTimeSlotManager = this.collectionTimeSlotManager ?? new QuickPulseCollectionTimeSlotManager(); this.performanceCollector = this.performanceCollector ?? PerformanceCounterUtility.GetPerformanceCollector(); this.timeProvider = this.timeProvider ?? new Clock(); this.topCpuCollector = this.topCpuCollector ?? new QuickPulseTopCpuCollector(this.timeProvider, new QuickPulseProcessProvider(PerfLib.GetPerfLib())); this.timings = this.timings ?? QuickPulseTimings.Default; CollectionConfigurationError[] errors; this.collectionConfiguration = new CollectionConfiguration( new CollectionConfigurationInfo() { ETag = string.Empty }, out errors, this.timeProvider); this.dataAccumulatorManager = this.dataAccumulatorManager ?? new QuickPulseDataAccumulatorManager(this.collectionConfiguration); this.InitializeServiceClient(configuration); this.stateManager = new QuickPulseCollectionStateManager( this.ServiceClient, this.timeProvider, this.timings, this.OnStartCollection, this.OnStopCollection, this.OnSubmitSamples, this.OnReturnFailedSamples, this.OnUpdatedConfiguration, this.OnUpdatedServiceEndpoint); this.CreateStateThread(); this.IsInitialized = true; } } } }
private static QuickPulseCollectionStateManager CreateManager( IQuickPulseServiceClient serviceClient, Clock timeProvider, List <string> actions, List <QuickPulseDataSample> returnedSamples = null, QuickPulseTimings timings = null, List <CollectionConfigurationInfo> collectionConfigurationInfos = null) { var manager = new QuickPulseCollectionStateManager( serviceClient, timeProvider, timings ?? QuickPulseTimings.Default, () => actions.Add(StartCollectionMessage), () => actions.Add(StopCollectionMessage), () => { actions.Add(CollectMessage); CollectionConfigurationError[] errors; var now = DateTimeOffset.UtcNow; return (new[] { new QuickPulseDataSample( new QuickPulseDataAccumulator( new CollectionConfiguration(EmptyCollectionConfigurationInfo, out errors, timeProvider)) { AIRequestSuccessCount = 5, StartTimestamp = now, EndTimestamp = now.AddSeconds(1) }, new Dictionary <string, Tuple <PerformanceCounterData, double> >(), Enumerable.Empty <Tuple <string, int> >(), false) }.ToList()); }, samples => { returnedSamples?.AddRange(samples); }, collectionConfigurationInfo => { actions.Add(UpdatedConfigurationMessage); collectionConfigurationInfos?.Add(collectionConfigurationInfo); CollectionConfigurationError[] errors; new CollectionConfiguration(collectionConfigurationInfo, out errors, timeProvider); return(errors); }, _ => { }); return(manager); }
/// <summary> /// Initialize method is called after all configuration properties have been loaded from the configuration. /// </summary> /// <param name="configuration">TelemetryConfiguration passed to the module.</param> public void Initialize(TelemetryConfiguration configuration) { if (!this.isInitialized) { lock (this.lockObject) { if (!this.isInitialized) { QuickPulseEventSource.Log.ModuleIsBeingInitializedEvent( this.QuickPulseServiceEndpoint, this.DisableFullTelemetryItems, this.DisableTopCpuProcesses); QuickPulseEventSource.Log.TroubleshootingMessageEvent("Validating configuration..."); this.ValidateConfiguration(configuration); this.config = configuration; QuickPulseEventSource.Log.TroubleshootingMessageEvent("Initializing members..."); this.collectionTimeSlotManager = this.collectionTimeSlotManager ?? new QuickPulseCollectionTimeSlotManager(); this.dataAccumulatorManager = this.dataAccumulatorManager ?? new QuickPulseDataAccumulatorManager(); this.performanceCollector = this.performanceCollector ?? (PerformanceCounterUtility.IsWebAppRunningInAzure() ? (IPerformanceCollector) new WebAppPerformanceCollector() : (IPerformanceCollector) new StandardPerformanceCollector()); this.timeProvider = this.timeProvider ?? new Clock(); this.topCpuCollector = this.topCpuCollector ?? new QuickPulseTopCpuCollector(this.timeProvider, new QuickPulseProcessProvider(PerfLib.GetPerfLib())); this.timings = timings ?? QuickPulseTimings.Default; this.InitializeServiceClient(configuration); this.stateManager = new QuickPulseCollectionStateManager( this.serviceClient, this.timeProvider, this.timings, this.OnStartCollection, this.OnStopCollection, this.OnSubmitSamples, this.OnReturnFailedSamples); this.CreateStateThread(); this.isInitialized = true; } } } }
/// <summary> /// Initialize method is called after all configuration properties have been loaded from the configuration. /// </summary> /// <param name="configuration">TelemetryConfiguration passed to the module.</param> public void Initialize(TelemetryConfiguration configuration) { if (!this.isInitialized) { lock (this.lockObject) { if (!this.isInitialized) { QuickPulseEventSource.Log.ModuleIsBeingInitializedEvent( string.Format( CultureInfo.InvariantCulture, "QuickPulseServiceEndpoint: '{0}', DisableFullTelemetryItems: '{1}'", this.QuickPulseServiceEndpoint, this.DisableFullTelemetryItems)); QuickPulseEventSource.Log.TroubleshootingMessageEvent("Validating configuration..."); this.ValidateConfiguration(configuration); this.config = configuration; QuickPulseEventSource.Log.TroubleshootingMessageEvent("Initializing members..."); this.collectionTimeSlotManager = this.collectionTimeSlotManager ?? new QuickPulseCollectionTimeSlotManager(); this.dataAccumulatorManager = this.dataAccumulatorManager ?? new QuickPulseDataAccumulatorManager(); this.performanceCollector = this.performanceCollector ?? new PerformanceCollector(); this.timeProvider = this.timeProvider ?? new Clock(); this.timings = timings ?? QuickPulseTimings.Default; this.InitializeServiceClient(configuration); this.stateManager = new QuickPulseCollectionStateManager( this.serviceClient, this.timeProvider, this.timings, this.OnStartCollection, this.OnStopCollection, this.OnSubmitSamples, this.OnReturnFailedSamples); this.CreateStateThread(); this.isInitialized = true; } } } }
private static QuickPulseCollectionStateManager CreateManager( IQuickPulseServiceClient serviceClient, Clock timeProvider, List <string> actions, List <QuickPulseDataSample> returnedSamples = null, QuickPulseTimings timings = null) { var manager = new QuickPulseCollectionStateManager( serviceClient, timeProvider, timings ?? QuickPulseTimings.Default, () => actions.Add(StartCollectionMessage), () => actions.Add(StopCollectionMessage), () => { actions.Add(CollectMessage); var now = DateTimeOffset.UtcNow; return (new[] { new QuickPulseDataSample( new QuickPulseDataAccumulator { AIRequestSuccessCount = 5, StartTimestamp = now, EndTimestamp = now.AddSeconds(1) }, new Dictionary <string, Tuple <PerformanceCounterData, double> >(), Enumerable.Empty <Tuple <string, int> >(), false) }.ToList()); }, samples => { if (returnedSamples != null) { returnedSamples.AddRange(samples); } }); return(manager); }
public void QuickPulseCollectionStateManagerInitiallyInIdleState() { // ARRANGE var serviceClient = new QuickPulseServiceClientMock(); var manager = new QuickPulseCollectionStateManager( serviceClient, new Clock(), QuickPulseTimings.Default, () => { }, () => { }, () => null, _ => { }); // ACT // ASSERT Assert.AreEqual(false, manager.IsCollectingData); }