/// <summary> /// Schedules a rule to be run over different stamps and environments. /// </summary> private void OncePerStamp(Func <SingleStampRuleArguments, IEnumerable <Instantiation> > generator, Watchlist watchlist) { foreach (var(stampId, properties) in watchlist.Entries) { var environmentConfiguration = _configuration.Environments[stampId.Environment]; var resources = _environmentResources[stampId.Environment]; var configuration = new SingleStampRuleConfiguration( _clock, _logger, _alertNotifier, resources.KustoQueryClient, _icmClient, environmentConfiguration.KustoDatabaseName, properties.CacheTableName, stampId); var request = new SingleStampRuleArguments { StampId = stampId, DynamicStampProperties = properties, BaseConfiguration = configuration, EnvironmentResources = resources, }; foreach (var rule in generator(request)) { Contract.AssertNotNull(rule.Rule); _scheduler.Add(rule.Rule, rule.PollingPeriod, rule.ForceRun); } } }
private IEnumerable <Instantiation> GenerateRedisAutoscalingRules(SingleStampRuleArguments arguments) { if (!arguments.DynamicStampProperties.RedisAutoscalingEnabled) { yield break; } var autoscalingAgentConfiguration = new RedisAutoscalingAgent.Configuration(); if (arguments.DynamicStampProperties.RedisAutoscalingMaximumClusterMemoryAllowedMb > 0) { autoscalingAgentConfiguration.MaximumClusterMemoryAllowedMb = arguments.DynamicStampProperties.RedisAutoscalingMaximumClusterMemoryAllowedMb; } var redisAutoscalingAgent = new RedisAutoscalingAgent(autoscalingAgentConfiguration, arguments.EnvironmentResources.MonitorManagementClient); var configuration = new RedisAutoscalingRule.Configuration(arguments.BaseConfiguration); var primaryRedisInstance = RedisInstance .FromPreloaded(arguments.EnvironmentResources.Azure, arguments.EnvironmentResources.RedisCaches[arguments.StampId.PrimaryRedisName]) .ThrowIfFailure(); var secondaryRedisInstance = RedisInstance .FromPreloaded(arguments.EnvironmentResources.Azure, arguments.EnvironmentResources.RedisCaches[arguments.StampId.SecondaryRedisName]) .ThrowIfFailure(); yield return(new Instantiation { Rule = new RedisAutoscalingRule(configuration, redisAutoscalingAgent, primaryRedisInstance, secondaryRedisInstance), PollingPeriod = TimeSpan.FromMinutes(10), }); }
private IEnumerable <Instantiation> GenerateRedisAutoscalingRules(SingleStampRuleArguments arguments) { if (!arguments.DynamicStampProperties.RedisAutoscalingEnabled) { yield break; } if (!arguments.EnvironmentResources.RedisCaches.ContainsKey(arguments.StampId.PrimaryRedisName) || !arguments.EnvironmentResources.RedisCaches.ContainsKey(arguments.StampId.SecondaryRedisName)) { _logger.Error($"Attempt to create Redis autoscaler for stamp `{arguments.StampId}` failed due to missing Redis instance. Skipping rule"); yield break; } var autoscalingAgentConfiguration = new RedisAutoscalingAgent.Configuration(); if (arguments.DynamicStampProperties.RedisAutoscalingMaximumClusterMemoryAllowedMb > 0) { autoscalingAgentConfiguration.MaximumClusterMemoryAllowedMb = arguments.DynamicStampProperties.RedisAutoscalingMaximumClusterMemoryAllowedMb; } var azureMetricsClient = new AzureMetricsClient(arguments.EnvironmentResources.MonitorManagementClient); var redisAutoscalingAgent = new RedisAutoscalingAgent(autoscalingAgentConfiguration, azureMetricsClient); var configuration = new RedisAutoscalingRule.Configuration(arguments.BaseConfiguration); var primaryRedisInstance = RedisInstance .FromPreloaded( arguments.EnvironmentResources.Azure, arguments.EnvironmentResources.RedisCaches[arguments.StampId.PrimaryRedisName], readOnly: _configuration.ReadOnly) .ThrowIfFailure(); var secondaryRedisInstance = RedisInstance .FromPreloaded( arguments.EnvironmentResources.Azure, arguments.EnvironmentResources.RedisCaches[arguments.StampId.SecondaryRedisName], readOnly: _configuration.ReadOnly) .ThrowIfFailure(); yield return(new Instantiation { Rule = new RedisAutoscalingRule(configuration, redisAutoscalingAgent, primaryRedisInstance, secondaryRedisInstance), PollingPeriod = TimeSpan.FromMinutes(10), }); }