Example #1
0
        private async Task <bool> InspectExistingAlarm(string alarmName,
                                                       double thresholdInUnits, int periodSeconds, string targetTopic)
        {
            var existingAlarm = await _alarmFinder.FindAlarmByName(alarmName);

            if (existingAlarm == null)
            {
                _logger.Info($"Table alarm {alarmName} does not already exist. Creating it at threshold {thresholdInUnits}");
                return(true);
            }

            if (!MetricAlarmHelper.AlarmActionsEqualsTarget(existingAlarm.AlarmActions, targetTopic))
            {
                _logger.Info($"Index alarm {alarmName} alarm target has changed to {targetTopic}");
                return(true);
            }


            if (!MetricAlarmHelper.AlarmAndOkActionsAreEqual(existingAlarm))
            {
                _logger.Info($"Index alarm {alarmName} alarm actions does not match ok actions");
                return(true);
            }

            if (AlarmThresholds.AreEqual(existingAlarm.Threshold, thresholdInUnits) && (existingAlarm.Period == periodSeconds))
            {
                _logger.Detail($"Table alarm {alarmName} already exists at same threshold {existingAlarm.Threshold}");
                return(false);
            }

            LogDifferences(existingAlarm, alarmName, thresholdInUnits, periodSeconds);
            return(true);
        }
Example #2
0
        public async Task EnsureWriteCapacityAlarm(TableDescription table, string alarmNameSuffix, double thresholdFraction,
                                                   string snsTopicArn, bool dryRun)
        {
            var alarmName        = GetAlarmName(table, AwsMetrics.ConsumedWriteCapacity, alarmNameSuffix);
            var thresholdInUnits = AlarmThresholds.Calulate(table.ProvisionedThroughput.WriteCapacityUnits, thresholdFraction);

            await CheckTableAlarm(alarmName, table.TableName, AwsMetrics.ConsumedWriteCapacity,
                                  thresholdInUnits, AwsConstants.FiveMinutesInSeconds, snsTopicArn, dryRun);
        }
        public async Task EnsureReadCapacityAlarm(TableDescription table, GlobalSecondaryIndexDescription index, string alarmNameSuffix,
                                                  double thresholdFraction, string snsTopicArn, bool dryRun)
        {
            var alarmName        = GetAlarmName(table, index, AwsMetrics.ConsumedReadCapacity, alarmNameSuffix);
            var thresholdInUnits = AlarmThresholds.Calulate(index.ProvisionedThroughput.ReadCapacityUnits, thresholdFraction);

            await CheckIndexAlarm(alarmName, table.TableName, index.IndexName, AwsMetrics.ConsumedReadCapacity,
                                  thresholdInUnits, AwsConstants.FiveMinutesInSeconds, snsTopicArn, dryRun);
        }
        public async Task CorrectAlarmsAreCreatedForEachTable()
        {
            var mockery   = new DynamoAlarmGeneratorMockery();
            var generator = mockery.AlarmGenerator;

            ConfigureTables(mockery);

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

            var expectedTable1ReadThreshold  = (int)AlarmThresholds.Calulate(ReadCapacity, 0.4);
            var expectedTable1WriteThreshold = (int)AlarmThresholds.Calulate(WriteCapacity, 0.4);

            CloudwatchVerify.AlarmWasPutOnTable(mockery.Cloudwatch,
                                                alarmName: "test1-ConsumedReadCapacityUnits-TestGroup",
                                                tableName: "test1",
                                                metricName: "ConsumedReadCapacityUnits",
                                                threshold: expectedTable1ReadThreshold,
                                                period: 300);

            CloudwatchVerify.AlarmWasPutOnTable(mockery.Cloudwatch,
                                                alarmName: "test1-ConsumedWriteCapacityUnits-TestGroup",
                                                tableName: "test1",
                                                metricName: "ConsumedWriteCapacityUnits",
                                                threshold: expectedTable1WriteThreshold,
                                                period: 300);

            var expectedTable2ReadThreshold  = (int)AlarmThresholds.Calulate(ReadCapacity, 0.65);
            var expectedTable2WriteThreshold = (int)AlarmThresholds.Calulate(WriteCapacity, 0.65);

            CloudwatchVerify.AlarmWasPutOnTable(mockery.Cloudwatch,
                                                alarmName: "test2-ConsumedReadCapacityUnits-TestGroup",
                                                tableName: "test2",
                                                metricName: "ConsumedReadCapacityUnits",
                                                threshold: expectedTable2ReadThreshold,
                                                period: 300);

            CloudwatchVerify.AlarmWasPutOnTable(mockery.Cloudwatch,
                                                alarmName: "test2-ConsumedWriteCapacityUnits-TestGroup",
                                                tableName: "test2",
                                                metricName: "ConsumedWriteCapacityUnits",
                                                threshold: expectedTable2WriteThreshold,
                                                period: 300);
        }
Example #5
0
        private void LogDifferences(MetricAlarm existingAlarm, string alarmName, double thresholdInUnits, int periodSeconds)
        {
            if (existingAlarm.Period != periodSeconds)
            {
                _logger.Info($"Table alarm {alarmName} period has changed from {existingAlarm.Period} to {periodSeconds}");
            }

            if (AlarmThresholds.AreEqual(existingAlarm.Threshold, thresholdInUnits))
            {
                return;
            }

            if (existingAlarm.Threshold < thresholdInUnits)
            {
                _logger.Info($"Table alarm {alarmName} already exists at lower threshold {existingAlarm.Threshold}. Will increase to {thresholdInUnits}");
            }
            else
            {
                _logger.Info($"Table alarm {alarmName} already exists at higher threshold {existingAlarm.Threshold}. Will decrease to {thresholdInUnits}");
            }
        }