コード例 #1
0
        public static EtlProducerWorker.EtlProducerWorkerSettings InitializeSettings(EtlProducerWorker.EtlProducerWorkerParameters param)
        {
            // For most settings we'll just apply the latest setting that
            // the caller has provided
            var etlProducerSettings = new EtlProducerWorker.EtlProducerWorkerSettings
            {
                EtlReadInterval      = param.LatestSettings.EtlReadInterval,
                EtlDeletionAge       = param.LatestSettings.EtlDeletionAgeMinutes,
                WindowsFabricEtlType = param.LatestSettings.ServiceFabricEtlType,
                EtlPath                  = param.LatestSettings.EtlPath,
                EtlFilePatterns          = param.LatestSettings.EtlFilePatterns,
                ProcessingWinFabEtlFiles = param.LatestSettings.ProcessingWinFabEtlFiles
            };

            if (param.IsReadingFromApplicationManifest)
            {
                // We need to merge the remaining settings from each of the ETL producers
                // that depend on us
                var appEtwGuids = new List <Guid>();
                foreach (var producer in param.EtlProducers)
                {
                    appEtwGuids = appEtwGuids.Union(producer.Settings.AppEtwGuids).ToList();
                }

                etlProducerSettings.CustomManifestPaths = GetServiceEtwManifestPaths(param.EtlProducers);
                etlProducerSettings.AppEtwGuids         = appEtwGuids;
            }
            else
            {
                // If we're getting settings from cluster manifest, then
                // all our settings are copied from the latest settings
                // provided by caller.
                etlProducerSettings.CustomManifestPaths = param.LatestSettings.CustomManifestPaths;
                etlProducerSettings.AppEtwGuids         = param.LatestSettings.AppEtwGuids;
            }

            return(etlProducerSettings);
        }
コード例 #2
0
        internal EtlProducer(
            DiskSpaceManager diskSpaceManager,
            IEtlProducerConfigReaderFactory configReaderFactory,
            ITraceFileEventReaderFactory traceFileEventReaderFactory,
            ITraceEventSourceFactory traceEventSourceFactory,
            ProducerInitializationParameters initParam)
        {
            this.diskSpaceManager            = diskSpaceManager;
            this.traceFileEventReaderFactory = traceFileEventReaderFactory;

            // Initialization
            this.logSourceId           = string.Concat(initParam.ApplicationInstanceId, "_", initParam.SectionName);
            this.traceSource           = traceEventSourceFactory.CreateTraceEventSource(FabricEvents.Tasks.FabricDCA);
            this.serviceConfigSections = new List <string>();
            this.logDirectory          = initParam.LogDirectory;
            this.consumerSinks         = initParam.ConsumerSinks;

            // Read instance-specific settings from the settings file
            var configReader = configReaderFactory.CreateEtlProducerConfigReader(this.traceSource, this.logSourceId);

            this.etlProducerSettings = configReader.GetSettings();
            if (false == this.etlProducerSettings.Enabled)
            {
                // ETL file processing is not enabled, so return immediately
                return;
            }

            if (!this.etlProducerSettings.ProcessingWinFabEtlFiles)
            {
                // If we are collecting ETW events on behalf of an app, then we will
                // need information from the <ETW> section of the service manifest.
                this.serviceConfigSections.Add(ServiceConfig.EtwElement);

                // Check if we can use an existing worker object
                string applicationType = this.etlProducerSettings.ApplicationType;
                lock (ProducerWorkers)
                {
                    EtlProducerWorkerInfo workerInfo = ProducerWorkers.FirstOrDefault(w => w.ApplicationType.Equals(
                                                                                          applicationType,
                                                                                          StringComparison.Ordinal));
                    if (null != workerInfo)
                    {
                        // Existing worker object is available.
                        this.traceSource.WriteInfo(
                            this.logSourceId,
                            "Existing ETL producer worker object for application type {0} is available. Restarting the worker object now.",
                            applicationType);

                        // Restart the worker object
                        workerInfo.ProducerWorker.Dispose();
                        workerInfo.ProducerWorker = null;

                        List <EtlProducer> etlProducers = new List <EtlProducer>(workerInfo.EtlProducers)
                        {
                            this
                        };
                        EtlProducerWorker.EtlProducerWorkerParameters newWorkerParam = new EtlProducerWorker.EtlProducerWorkerParameters()
                        {
                            TraceSource = this.traceSource,
                            IsReadingFromApplicationManifest = !this.etlProducerSettings.ProcessingWinFabEtlFiles,
                            ApplicationType    = applicationType,
                            LogDirectory       = initParam.LogDirectory,
                            ProducerInstanceId = applicationType,
                            EtlProducers       = etlProducers,
                            LatestSettings     = this.etlProducerSettings
                        };
                        try
                        {
                            EtlProducerWorker newWorker = new EtlProducerWorker(
                                newWorkerParam,
                                this.diskSpaceManager,
                                this.traceFileEventReaderFactory);
                            workerInfo.EtlProducers.Add(this);
                            workerInfo.ProducerWorker = newWorker;
                        }
                        catch (InvalidOperationException)
                        {
                            this.traceSource.WriteError(
                                this.logSourceId,
                                "Failed to restart ETL producer worker object for application type {0}.",
                                applicationType);
                        }
                    }
                    else
                    {
                        // Create a new worker object
                        this.traceSource.WriteInfo(
                            this.logSourceId,
                            "Creating ETL producer worker object for application type {0} ...",
                            applicationType);

                        List <EtlProducer> etlProducers = new List <EtlProducer> {
                            this
                        };
                        EtlProducerWorker.EtlProducerWorkerParameters newWorkerParam = new EtlProducerWorker.EtlProducerWorkerParameters()
                        {
                            TraceSource = this.traceSource,
                            IsReadingFromApplicationManifest = !this.etlProducerSettings.ProcessingWinFabEtlFiles,
                            ApplicationType    = applicationType,
                            LogDirectory       = initParam.LogDirectory,
                            ProducerInstanceId = applicationType,
                            EtlProducers       = etlProducers,
                            LatestSettings     = this.etlProducerSettings
                        };
                        try
                        {
                            EtlProducerWorker newWorker = new EtlProducerWorker(
                                newWorkerParam,
                                this.diskSpaceManager,
                                this.traceFileEventReaderFactory);
                            workerInfo = new EtlProducerWorkerInfo()
                            {
                                ApplicationType = applicationType,
                                EtlProducers    = new List <EtlProducer>(),
                                ProducerWorker  = newWorker
                            };
                            workerInfo.EtlProducers.Add(this);

                            ProducerWorkers.Add(workerInfo);
                        }
                        catch (InvalidOperationException)
                        {
                            this.traceSource.WriteError(
                                this.logSourceId,
                                "Failed to create ETL producer worker object for application type {0}.",
                                applicationType);
                        }
                    }
                }
            }
            else
            {
                // Create a new  worker object
                List <EtlProducer> etlProducers = new List <EtlProducer> {
                    this
                };
                EtlProducerWorker.EtlProducerWorkerParameters newWorkerParam = new EtlProducerWorker.EtlProducerWorkerParameters()
                {
                    TraceSource = this.traceSource,
                    IsReadingFromApplicationManifest = !this.etlProducerSettings.ProcessingWinFabEtlFiles,
                    ApplicationType    = string.Empty,
                    LogDirectory       = initParam.LogDirectory,
                    ProducerInstanceId = this.logSourceId,
                    EtlProducers       = etlProducers,
                    LatestSettings     = this.etlProducerSettings
                };
                try
                {
                    EtlProducerWorker newWorker = new EtlProducerWorker(
                        newWorkerParam,
                        this.diskSpaceManager,
                        this.traceFileEventReaderFactory);
                    this.producerWorker = newWorker;
                }
                catch (InvalidOperationException)
                {
                }
            }
        }
コード例 #3
0
        public void Dispose()
        {
            if (this.disposed)
            {
                return;
            }

            this.disposed = true;

            if (!this.etlProducerSettings.ProcessingWinFabEtlFiles)
            {
                string applicationType = this.etlProducerSettings.ApplicationType;
                lock (ProducerWorkers)
                {
                    EtlProducerWorkerInfo workerInfo = ProducerWorkers.FirstOrDefault(w => w.ApplicationType.Equals(
                                                                                          applicationType,
                                                                                          StringComparison.Ordinal));
                    if (null != workerInfo)
                    {
                        // Tell the worker object to stop
                        this.traceSource.WriteInfo(
                            this.logSourceId,
                            "Stopping ETL producer worker object for application type {0} ...",
                            applicationType);

                        workerInfo.ProducerWorker.Dispose();
                        workerInfo.ProducerWorker = null;

                        workerInfo.EtlProducers.Remove(this);
                        if (0 == workerInfo.EtlProducers.Count)
                        {
                            // No one else is using the worker object. No need to
                            // restart it.
                            this.traceSource.WriteInfo(
                                this.logSourceId,
                                "No other ETL producer is using the ETL producer worker object for application type {0}, so no need to restart it.",
                                applicationType);
                            ProducerWorkers.Remove(workerInfo);
                        }
                        else
                        {
                            // Restart the worker. Arbitrarily choose one of the remaining
                            // producers for supplying settings.
                            this.traceSource.WriteInfo(
                                this.logSourceId,
                                "Restarting the ETL producer worker object for application type {0} because other ETL producers are using it.",
                                applicationType);
                            EtlProducer producer = workerInfo.EtlProducers[0];
                            EtlProducerWorker.EtlProducerWorkerParameters newWorkerParam = new EtlProducerWorker.EtlProducerWorkerParameters()
                            {
                                TraceSource = producer.traceSource,
                                IsReadingFromApplicationManifest = !producer.etlProducerSettings.ProcessingWinFabEtlFiles,
                                ApplicationType    = applicationType,
                                LogDirectory       = producer.logDirectory,
                                ProducerInstanceId = applicationType,
                                EtlProducers       = workerInfo.EtlProducers,
                                LatestSettings     = producer.etlProducerSettings
                            };
                            try
                            {
                                EtlProducerWorker newWorker = new EtlProducerWorker(
                                    newWorkerParam,
                                    this.diskSpaceManager,
                                    this.traceFileEventReaderFactory);
                                workerInfo.ProducerWorker = newWorker;
                            }
                            catch (InvalidOperationException)
                            {
                                this.traceSource.WriteError(
                                    this.logSourceId,
                                    "Failed to restart the ETL producer worker object for application type {0}.",
                                    applicationType);
                            }
                        }
                    }
                }
            }
            else
            {
                if (null != this.producerWorker)
                {
                    this.producerWorker.Dispose();
                }
            }

            GC.SuppressFinalize(this);
        }