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); }
private async Task <IList <Alarm> > BuildIndexAlarms(ResourceThresholds <DynamoResourceConfig> resourceConfig, AwsServiceAlarms <DynamoResourceConfig> service, AlertingGroupParameters groupParameters, AwsResource <TableDescription> parentTableEntity) { // called twice var mergedConfig = service.Options.OverrideWith(resourceConfig.Options); var result = new List <Alarm>(); var gsiSet = parentTableEntity.Resource.GlobalSecondaryIndexes; var mergedValuesByAlarmName = service.Values.OverrideWith(resourceConfig.Values); var defaults = _defaultAlarms.DynamoDbGsiRead; if (mergedConfig.MonitorWrites ?? DynamoResourceConfig.MonitorWritesDefault) { defaults = defaults.Concat(_defaultAlarms.DynamoDbGsiWrite).ToArray(); } foreach (var gsi in gsiSet) { var gsiResource = new AwsResource <GlobalSecondaryIndexDescription>(gsi.IndexName, gsi); 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, parentTableEntity.Resource, alarm.DimensionNames); var threshold = await ThresholdCalculator.ExpandThreshold(_gsiProvider, gsiResource.Resource, mergedConfig, configuredThreshold); var built = alarm.CopyWith(threshold, values); var model = new Alarm { AlarmName = $"{resourceConfig.Name}-{gsi.IndexName}-{alarm.Name}-{groupParameters.AlarmNameSuffix}", AlarmDescription = groupParameters.DefaultAlarmDescription(), // TODO: remove this property in a future PR // passing in the entity shouldn't be necessary and passing in the table entity here // when the alarm is for a GSI is an even worse hack Resource = parentTableEntity, Dimensions = dimensions, AlarmDefinition = built }; result.Add(model); } } return(result); }
private async Task <List <Alarm> > BuildAlarmsForQueue( IList <AlarmDefinition> defaults, ResourceThresholds <SqsResourceConfig> resource, PopulatedServiceAlarms <SqsResourceConfig, QueueDataV2> service, AlertingGroupParameters groupParameters, QueueDataV2 queue) { var mergedConfig = service.Options.OverrideWith(resource.Options); bool includeErrorQueues = mergedConfig.IncludeErrorQueues ?? true; var result = new List <Alarm>(); var mergedValuesByAlarmName = service.Values.OverrideWith(resource.Values); foreach (var alarm in defaults) { var dimensions = _dimensionProvider.GetDimensions(queue, alarm.DimensionNames); var values = mergedValuesByAlarmName.GetValueOrDefault(alarm.Name) ?? new AlarmValues(); var actualThreshold = alarm.Threshold.CopyWith(value: values.Threshold); var threshold = await ThresholdCalculator.ExpandThreshold(_attributeProvider, queue, mergedConfig, actualThreshold); var built = alarm.CopyWith(threshold, values); var model = new Alarm { AlarmName = $"{resource.Name}-{built.Name}-{groupParameters.AlarmNameSuffix}", AlarmDescription = groupParameters.DefaultAlarmDescription(resource), // error queues currently named as per parent queue ResourceIdentifier = resource.Name, Dimensions = dimensions, AlarmDefinition = built }; result.Add(model); } if (includeErrorQueues && queue.ErrorQueue != null) { var alarms = await BuildAlarmsForQueue(_errorQueueDefaults, resource, service, groupParameters, queue.ErrorQueue); result.AddRange(alarms); } return(result); }
private async Task <List <Alarm> > BuildTableAlarms(ResourceThresholds <DynamoResourceConfig> resourceConfig, AwsServiceAlarms <DynamoResourceConfig> service, AlertingGroupParameters groupParameters, AwsResource <TableDescription> entity) { var mergedConfig = service.Options.OverrideWith(resourceConfig.Options); var result = new List <Alarm>(); var mergedValuesByAlarmName = service.Values.OverrideWith(resourceConfig.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.Resource, 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.Resource, mergedConfig, configuredThreshold); var built = alarm.CopyWith(threshold, values); var model = new Alarm { AlarmName = $"{resourceConfig.Name}-{built.Name}-{groupParameters.AlarmNameSuffix}", AlarmDescription = groupParameters.DefaultAlarmDescription(), Resource = entity, Dimensions = dimensions, AlarmDefinition = built }; result.Add(model); } return(result); }