public static void UnregisterBuildId(this ILogger logger) { GlobalInfoStorage.SetGlobalInfo(GlobalInfoKey.BuildId, value: null); if (logger is IOperationLogger operationLogger) { operationLogger.UnregisterBuildId(); } }
public static void RegisterBuildId(this ILogger logger, string buildId) { GlobalInfoStorage.SetGlobalInfo(GlobalInfoKey.BuildId, buildId); if (logger is IOperationLogger operationLogger) { operationLogger.RegisterBuildId(buildId); } }
private static IStructuredLogger CreateNLogAdapter(OperationContext operationContext, DistributedCacheServiceArguments arguments) { Contract.RequiresNotNull(arguments.Configuration.LoggingSettings); // This is done for performance. See: https://github.com/NLog/NLog/wiki/performance#configure-nlog-to-not-scan-for-assemblies NLog.Config.ConfigurationItemFactory.Default = new NLog.Config.ConfigurationItemFactory(typeof(NLog.ILogger).GetTypeInfo().Assembly); // This is needed for dependency ingestion. See: https://github.com/NLog/NLog/wiki/Dependency-injection-with-NLog // The issue is that we need to construct a log, which requires access to both our config and the host. It // seems too much to put it into the AzureBlobStorageLogTarget itself, so we do it here. var defaultConstructor = NLog.Config.ConfigurationItemFactory.Default.CreateInstance; NLog.Config.ConfigurationItemFactory.Default.CreateInstance = type => { if (type == typeof(AzureBlobStorageLogTarget)) { var log = CreateAzureBlobStorageLogAsync(operationContext, arguments, arguments.Configuration.LoggingSettings.Configuration).Result; var target = new AzureBlobStorageLogTarget(log); return(target); } return(defaultConstructor(type)); }; NLog.Targets.Target.Register <AzureBlobStorageLogTarget>(nameof(AzureBlobStorageLogTarget)); // This is done in order to allow our logging configuration to access key telemetry information. var telemetryFieldsProvider = arguments.TelemetryFieldsProvider; NLog.LayoutRenderers.LayoutRenderer.Register("APEnvironment", _ => telemetryFieldsProvider.APEnvironment); NLog.LayoutRenderers.LayoutRenderer.Register("APCluster", _ => telemetryFieldsProvider.APCluster); NLog.LayoutRenderers.LayoutRenderer.Register("APMachineFunction", _ => telemetryFieldsProvider.APMachineFunction); NLog.LayoutRenderers.LayoutRenderer.Register("MachineName", _ => telemetryFieldsProvider.MachineName); NLog.LayoutRenderers.LayoutRenderer.Register("ServiceName", _ => telemetryFieldsProvider.ServiceName); NLog.LayoutRenderers.LayoutRenderer.Register("ServiceVersion", _ => telemetryFieldsProvider.ServiceVersion); NLog.LayoutRenderers.LayoutRenderer.Register("Stamp", _ => telemetryFieldsProvider.Stamp); NLog.LayoutRenderers.LayoutRenderer.Register("Ring", _ => telemetryFieldsProvider.Ring); NLog.LayoutRenderers.LayoutRenderer.Register("ConfigurationId", _ => telemetryFieldsProvider.ConfigurationId); NLog.LayoutRenderers.LayoutRenderer.Register("CacheVersion", _ => Utilities.Branding.Version); NLog.LayoutRenderers.LayoutRenderer.Register("Role", _ => GlobalInfoStorage.GetGlobalInfo(GlobalInfoKey.LocalLocationStoreRole)); NLog.LayoutRenderers.LayoutRenderer.Register("BuildId", _ => GlobalInfoStorage.GetGlobalInfo(GlobalInfoKey.BuildId)); // Follows ISO8601 without timezone specification. // See: https://kusto.azurewebsites.net/docs/query/scalar-data-types/datetime.html // See: https://docs.microsoft.com/en-us/dotnet/standard/base-types/standard-date-and-time-format-strings?view=netframework-4.8#the-round-trip-o-o-format-specifier var processStartTimeUtc = SystemClock.Instance.UtcNow.ToString("o", System.Globalization.CultureInfo.InvariantCulture); NLog.LayoutRenderers.LayoutRenderer.Register("ProcessStartTimeUtc", _ => processStartTimeUtc); var configuration = new NLog.Config.XmlLoggingConfiguration(arguments.Configuration.LoggingSettings.NLogConfigurationPath); return(new NLogAdapter(operationContext.TracingContext.Logger, configuration)); }
private void LogMachinePerformanceStatistics(OperationContext context) { var machineStatistics = _performanceCollector.GetMachinePerformanceStatistics(); // Tracing a few things as metrics. Tracer.TrackMetric(context, $"MachinePerf_{nameof(machineStatistics.ProcessThreadCount)}", machineStatistics.ProcessThreadCount); Tracer.TrackMetric(context, $"MachinePerf_{nameof(machineStatistics.ThreadPoolWorkerThreads)}", machineStatistics.ThreadPoolWorkerThreads); Tracer.Info(context, "MachinePerformanceStatistics: " + machineStatistics.ToTracingString()); if (GlobalInfoStorage.GetGlobalInfo(GlobalInfoKey.LocalLocationStoreRole) == "Master") { machineStatistics.CollectMetrics((name, value) => { context.TrackMetric(name, value, "CacheMasterPerfStats"); }); } }
private async Task ApplySecretSettingsForLlsAsync( RedisContentLocationStoreConfiguration configuration, AbsolutePath localCacheRoot, RocksDbContentLocationDatabaseConfiguration dbConfig) { (var secrets, var errors) = await _secretRetriever.TryRetrieveSecretsAsync(); if (secrets == null) { _logger.Error($"Unable to configure Local Location Store. {errors}"); return; } configuration.Checkpoint = new CheckpointConfiguration(localCacheRoot); if (_distributedSettings.IsMasterEligible) { // Use master selection by setting role to null configuration.Checkpoint.Role = null; } else { // Not master eligible. Set role to worker. configuration.Checkpoint.Role = Role.Worker; } // It is important to set the current role of the service, to have non-null Role column // in all the tracing messages emitted to Kusto. GlobalInfoStorage.SetServiceRole(configuration.Checkpoint.Role?.ToString() ?? "MasterEligible"); var checkpointConfiguration = configuration.Checkpoint; ApplyIfNotNull(_distributedSettings.MirrorClusterState, value => configuration.MirrorClusterState = value); ApplyIfNotNull( _distributedSettings.HeartbeatIntervalMinutes, value => checkpointConfiguration.HeartbeatInterval = TimeSpan.FromMinutes(value)); ApplyIfNotNull( _distributedSettings.CreateCheckpointIntervalMinutes, value => checkpointConfiguration.CreateCheckpointInterval = TimeSpan.FromMinutes(value)); ApplyIfNotNull( _distributedSettings.RestoreCheckpointIntervalMinutes, value => checkpointConfiguration.RestoreCheckpointInterval = TimeSpan.FromMinutes(value)); ApplyIfNotNull( _distributedSettings.RestoreCheckpointTimeoutMinutes, value => checkpointConfiguration.RestoreCheckpointTimeout = TimeSpan.FromMinutes(value)); ApplyIfNotNull( _distributedSettings.UpdateClusterStateIntervalSeconds, value => checkpointConfiguration.UpdateClusterStateInterval = TimeSpan.FromSeconds(value)); ApplyIfNotNull(_distributedSettings.PacemakerEnabled, v => checkpointConfiguration.PacemakerEnabled = v); ApplyIfNotNull(_distributedSettings.PacemakerNumberOfBuckets, v => checkpointConfiguration.PacemakerNumberOfBuckets = v); ApplyIfNotNull(_distributedSettings.PacemakerUseRandomIdentifier, v => checkpointConfiguration.PacemakerUseRandomIdentifier = v); ApplyIfNotNull( _distributedSettings.SafeToLazilyUpdateMachineCountThreshold, value => configuration.SafeToLazilyUpdateMachineCountThreshold = value); configuration.EnableReconciliation = !_distributedSettings.Unsafe_DisableReconciliation; configuration.ReconciliationCycleFrequency = TimeSpan.FromMinutes(_distributedSettings.ReconciliationCycleFrequencyMinutes); configuration.ReconciliationMaxCycleSize = _distributedSettings.ReconciliationMaxCycleSize; configuration.ReconciliationMaxRemoveHashesCycleSize = _distributedSettings.ReconciliationMaxRemoveHashesCycleSize; configuration.ReconciliationMaxRemoveHashesAddPercentage = _distributedSettings.ReconciliationMaxRemoveHashesAddPercentage; ApplyIfNotNull(_distributedSettings.UseIncrementalCheckpointing, value => configuration.Checkpoint.UseIncrementalCheckpointing = value); ApplyIfNotNull(_distributedSettings.IncrementalCheckpointDegreeOfParallelism, value => configuration.Checkpoint.IncrementalCheckpointDegreeOfParallelism = value); ApplyIfNotNull(_distributedSettings.UseRedisPreventThreadTheftFeature, value => configuration.UsePreventThreadTheftFeature = value); configuration.RedisGlobalStoreConnectionString = ((PlainTextSecret)GetRequiredSecret(secrets, _distributedSettings.GlobalRedisSecretName)).Secret; if (_distributedSettings.SecondaryGlobalRedisSecretName != null) { configuration.RedisGlobalStoreSecondaryConnectionString = ((PlainTextSecret)GetRequiredSecret( secrets, _distributedSettings.SecondaryGlobalRedisSecretName)).Secret; } ApplyIfNotNull(_distributedSettings.RedisInternalLogSeverity, value => { if (!Enum.TryParse <Severity>(value, out var parsedValue)) { throw new ArgumentException($"Failed to parse `{nameof(_distributedSettings.RedisInternalLogSeverity)}` setting with value `{value}` into type `{nameof(Severity)}`"); } configuration.RedisInternalLogSeverity = parsedValue; }); ApplyIfNotNull(_distributedSettings.LocationEntryExpiryMinutes, value => configuration.LocationEntryExpiry = TimeSpan.FromMinutes(value)); ApplyIfNotNull(_distributedSettings.RestoreCheckpointAgeThresholdMinutes, v => configuration.Checkpoint.RestoreCheckpointAgeThreshold = TimeSpan.FromMinutes(v)); // Need to disable cleaning database on initialization when restore checkpoint age is set. ApplyIfNotNull(_distributedSettings.RestoreCheckpointAgeThresholdMinutes, v => dbConfig.CleanOnInitialize = false); var errorBuilder = new StringBuilder(); var storageCredentials = GetStorageCredentials(secrets, errorBuilder); Contract.Assert(storageCredentials != null && storageCredentials.Length > 0); var blobStoreConfiguration = new BlobCentralStoreConfiguration( credentials: storageCredentials, containerName: _arguments.HostInfo.AppendRingSpecifierIfNeeded("checkpoints", _distributedSettings.UseRingIsolation), checkpointsKey: "checkpoints-eventhub"); ApplyIfNotNull( _distributedSettings.CentralStorageOperationTimeoutInMinutes, value => blobStoreConfiguration.OperationTimeout = TimeSpan.FromMinutes(value)); configuration.CentralStore = blobStoreConfiguration; if (_distributedSettings.UseDistributedCentralStorage) { var distributedCentralStoreConfiguration = new DistributedCentralStoreConfiguration(localCacheRoot) { MaxRetentionGb = _distributedSettings.MaxCentralStorageRetentionGb, PropagationDelay = TimeSpan.FromSeconds(_distributedSettings.CentralStoragePropagationDelaySeconds), PropagationIterations = _distributedSettings.CentralStoragePropagationIterations, MaxSimultaneousCopies = _distributedSettings.CentralStorageMaxSimultaneousCopies }; if (_distributedSettings.UseSelfCheckSettingsForDistributedCentralStorage) { distributedCentralStoreConfiguration.SelfCheckSettings = CreateSelfCheckSettings(_distributedSettings); } distributedCentralStoreConfiguration.TraceFileSystemContentStoreDiagnosticMessages = _distributedSettings.TraceFileSystemContentStoreDiagnosticMessages; ApplyIfNotNull(_distributedSettings.DistributedCentralStoragePeerToPeerCopyTimeoutSeconds, v => distributedCentralStoreConfiguration.PeerToPeerCopyTimeout = TimeSpan.FromSeconds(v)); ApplyIfNotNull(_distributedSettings.DistributedCentralStorageImmutabilityOptimizations, v => distributedCentralStoreConfiguration.ImmutabilityOptimizations = v); configuration.DistributedCentralStore = distributedCentralStoreConfiguration; } var eventStoreConfiguration = new EventHubContentLocationEventStoreConfiguration( eventHubName: _distributedSettings.EventHubName, eventHubConnectionString: ((PlainTextSecret)GetRequiredSecret(secrets, _distributedSettings.EventHubSecretName)).Secret, consumerGroupName: _distributedSettings.EventHubConsumerGroupName, epoch: _keySpace + _distributedSettings.EventHubEpoch); dbConfig.Epoch = eventStoreConfiguration.Epoch; configuration.EventStore = eventStoreConfiguration; ApplyIfNotNull( _distributedSettings.MaxEventProcessingConcurrency, value => eventStoreConfiguration.MaxEventProcessingConcurrency = value); ApplyIfNotNull( _distributedSettings.EventBatchSize, value => eventStoreConfiguration.EventBatchSize = value); ApplyIfNotNull( _distributedSettings.EventProcessingMaxQueueSize, value => eventStoreConfiguration.EventProcessingMaxQueueSize = value); }
public static void ChangeRole(string role) { GlobalInfoStorage.SetGlobalInfo(GlobalInfoKey.LocalLocationStoreRole, role); }