Esempio n. 1
0
        internal void UpdateSettings(AzureBlobCsvUploader.BlobUploadSettings newSettings)
        {
            bool updateFilter   = ShouldUpdateFilter(newSettings);
            bool updateUploader = ShouldUpdateUploader(newSettings);

            if (updateFilter || updateUploader)
            {
                this.blobUploadSettings = newSettings;
            }

            if (updateUploader)
            {
                this.traceSource.WriteInfo(
                    this.logSourceId,
                    "Due to settings change, the uploader will be stopped and restarted.");

                // Stop the uploader
                if (null != this.uploader)
                {
                    this.uploader.Dispose();
                }

                // Restart the upload with the new settings
                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.LttTraceContainerName);

                    this.uploader = new AzureFileUploader(
                        this.traceSource,
                        this.logSourceId,
                        this.csvFolder,
                        destinationPath,
                        this.workFolder,
                        this.blobUploadSettings.StorageAccountFactory,
                        this.blobUploadSettings.LttTraceContainerName,
                        this.blobUploadSettings.UploadInterval,
                        this.blobUploadSettings.FileSyncInterval,
                        this.blobUploadSettings.BlobDeletionAge,
                        this.initParam.FabricNodeInstanceName,
                        this.blobUploadSettings.DeploymentId);

                    this.uploader.Start();
                }
                catch (Exception ex)
                {
                    throw new InvalidOperationException("AzureFileUploader could not be constructed.", ex);
                }
            }
        }
Esempio n. 2
0
        private bool ShouldUpdateFilter(AzureBlobCsvUploader.BlobUploadSettings newSettings)
        {
            bool updateNeeded = false;

            if (false == newSettings.Filter.Equals(this.blobUploadSettings.Filter, StringComparison.Ordinal))
            {
                this.traceSource.WriteInfo(
                    this.logSourceId,
                    "Settings change detected. Current LTT event filter: {0}, new ETW event filter: {1}.",
                    this.blobUploadSettings.Filter,
                    newSettings.Filter);
                updateNeeded = true;
            }
            return(updateNeeded);
        }
Esempio n. 3
0
        private bool ShouldUpdateUploader(AzureBlobCsvUploader.BlobUploadSettings newSettings)
        {
            bool updateNeeded = false;

            if (false == this.blobUploadSettings.StorageAccountFactory.Connection.UseDevelopmentStorage)
            {
                if (false == AreAccountKeysEqual(
                        newSettings.StorageAccountFactory.Connection.AccountKey,
                        this.blobUploadSettings.StorageAccountFactory.Connection.AccountKey))
                {
                    this.traceSource.WriteInfo(
                        this.logSourceId,
                        "Settings change detected. Account key has changed.");
                    updateNeeded = true;
                }
            }

            if (newSettings.UploadInterval != this.blobUploadSettings.UploadInterval)
            {
                this.traceSource.WriteInfo(
                    this.logSourceId,
                    "Settings change detected. Current upload interval (minutes): {0}, new upload interval (minutes): {1}.",
                    this.blobUploadSettings.UploadInterval,
                    newSettings.UploadInterval);
                updateNeeded = true;
            }

            if (newSettings.BlobDeletionAge != this.blobUploadSettings.BlobDeletionAge)
            {
                this.traceSource.WriteInfo(
                    this.logSourceId,
                    "Settings change detected. Current file deletion age (minutes): {0}, new file deletion age (minutes): {1}.",
                    this.blobUploadSettings.BlobDeletionAge,
                    newSettings.BlobDeletionAge);
                updateNeeded = true;
            }

            return(updateNeeded);
        }
Esempio n. 4
0
        internal CsvUploadWorker(CsvUploadWorkerParameters initParam, DiskSpaceManager diskSpaceManager)
        {
            // Initialization
            this.FlushDataOnDispose = false;
            this.initParam          = initParam;
            this.logSourceId        = this.initParam.UploaderInstanceId;
            this.traceSource        = this.initParam.TraceSource;
            this.blobUploadSettings = this.initParam.Settings;
            this.azureUtility       = new AzureUtility(this.traceSource, this.logSourceId);
            this.destinationKey     = String.Join(
                "_",
                new string[]
            {
                StandardPluginTypes.AzureBlobCsvUploader,
                this.blobUploadSettings.StorageAccountFactory.Connection.UseDevelopmentStorage ?
                AzureConstants.DevelopmentStorageConnectionString :
                this.blobUploadSettings.StorageAccountFactory.Connection.AccountName,
                this.blobUploadSettings.LttTraceContainerName
            });
            this.disposed = false;

            // Create a sub-directory for ourselves under the log directory
            bool success = GetCsvSubDirectory();

            string sourceDirectory = Path.Combine(initParam.LogDirectory, "Traces");

            // Create the helper object that writes events delivered from the LTT
            // files into CSV files.
            if (success)
            {
                this.csvToUploadFolderWriter = new CsvToUploadFolderWriter(
                    this.logSourceId,
                    this.initParam.FabricNodeId,
                    this.csvFolder,
                    sourceDirectory,
                    diskSpaceManager,
                    false);
                if (null == this.csvToUploadFolderWriter)
                {
                    this.traceSource.WriteError(
                        this.logSourceId,
                        "Failed to create CSV to Upload Foler writer helper object.");
                    success = false;
                }
            }

            if (success)
            {
                // Create a sub-directory for the uploader under the log directory
                success = GetUploaderWorkSubDirectory();
            }

            if (this.blobUploadSettings.Enabled)
            {
                // 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.LttTraceContainerName);

                    this.uploader = new AzureFileUploader(
                        this.traceSource,
                        this.logSourceId,
                        this.csvFolder,
                        destinationPath,
                        this.workFolder,
                        this.blobUploadSettings.StorageAccountFactory,
                        this.blobUploadSettings.LttTraceContainerName,
                        this.blobUploadSettings.UploadInterval,
                        this.blobUploadSettings.FileSyncInterval,
                        this.blobUploadSettings.BlobDeletionAge,
                        this.initParam.FabricNodeInstanceName,
                        this.blobUploadSettings.DeploymentId);

                    this.uploader.Start();
                }
                catch (Exception ex)
                {
                    throw new InvalidOperationException("AzureFileUploader could not be constructed.", ex);
                }

                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.LttTraceContainerName,
                    this.csvFolder,
                    this.blobUploadSettings.UploadInterval);
            }
            else
            {
                this.traceSource.WriteInfo(
                    this.logSourceId,
                    "Upload to blob storage is disabled (Storage key not available). Only log age management is enabled."
                    + "Local trace Path: {0}",
                    this.csvFolder
                    );
            }
        }