internal EtwCsvUploadWorker(EtwCsvUploadWorkerParameters param, FabricEvents.ExtensionsEvents traceSource) { // Initialization Action onError = () => { if (null != this.etlToCsvWriter) { this.etlToCsvWriter.Dispose(); } }; this.logSourceId = param.UploaderInstanceId; this.traceSource = traceSource; this.fileUploadSettings = param.Settings; this.etwCsvFolder = string.Empty; this.initParam = param; if (false == this.fileUploadSettings.DestinationIsLocalAppFolder) { // Append fabric node instance name to destination path, so that // each node uploads to a different subfolder. this.destinationPathForNode = Path.Combine( this.fileUploadSettings.DestinationPath, param.FabricNodeInstanceName); } else { this.destinationPathForNode = this.fileUploadSettings.DestinationPath; } // Create a sub-directory for ourselves under the log directory this.etwCsvFolder = this.GetEtwCsvSubDirectory(); if (!string.IsNullOrWhiteSpace(this.etwCsvFolder)) { // Create the helper object that writes events delivered from the ETL // files into CSV files. this.etlToCsvWriter = new EtlToCsvFileWriter( new TraceEventSourceFactory(), this.logSourceId, param.FabricNodeId, this.etwCsvFolder, false, param.DiskSpaceManager, new EtlToCsvFileWriterConfigReader()); } // Set the event filter this.etlToCsvWriter.SetEtwEventFilter( this.fileUploadSettings.Filter, param.IsReadingFromApplicationManifest ? string.Empty : WinFabDefaultFilter.StringRepresentation, param.IsReadingFromApplicationManifest ? string.Empty : WinFabSummaryFilter.StringRepresentation, !param.IsReadingFromApplicationManifest); // Create a sub-directory for the uploader under the log directory if (!this.GetUploaderWorkSubDirectory()) { onError(); throw new InvalidOperationException(); } try { this.uploader = new FileShareUploader( this.traceSource, this.logSourceId, param.IsReadingFromApplicationManifest, this.etwCsvFolder, this.destinationPathForNode, this.fileUploadSettings.AccessInfo, this.workFolder, this.fileUploadSettings.UploadInterval, this.fileUploadSettings.FileSyncInterval, this.fileUploadSettings.FileDeletionAgeMinutes, this.fileUploadSettings.DestinationIsLocalAppFolder, param.FabricNodeId); this.uploader.Start(); } catch (Exception) { onError(); throw; } this.traceSource.WriteInfo( this.logSourceId, "Upload to file share is configured. Destination: {0}, Local trace Path: {1}.", this.fileUploadSettings.DestinationPath, this.etwCsvFolder); }
public EtwCsvUploadWorker(EtwCsvUploadWorkerParameters initParam) { // Initialization this.initParam = initParam; this.logSourceId = this.initParam.UploaderInstanceId; this.traceSource = this.initParam.TraceSource; this.blobUploadSettings = this.initParam.Settings; var accountName = this.blobUploadSettings.StorageAccountFactory.Connection.UseDevelopmentStorage ? AzureConstants.DevelopmentStorageConnectionString : this.blobUploadSettings.StorageAccountFactory.Connection.AccountName; this.destinationKey = string.Join( "_", StandardPluginTypes.AzureBlobEtwCsvUploader, accountName, this.blobUploadSettings.EtwTraceContainerName); // Create a sub-directory for ourselves under the log directory bool success = this.GetEtwCsvSubDirectory(); // Create the helper object that writes events delivered from the ETL // files into CSV files. if (success) { this.etlToCsvWriter = new EtlToCsvFileWriter( new TraceEventSourceFactory(), this.logSourceId, this.initParam.FabricNodeId, this.etwCsvFolder, false, initParam.DiskSpaceManager); // Set the event filter this.etlToCsvWriter.SetEtwEventFilter( this.blobUploadSettings.Filter, this.initParam.IsReadingFromApplicationManifest ? string.Empty : WinFabDefaultFilter.StringRepresentation, this.initParam.IsReadingFromApplicationManifest ? string.Empty : WinFabSummaryFilter.StringRepresentation, !this.initParam.IsReadingFromApplicationManifest); // Create a sub-directory for the uploader under the log directory success = this.GetUploaderWorkSubDirectory(); } if (success) { // Create and initialize the uploader // // NOTE: By specifying 'true' for the 'filterDeletionByNodeId' parameter, // we only delete those blobs that were uploaded by the current node. We // identify this via the Fabric node ID that the ETL-to-CSV writer prefixed // to the file name before uploading. This is done so that all nodes don't // wastefully try to delete all blobs. try { var destinationPath = string.Concat( this.blobUploadSettings.StorageAccountFactory.Connection.UseDevelopmentStorage ? AzureConstants.DevelopmentStorageConnectionString : this.blobUploadSettings.StorageAccountFactory.Connection.AccountName, ";", // This separator cannot occur in account name or container name this.blobUploadSettings.EtwTraceContainerName); this.uploader = new AzureFileUploader( this.traceSource, this.logSourceId, this.etwCsvFolder, destinationPath, this.workFolder, this.blobUploadSettings.StorageAccountFactory, this.blobUploadSettings.EtwTraceContainerName, this.blobUploadSettings.UploadInterval, this.blobUploadSettings.FileSyncInterval, this.blobUploadSettings.BlobDeletionAge, this.initParam.FabricNodeInstanceName, this.blobUploadSettings.DeploymentId); this.uploader.Start(); } catch (Exception e) { throw new InvalidOperationException("AzureFileUploader could not be constructed.", e); } } if (success) { this.traceSource.WriteInfo( this.logSourceId, "Upload to blob storage is configured. Storage account: {0}, Trace container: {1}, Local trace Path: {2}, Upload interval (minutes): {3}", this.blobUploadSettings.StorageAccountFactory.Connection.AccountName, this.blobUploadSettings.EtwTraceContainerName, this.etwCsvFolder, this.blobUploadSettings.UploadInterval.TotalMinutes); } else { if (null != this.etlToCsvWriter) { this.etlToCsvWriter.Dispose(); this.etlToCsvWriter = null; } } if (!success) { throw new InvalidOperationException(); } }