public async Task MainAndErrorQueuesAreMonitoredAtDifferentThresholds()
        {
            var queueSource = new Mock <IResourceSource <QueueData> >();

            VerifyQueues.ReturnsQueues(queueSource, new List <string> {
                "prod-pattern-queue", "prod-pattern-queue_error"
            });

            var alarmCreator           = new Mock <IQueueAlarmCreator>();
            var snsTopicCreator        = new Mock <ISnsTopicCreator>();
            var snsSubscriptionCreator = new Mock <ISnsSubscriptionCreator>();

            var snsCreator = new SnsCreator(snsTopicCreator.Object, snsSubscriptionCreator.Object);

            var config = MakePatternConfig();

            var populator = new QueueNamePopulator(new ConsoleAlarmLogger(false),
                                                   queueSource.Object);

            var generator = new SqsAlarmGenerator(
                new ConsoleAlarmLogger(false), queueSource.Object,
                populator, alarmCreator.Object,
                snsCreator);


            await generator.GenerateAlarmsFor(config, RunMode.GenerateAlarms);

            VerifyQueues.EnsureLengthAlarm(alarmCreator, "prod-pattern-queue", 10, false);
            VerifyQueues.EnsureOldestMessageAlarm(alarmCreator, "prod-pattern-queue", 600, false);

            VerifyQueues.EnsureLengthAlarm(alarmCreator, "prod-pattern-queue_error", 1, false);
            VerifyQueues.NoOldestMessageAlarm(alarmCreator, "prod-pattern-queue_error");
        }
        public async Task AlertingGroupCanTurnOffErrorQueueMonitoring()
        {
            var queueSource = new Mock <IResourceSource <QueueData> >();

            VerifyQueues.ReturnsQueues(queueSource, new List <string> {
                "pattern1", "pattern1_error"
            });

            var alarmCreator           = new Mock <IQueueAlarmCreator>();
            var snsTopicCreator        = new Mock <ISnsTopicCreator>();
            var snsSubscriptionCreator = new Mock <ISnsSubscriptionCreator>();

            var snsCreator = new SnsCreator(snsTopicCreator.Object, snsSubscriptionCreator.Object);

            var config = MakePatternConfig();
            var sqs    = config.AlertingGroups[0].Sqs;

            sqs.Errors = new ErrorQueue
            {
                Monitored = false
            };

            var populator = new QueueNamePopulator(new ConsoleAlarmLogger(false),
                                                   queueSource.Object);

            var generator = new SqsAlarmGenerator(
                new ConsoleAlarmLogger(false), queueSource.Object,
                populator, alarmCreator.Object,
                snsCreator);

            await generator.GenerateAlarmsFor(config, RunMode.GenerateAlarms);

            VerifyQueues.NoLengthAlarm(alarmCreator, "pattern1_error");
            VerifyQueues.NoOldestMessageAlarm(alarmCreator, "pattern1_error");
        }
        public async Task ExtraQueuesInResourcesShouldBeIgnored()
        {
            var queueSource = new Mock <IResourceSource <QueueData> >();

            VerifyQueues.ReturnsQueues(queueSource, new List <string>
            {
                "aa_nomatch_queue",
                "prod-pattern-queue",
                "prod-pattern-queue-two",
                "zz_nomatch_queue"
            });

            var alarmCreator           = new Mock <IQueueAlarmCreator>();
            var snsTopicCreator        = new Mock <ISnsTopicCreator>();
            var snsSubscriptionCreator = new Mock <ISnsSubscriptionCreator>();

            var snsCreator = new SnsCreator(snsTopicCreator.Object, snsSubscriptionCreator.Object);

            var config = MakePatternConfig();

            var populator = new QueueNamePopulator(new ConsoleAlarmLogger(false),
                                                   queueSource.Object);

            var generator = new SqsAlarmGenerator(
                new ConsoleAlarmLogger(false), queueSource.Object,
                populator, alarmCreator.Object,
                snsCreator);

            await generator.GenerateAlarmsFor(config, RunMode.GenerateAlarms);

            VerifyQueues.EnsureLengthAlarm(alarmCreator, "prod-pattern-queue", 10, false);
            VerifyQueues.EnsureLengthAlarm(alarmCreator, "prod-pattern-queue-two", 10, false);
            VerifyQueues.NoLengthAlarm(alarmCreator, "aa_nomatch_queue");
            VerifyQueues.NoLengthAlarm(alarmCreator, "zz_nomatch_queue");
        }
        public async Task GenerateAlarmsRunShouldCallQueueAlarmCreator()
        {
            var queueSource = new Mock <IResourceSource <QueueData> >();

            VerifyQueues.ReturnsQueues(queueSource, new List <string> {
                "queue1"
            });

            var alarmCreator           = new Mock <IQueueAlarmCreator>();
            var snsTopicCreator        = new Mock <ISnsTopicCreator>();
            var snsSubscriptionCreator = new Mock <ISnsSubscriptionCreator>();

            var snsCreator = new SnsCreator(snsTopicCreator.Object, snsSubscriptionCreator.Object);

            var config = MakeSimpleConfig();

            var populator = new QueueNamePopulator(new ConsoleAlarmLogger(false),
                                                   queueSource.Object);

            var generator = new SqsAlarmGenerator(
                new ConsoleAlarmLogger(false), queueSource.Object,
                populator, alarmCreator.Object,
                snsCreator);

            await generator.GenerateAlarmsFor(config, RunMode.GenerateAlarms);

            VerifyQueues.EnsureLengthAlarm(alarmCreator, "queue1", false);
        }
        public DynamoAlarmGeneratorMockery()
        {
            Cloudwatch  = new Mock <IAmazonCloudWatch>();
            AlarmFinder = new Mock <IAlarmFinder>();

            SnsTopicCreator        = new Mock <ISnsTopicCreator>();
            SnsSubscriptionCreator = new Mock <ISnsSubscriptionCreator>();

            TableLoader = new Mock <IResourceSource <TableDescription> >();

            var logger             = new ConsoleAlarmLogger(false);
            var tableNamePopulator = new TableNamePopulator(logger, TableLoader.Object);
            var snsCreator         = new SnsCreator(SnsTopicCreator.Object, SnsSubscriptionCreator.Object);

            var tableAlarmCreator = new TableAlarmCreator(Cloudwatch.Object, AlarmFinder.Object, logger, Mock.Of <ILegacyAlarmTracker>());
            var indexAlarmCreator = new IndexAlarmCreator(Cloudwatch.Object, AlarmFinder.Object, logger, Mock.Of <ILegacyAlarmTracker>());

            AlarmGenerator = new DynamoAlarmGenerator(
                logger,
                tableNamePopulator,
                tableAlarmCreator,
                indexAlarmCreator,
                snsCreator,
                TableLoader.Object);
        }
Beispiel #6
0
 public SqsAlarmGenerator(IAlarmLogger logger,
                          IResourceSource <QueueData> queueSource,
                          QueueNamePopulator queueNamePopulator,
                          IQueueAlarmCreator queueAlarmCreator,
                          SnsCreator snsCreator)
 {
     _logger             = logger;
     _queueSource        = queueSource;
     _queueNamePopulator = queueNamePopulator;
     _queueAlarmCreator  = queueAlarmCreator;
     _snsCreator         = snsCreator;
 }
        public async Task NamedQueueShouldAlsoMonitorMatchingErrorQueue()
        {
            var queueSource = new Mock <IResourceSource <QueueData> >();

            VerifyQueues.ReturnsQueues(queueSource, new List <string>
            {
                "prod-pattern-queue",
                "prod-pattern-queue_error",
                "some-other-queue"
            });

            var alarmCreator           = new Mock <IQueueAlarmCreator>();
            var snsTopicCreator        = new Mock <ISnsTopicCreator>();
            var snsSubscriptionCreator = new Mock <ISnsSubscriptionCreator>();

            var snsCreator = new SnsCreator(snsTopicCreator.Object, snsSubscriptionCreator.Object);

            var config    = MakeSimpleConfig();
            var sqsConfig = config.AlertingGroups[0].Sqs;

            sqsConfig.LengthThreshold = 11;
            sqsConfig.Errors          = new ErrorQueue
            {
                Monitored       = true,
                LengthThreshold = 7
            };

            sqsConfig.Queues = new List <Queue>
            {
                new Queue
                {
                    Name = "prod-pattern-queue"
                }
            };

            var populator = new QueueNamePopulator(new ConsoleAlarmLogger(false),
                                                   queueSource.Object);

            var generator = new SqsAlarmGenerator(
                new ConsoleAlarmLogger(false), queueSource.Object,
                populator, alarmCreator.Object,
                snsCreator);

            await generator.GenerateAlarmsFor(config, RunMode.GenerateAlarms);

            VerifyQueues.EnsureLengthAlarm(alarmCreator, "prod-pattern-queue", 11, false);
            VerifyQueues.EnsureLengthAlarm(alarmCreator, "prod-pattern-queue_error", 7, false);
            VerifyQueues.NoLengthAlarm(alarmCreator, "some-other-queue");
        }
Beispiel #8
0
 public DynamoAlarmGenerator(
     IAlarmLogger logger,
     TableNamePopulator populator,
     ITableAlarmCreator tableAlarmCreator,
     IIndexAlarmCreator indexAlarmCreator,
     SnsCreator snsCreator,
     IResourceSource <TableDescription> tableSource)
 {
     _logger            = logger;
     _populator         = populator;
     _tableAlarmCreator = tableAlarmCreator;
     _indexAlarmCreator = indexAlarmCreator;
     _snsCreator        = snsCreator;
     _tableSource       = tableSource;
 }
        public async Task QueueValuesAreUsedAsOverride()
        {
            var queueSource = new Mock <IResourceSource <QueueData> >();

            VerifyQueues.ReturnsQueues(queueSource, new List <string> {
                "pattern1", "pattern1_error"
            });

            var alarmCreator           = new Mock <IQueueAlarmCreator>();
            var snsTopicCreator        = new Mock <ISnsTopicCreator>();
            var snsSubscriptionCreator = new Mock <ISnsSubscriptionCreator>();

            var snsCreator = new SnsCreator(snsTopicCreator.Object, snsSubscriptionCreator.Object);

            var config = MakePatternConfig();
            var sqs    = config.AlertingGroups[0].Sqs;

            sqs.Errors = new ErrorQueue
            {
                LengthThreshold        = 142,
                OldestMessageThreshold = 112
            };
            sqs.Queues[0].LengthThreshold        = 42;
            sqs.Queues[0].OldestMessageThreshold = 12;

            var populator = new QueueNamePopulator(new ConsoleAlarmLogger(false),
                                                   queueSource.Object);

            var generator = new SqsAlarmGenerator(
                new ConsoleAlarmLogger(false), queueSource.Object,
                populator, alarmCreator.Object,
                snsCreator);

            await generator.GenerateAlarmsFor(config, RunMode.GenerateAlarms);

            VerifyQueues.EnsureLengthAlarm(alarmCreator, "pattern1", 42, false);
            VerifyQueues.EnsureOldestMessageAlarm(alarmCreator, "pattern1", 12, false);

            VerifyQueues.EnsureLengthAlarm(alarmCreator, "pattern1_error", 1, false);
            VerifyQueues.NoOldestMessageAlarm(alarmCreator, "pattern1_error");
        }
        public async Task AlertingGroupThresholdsAreUsedByDefault()
        {
            var queueSource = new Mock <IResourceSource <QueueData> >();

            VerifyQueues.ReturnsQueues(queueSource, new List <string> {
                "prod-pattern-queue", "prod-pattern-queue_error"
            });

            var alarmCreator           = new Mock <IQueueAlarmCreator>();
            var snsTopicCreator        = new Mock <ISnsTopicCreator>();
            var snsSubscriptionCreator = new Mock <ISnsSubscriptionCreator>();

            var snsCreator = new SnsCreator(snsTopicCreator.Object, snsSubscriptionCreator.Object);

            var config = MakePatternConfig();
            var sqs    = config.AlertingGroups[0].Sqs;

            sqs.LengthThreshold        = 32;
            sqs.OldestMessageThreshold = 17;

            sqs.Queues[0].LengthThreshold        = null;
            sqs.Queues[0].OldestMessageThreshold = null;

            var populator = new QueueNamePopulator(new ConsoleAlarmLogger(false),
                                                   queueSource.Object);

            var generator = new SqsAlarmGenerator(
                new ConsoleAlarmLogger(false), queueSource.Object,
                populator, alarmCreator.Object,
                snsCreator);


            await generator.GenerateAlarmsFor(config, RunMode.GenerateAlarms);

            VerifyQueues.EnsureLengthAlarm(alarmCreator, "prod-pattern-queue", 32, false);
            VerifyQueues.EnsureOldestMessageAlarm(alarmCreator, "prod-pattern-queue", 17, false);
        }