internal AzureTableTrimmer( FabricEvents.ExtensionsEvents traceSource, string logSourceId, StorageAccountFactory storageAccountFactory, string tableName, TimeSpan entityDeletionAge, QueryCreationMethod queryCreationMethod, AzureTablePerformance perfHelper) { // Initialization this.stopping = false; this.traceSource = traceSource; this.logSourceId = logSourceId; this.storageAccountFactory = storageAccountFactory; this.tableName = tableName; this.entityDeletionAge = entityDeletionAge; this.perfHelper = perfHelper; this.queryCreationMethod = queryCreationMethod; // Deletion and query are currently synchronous, so the concurrency // count is 1. this.perfHelper.ExternalOperationInitialize( ExternalOperationTime.ExternalOperationType.TableQuery, 1); this.perfHelper.ExternalOperationInitialize( ExternalOperationTime.ExternalOperationType.TableDeletion, 1); // Create a timer to delete old logs string timerId = String.Concat( this.logSourceId, OldLogDeletionTimerIdSuffix); this.oldLogDeletionTimer = new DcaTimer( timerId, this.DeleteOldLogsHandler, (this.entityDeletionAge < TimeSpan.FromDays(1)) ? AzureConstants.OldLogDeletionIntervalForTest : AzureConstants.OldLogDeletionInterval); this.oldLogDeletionTimer.Start(); }
public AzureTableEtwEventUploader(ConsumerInitializationParameters initParam) { // Initialization this.stopping = false; this.initParam = initParam; this.logSourceId = String.Concat(this.initParam.ApplicationInstanceId, "_", this.initParam.SectionName); this.traceSource = new FabricEvents.ExtensionsEvents(FabricEvents.Tasks.FabricDCA); this.configReader = new ConfigReader(initParam.ApplicationInstanceId); this.azureUtility = new AzureUtility(this.traceSource, this.logSourceId); this.perfHelper = new AzureTablePerformance(this.traceSource, this.logSourceId); // Make sure that the Azure interfaces are available if (false == AzureUtility.IsAzureInterfaceAvailable()) { const string Message = "Due to unavailability of Azure interfaces, ETW traces will not be uploaded to Azure table storage."; this.traceSource.WriteError( this.logSourceId, Message); throw new InvalidOperationException(Message); } this.azureNodeInstanceId = AzureUtility.RoleInstanceId; // Read table-specific settings from settings.xml GetSettings(); if (false == this.tableUploadSettings.Enabled) { // Upload to Azure table storage is not enabled, so return immediately return; } // Create a sub-directory for ourselves under the log directory string bufferedEventFolder = GetBufferedEventSubDirectory(); if (String.IsNullOrEmpty(bufferedEventFolder)) { throw new InvalidOperationException("Unable to get buffered event subdirectory."); } // Create the helper object that buffers events delivered from the ETL // files into CSV files on disk. this.bufferedEventProvider = new BufferedEtwEventProvider( new TraceEventSourceFactory(), this.logSourceId, bufferedEventFolder, this.tableUploadSettings.UploadIntervalMinutes, this.tableUploadSettings.EntityDeletionAge, this); if (null == this.bufferedEventProvider) { const string Message = "Failed to create buffered event provider helper object."; this.traceSource.WriteError( this.logSourceId, Message); throw new InvalidOperationException(Message); } // Set the filter for Windows Fabric events this.bufferedEventProvider.SetEtwEventFilter( this.tableUploadSettings.Filter, defaultTableFilter, WinFabSummaryFilter.StringRepresentation, true); // Initialize the batch upload concurrency count Debug.Assert(this.tableUploadSettings.BatchUploadConcurrencyCount <= AzureConstants.MaxBatchConcurrencyCount); if (this.tableUploadSettings.BatchUploadConcurrencyCount <= AzureConstants.MaxBatchConcurrencyCount) { this.batchConcurrencyCount = this.tableUploadSettings.BatchUploadConcurrencyCount; } else { this.traceSource.WriteError( this.logSourceId, "{0} is an invalid value for table batch concurrency count. The maximum supported value is {1} and that value will be used instead.", this.tableUploadSettings.BatchUploadConcurrencyCount, AzureConstants.MaxBatchConcurrencyCount); this.batchConcurrencyCount = AzureConstants.MaxBatchConcurrencyCount; } this.perfHelper.ExternalOperationInitialize( ExternalOperationTime.ExternalOperationType.TableUpload, this.batchConcurrencyCount); // Create the table try { CreateTable(); } catch (Exception e) { const string Message = "Due to an error in table creation ETW traces will not be uploaded to Azure table storage."; this.traceSource.WriteExceptionAsError( this.logSourceId, e, Message); throw new InvalidOperationException(Message, e); } this.traceSource.WriteInfo( this.logSourceId, "Created table for uploading ETW traces. Storage account: {0}, Table name: {1}", this.tableUploadSettings.StorageAccountFactory.Connection.AccountName, this.tableUploadSettings.TableName); // Initialize old log deletion this.trimmer = new AzureTableTrimmer( this.traceSource, this.logSourceId, this.tableUploadSettings.StorageAccountFactory, this.tableUploadSettings.TableName, this.tableUploadSettings.EntityDeletionAge, this.CreateDeletionQuery, this.perfHelper); }