Esempio n. 1
0
        internal static ITelemetryWriter CreateTelemetryWriter(
            ConfigReader configReader,
            string clusterId,
            string nodeName,
            TelemetryCollection.LogErrorDelegate logErrorDelegate)
        {
#if !DotNetCoreClrLinux
            bool createFileShareWriter = false;
#endif
            FabricEvents.ExtensionsEvents traceSource = new FabricEvents.ExtensionsEvents(FabricEvents.Tasks.FabricDCA);
            traceSource.WriteInfo("TelemetryWriterFactory", "Entering TelemetryWriterFactory");

#if !DotNetCoreClrLinux
            string fabricLogsShare;
            bool   isFabricLogsLocalFolder;
            if (FileShareCommon.GetDestinationPath(
                    traceSource,
                    string.Concat(ConfigReader.FileShareWinFabSectionName),
                    configReader,
                    ConfigReader.FileShareWinFabSectionName,
                    out isFabricLogsLocalFolder,
                    out fabricLogsShare))
            {
                traceSource.WriteInfo("TelemetryWriterFactory", "isFabricLogsLocalFolder: {0}, fabricLogsShare: {1}", isFabricLogsLocalFolder, fabricLogsShare);

                string customizedGoalStateFileUrl = configReader.GetUnencryptedConfigValue(
                    ConfigReader.UpgradeOrchestrationServiceConfigSectionName,
                    ConfigReader.GoalStateFileUrlParamName,
                    string.Empty);

                if (customizedGoalStateFileUrl != string.Empty)
                {
                    createFileShareWriter = true;
                }
            }

            if (createFileShareWriter)
            {
                string fileShareDirectory = Path.Combine(Path.GetDirectoryName(fabricLogsShare), "fabrictelemetries-" + clusterId, nodeName);
                traceSource.WriteInfo("TelemetryWriterFactory", "return fileShare {0}", fileShareDirectory);
                return(new FileShareTelemetryWriter(fileShareDirectory, logErrorDelegate));
            }
            else
#endif
            {
                traceSource.WriteInfo("TelemetryWriterFactory", "return appinsight");
                return(new AppInsightsTelemetryWriter());
            }
        }
Esempio n. 2
0
        private void GetSettings()
        {
            // Check for values in settings.xml
            this.fileUploadSettings.Enabled = this.configReader.GetUnencryptedConfigValue(
                this.initParam.SectionName,
                FileShareUploaderConstants.EnabledParamName,
                FileShareUploaderConstants.FileShareUploadEnabledByDefault);
            if (this.fileUploadSettings.Enabled)
            {
                if (false == FileShareCommon.GetDestinationPath(
                        this.traceSource,
                        this.logSourceId,
                        this.configReader,
                        this.initParam.SectionName,
                        out this.fileUploadSettings.DestinationIsLocalAppFolder,
                        out this.fileUploadSettings.DestinationPath))
                {
                    this.fileUploadSettings.Enabled = false;
                    return;
                }

                if (false == FileShareCommon.GetAccessInfo(
                        this.traceSource,
                        this.logSourceId,
                        this.configReader,
                        this.initParam.SectionName,
                        out this.fileUploadSettings.AccessInfo))
                {
                    this.fileUploadSettings.Enabled = false;
                    return;
                }

                var defaultUploadInterval = this.fileUploadSettings.DestinationIsLocalAppFolder ?
                                            (int)FileShareUploaderConstants.DefaultLocalFolderFlushInterval.TotalMinutes :
                                            (int)FileShareUploaderConstants.DefaultFileUploadInterval.TotalMinutes;
                this.fileUploadSettings.UploadInterval = TimeSpan.FromMinutes(this.configReader.GetUnencryptedConfigValue(
                                                                                  this.initParam.SectionName,
                                                                                  FileShareUploaderConstants.UploadIntervalParamName,
                                                                                  defaultUploadInterval));
                this.fileUploadSettings.FileSyncInterval = TimeSpan.FromMinutes(this.configReader.GetUnencryptedConfigValue(
                                                                                    this.initParam.SectionName,
                                                                                    FileShareUploaderConstants.FileSyncIntervalParamName,
                                                                                    (int)FileShareUploaderConstants.DefaultFileSyncInterval.TotalMinutes));
                var fileDeletionAge = TimeSpan.FromDays(this.configReader.GetUnencryptedConfigValue(
                                                            this.initParam.SectionName,
                                                            FileShareUploaderConstants.DataDeletionAgeParamName,
                                                            (int)FileShareUploaderConstants.DefaultDataDeletionAgeDays.TotalDays));
                if (fileDeletionAge > FileShareUploaderConstants.MaxDataDeletionAge)
                {
                    this.traceSource.WriteWarning(
                        this.logSourceId,
                        "The value {0} specified for section {1}, parameter {2} is greater than the maximum permitted value {3}. Therefore the maximum permitted value will be used instead.",
                        fileDeletionAge,
                        this.initParam.SectionName,
                        FileShareUploaderConstants.DataDeletionAgeParamName,
                        FileShareUploaderConstants.MaxDataDeletionAge);
                    fileDeletionAge = FileShareUploaderConstants.MaxDataDeletionAge;
                }

                this.fileUploadSettings.FileDeletionAgeMinutes = fileDeletionAge;

                this.fileUploadSettings.Filter = this.GetFilters();

                // Check for test settings
                var logDeletionAgeTestValue = TimeSpan.FromMinutes(this.configReader.GetUnencryptedConfigValue(
                                                                       this.initParam.SectionName,
                                                                       FileShareUploaderConstants.TestDataDeletionAgeParamName,
                                                                       0));
                if (logDeletionAgeTestValue != TimeSpan.Zero)
                {
                    if (logDeletionAgeTestValue > FileShareUploaderConstants.MaxDataDeletionAge)
                    {
                        this.traceSource.WriteWarning(
                            this.logSourceId,
                            "The value {0} specified for section {1}, parameter {2} is greater than the maximum permitted value {3}. Therefore the maximum permitted value will be used instead.",
                            logDeletionAgeTestValue,
                            this.initParam.SectionName,
                            FileShareUploaderConstants.TestDataDeletionAgeParamName,
                            FileShareUploaderConstants.MaxDataDeletionAge);
                        logDeletionAgeTestValue = FileShareUploaderConstants.MaxDataDeletionAge;
                    }

                    this.fileUploadSettings.FileDeletionAgeMinutes = logDeletionAgeTestValue;
                }

                // Write settings to log
                this.traceSource.WriteInfo(
                    this.logSourceId,
                    "Folder upload enabled. Destination path: {0}, Account type: {1}, Domain name: {2}, User name: {3}, File deletion age ({4}): {5}",
                    this.fileUploadSettings.DestinationPath,
                    this.fileUploadSettings.AccessInfo.AccountType,
                    this.fileUploadSettings.AccessInfo.DomainName,
                    this.fileUploadSettings.AccessInfo.UserName,
                    (logDeletionAgeTestValue == TimeSpan.Zero) ? "days" : "minutes",
                    (logDeletionAgeTestValue == TimeSpan.Zero) ? fileDeletionAge : logDeletionAgeTestValue);
            }
            else
            {
                this.traceSource.WriteInfo(
                    this.logSourceId,
                    "Folder upload not enabled");
            }
        }