예제 #1
0
        /// <summary>
        /// Schedules a rule to be run over different stamps and environments.
        /// </summary>
        private void OncePerStamp(Func <RuleGeneratorArguments, IEnumerable <Instantiation> > generator, Watchlist watchlist)
        {
            foreach (var(stampId, properties) in watchlist.Entries)
            {
                var configuration = new KustoRuleConfiguration(
                    _clock,
                    _logger,
                    _alertNotifier,
                    _cslQueryProvider,
                    stampId,
                    _configuration.Environments[stampId.Environment].KustoDatabaseName,
                    properties.CacheTableName);

                var request = new RuleGeneratorArguments
                {
                    StampId = stampId,
                    DynamicStampProperties = properties,
                    BaseConfiguration      = configuration,
                    EnvironmentResources   = _environmentResources[stampId.Environment],
                };

                foreach (var rule in generator(request))
                {
                    Contract.AssertNotNull(rule.Rule);
                    _scheduler.Add(rule.Rule, rule.PollingPeriod, rule.ForceRun);
                }
            }
        }
예제 #2
0
        private IEnumerable <Instantiation> GenerateRedisAutoscalingRules(RuleGeneratorArguments 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),
            });
        }