Ejemplo n.º 1
0
        private static ResourceAndThresholdsPair <TConfig, T> PatternToTable(
            ResourceThresholds <TConfig> pattern, AwsResource <T> resource)
        {
            pattern = pattern.AsNamed(resource.Name);

            var matched = new ResourceAndThresholdsPair <TConfig, T>(pattern, resource);

            return(matched);
        }
        private async Task <IList <Alarm> > BuildIndexAlarms(ResourceAndThresholdsPair <DynamoResourceConfig, TableDescription> resourceConfig,
                                                             PopulatedServiceAlarms <DynamoResourceConfig, TableDescription> service,
                                                             AlertingGroupParameters groupParameters,
                                                             TableDescription parentTableDescription)
        {
            // called twice
            var mergedConfig = service.Options.OverrideWith(resourceConfig.Definition.Options);

            var result = new List <Alarm>();

            var gsiSet = parentTableDescription.GlobalSecondaryIndexes;

            var mergedValuesByAlarmName = service.Values
                                          .OverrideWith(resourceConfig.Definition.Values);

            var defaults = _defaultAlarms.DynamoDbGsiRead;

            if (mergedConfig.MonitorWrites ?? DynamoResourceConfig.MonitorWritesDefault)
            {
                defaults = defaults.Concat(_defaultAlarms.DynamoDbGsiWrite).ToArray();
            }

            foreach (var gsi in gsiSet)
            {
                foreach (var alarm in defaults)
                {
                    var values = mergedValuesByAlarmName.GetValueOrDefault(alarm.Name) ?? new AlarmValues();
                    var configuredThreshold = alarm.Threshold.CopyWith(value: values.Threshold);
                    var dimensions          = _gsiProvider.GetDimensions(gsi, parentTableDescription, alarm.DimensionNames);

                    if (mergedConfig.ThresholdIsAbsolute ?? DynamoResourceConfig.ThresholdIsAbsoluteDefault)
                    {
                        configuredThreshold.ThresholdType = ThresholdType.Absolute;
                    }

                    var threshold = await ThresholdCalculator.ExpandThreshold(_gsiProvider,
                                                                              gsi,
                                                                              mergedConfig,
                                                                              configuredThreshold);

                    var built = alarm.CopyWith(threshold, values);

                    var model = new Alarm
                    {
                        AlarmName          = $"{resourceConfig.Resource.Name}-{gsi.IndexName}-{alarm.Name}-{groupParameters.AlarmNameSuffix}",
                        AlarmDescription   = groupParameters.DefaultAlarmDescription(resourceConfig.Definition),
                        ResourceIdentifier = resourceConfig.Resource.Name,
                        Dimensions         = dimensions,
                        AlarmDefinition    = built
                    };

                    result.Add(model);
                }
            }

            return(result);
        }
Ejemplo n.º 3
0
        private async Task <List <Alarm> > BuildTableAlarms(ResourceAndThresholdsPair <DynamoResourceConfig, TableDescription> resourceConfig,
                                                            PopulatedServiceAlarms <DynamoResourceConfig, TableDescription> service,
                                                            AlertingGroupParameters groupParameters,
                                                            TableDescription entity)
        {
            var mergedConfig = service.Options.OverrideWith(resourceConfig.Definition.Options);

            var result = new List <Alarm>();

            var mergedValuesByAlarmName = service.Values.OverrideWith(resourceConfig.Definition.Values);

            var defaults = _defaultAlarms.DynamoDbRead;

            if (mergedConfig.MonitorWrites ?? DynamoResourceConfig.MonitorWritesDefault)
            {
                defaults = defaults.Concat(_defaultAlarms.DynamoDbWrite).ToArray();
            }

            foreach (var alarm in defaults)
            {
                var dimensions          = _dimensions.GetDimensions(entity, alarm.DimensionNames);
                var values              = mergedValuesByAlarmName.GetValueOrDefault(alarm.Name) ?? new AlarmValues();
                var configuredThreshold = alarm.Threshold.CopyWith(value: values.Threshold);

                if (mergedConfig.ThresholdIsAbsolute ?? DynamoResourceConfig.ThresholdIsAbsoluteDefault)
                {
                    configuredThreshold.ThresholdType = ThresholdType.Absolute;
                }

                var threshold = await ThresholdCalculator.ExpandThreshold(_attributeProvider,
                                                                          entity,
                                                                          mergedConfig,
                                                                          configuredThreshold);

                var built = alarm.CopyWith(threshold, values);

                var model = new Alarm
                {
                    AlarmName          = $"{resourceConfig.Resource.Name}-{built.Name}-{groupParameters.AlarmNameSuffix}",
                    AlarmDescription   = groupParameters.DefaultAlarmDescription(),
                    ResourceIdentifier = resourceConfig.Resource.Name,
                    Dimensions         = dimensions,
                    AlarmDefinition    = built
                };

                result.Add(model);
            }

            return(result);
        }
        private static ResourceAndThresholdsPair <TConfig, T> PatternToTable(
            ResourceThresholds <TConfig> pattern, AwsResource <T> resource)
        {
            var config = new ResourceThresholds <TConfig>
            {
                Name    = resource.Name,
                Pattern = null,
                Values  = pattern.Values,
                Options = pattern.Options
            };

            var matched = new ResourceAndThresholdsPair <TConfig, T>(config, resource);

            return(matched);
        }
Ejemplo n.º 5
0
        private async Task<IList<Alarm>> CreateAlarmsForResource(
            ResourceAndThresholdsPair<SqsResourceConfig, QueueDataV2> resource,
            PopulatedServiceAlarms<SqsResourceConfig, QueueDataV2> service,
            AlertingGroupParameters groupParameters)
        {
            var entity = await resource.Resource.GetFullResource();

            if (entity == null)
            {
                throw new Exception($"Entity {resource.Resource.Name} not found");
            }

            var mergedConfig = service.Options.OverrideWith(resource.Definition.Options);
            var includeErrorQueues = mergedConfig.IncludeErrorQueues ?? true;

            var result = new List<Alarm>();

            // get working queue alarms
            if (entity.WorkingQueue != null)
            {
                var alarms = await BuildAlarmsForQueue(_defaultAlarms,
                    mergedConfig,
                    resource.Definition,
                    service,
                    groupParameters,
                    entity.WorkingQueue);

                result.AddRange(alarms);
            }

            // get error queue alarms
            if (includeErrorQueues && entity.ErrorQueue != null)
            {
                var alarms = await BuildAlarmsForQueue(_errorQueueDefaults,
                    mergedConfig,
                    resource.Definition,
                    service,
                    groupParameters,
                    entity.ErrorQueue);

                result.AddRange(alarms);
            }

            return result;
        }
        private async Task <IList <Alarm> > CreateAlarmsForResource(
            ResourceAndThresholdsPair <TAlarmConfig, T> resource,
            PopulatedServiceAlarms <TAlarmConfig, T> service,
            AlertingGroupParameters groupParameters)
        {
            var entity = await resource.Resource.GetFullResource();

            if (entity == null)
            {
                throw new Exception($"Entity {resource.Resource.Name} not found");
            }

            var mergedConfig            = service.Options.OverrideWith(resource.Definition.Options);
            var mergedValuesByAlarmName = service.Values.OverrideWith(resource.Definition.Values);

            var result = new List <Alarm>();

            foreach (var alarm in _defaultAlarms)
            {
                var values = mergedValuesByAlarmName.GetValueOrDefault(alarm.Name) ?? new AlarmValues();
                var configuredThreshold = alarm.Threshold.CopyWith(value: values.Threshold);
                var dimensions          = _dimensions.GetDimensions(entity, alarm.DimensionNames);
                var threshold           = await ThresholdCalculator.ExpandThreshold(_attributeProvider,
                                                                                    entity,
                                                                                    mergedConfig,
                                                                                    configuredThreshold);

                var built = alarm.CopyWith(threshold, values);

                var model = new Alarm
                {
                    AlarmName          = $"{resource.Resource.Name}-{built.Name}-{groupParameters.AlarmNameSuffix}",
                    AlarmDescription   = groupParameters.DefaultAlarmDescription(),
                    ResourceIdentifier = resource.Resource.Name,
                    Dimensions         = dimensions,
                    AlarmDefinition    = built
                };

                result.Add(model);
            }

            return(result);
        }
        private async Task <IList <Alarm> > CreateAlarmsForResource(
            ResourceAndThresholdsPair <DynamoResourceConfig, TableDescription> resource,
            PopulatedServiceAlarms <DynamoResourceConfig, TableDescription> service,
            AlertingGroupParameters groupParameters)
        {
            var entity = await resource.Resource.GetFullResource();

            if (entity == null)
            {
                _logger.Error($"Skipping table {resource.Resource.Name} as it does not exist");
                return(Array.Empty <Alarm>());
            }

            var result = await BuildTableAlarms(resource, service, groupParameters, entity);

            result.AddRange(await BuildIndexAlarms(resource, service, groupParameters, entity));

            return(result);
        }
        private async Task <IList <Alarm> > CreateAlarmsForResource(
            ResourceAndThresholdsPair <SqsResourceConfig, QueueDataV2> resource,
            PopulatedServiceAlarms <SqsResourceConfig, QueueDataV2> service,
            AlertingGroupParameters groupParameters)
        {
            var entity = await resource.Resource.GetFullResource();

            if (entity == null)
            {
                throw new Exception($"Entity {resource.Resource.Name} not found");
            }

            var alarms = await BuildAlarmsForQueue(_defaultAlarms,
                                                   resource.Definition,
                                                   service,
                                                   groupParameters,
                                                   entity);

            return(alarms);
        }