private async Task <IList <Alarm> > CreateAlarmsForResource( IList <AlarmDefinition> defaults, ResourceThresholds <TAlarmConfig> resource, AwsServiceAlarms <TAlarmConfig> service, string groupSuffix) { var entity = await _tableSource.GetResourceAsync(resource.Name); // apply thresholds from resource or alerting group var expanded = await _builder.CopyAndUpdateDefaultAlarmsForResource(entity, defaults, service, resource); var result = new List <Alarm>(); if (entity == null) { throw new Exception($"Entity {resource.Name} not found"); } foreach (var alarm in expanded) { var dimensions = _dimensions.GetDimensions(entity.Resource, alarm.DimensionNames); var model = new Alarm { AlarmName = _builder.GetAlarmName(entity, alarm.Name, groupSuffix), Resource = entity, Dimensions = dimensions, AlarmDefinition = alarm }; result.Add(model); } return(result); }
private async Task <IEnumerable <ProvisioningReportRow> > GenerateTableReport(Table tableConfig) { var reportRows = new List <ProvisioningReportRow>(); Console.WriteLine($"Reading info about {tableConfig.Name}"); var tableResource = await _tableSource.GetResourceAsync(tableConfig.Name); var table = tableResource.Resource; try { Console.WriteLine("Reading usage data"); reportRows.Add(await GetBaseTableReport(table)); foreach (var index in table.GlobalSecondaryIndexes) { reportRows.Add(await GetIndexReport(table, index)); } } catch (Exception ex) { Console.Error.WriteLine($"Error when reading to generate report for {tableConfig.Name}"); Console.Error.WriteLine(ex.ToString()); } return(reportRows); }
private async Task <IList <Alarm> > GetAlarms(IList <AlarmDefinition> alarms, ResourceThresholds <TAlarmConfig> awsResource, TAlarmConfig configuration, string groupSuffix) { var result = new List <Alarm>(); var entity = await _tableSource.GetResourceAsync(awsResource.Name); if (entity == null) { throw new Exception($"Entity {awsResource.Name} not found"); } // expand dynamic thresholds foreach (var alarm in alarms) { alarm.Threshold = await ExpandThreshold(entity.Resource, configuration, alarm.Threshold); var dimensions = _dimensions.GetDimensions(entity.Resource, alarm.DimensionNames); var model = new Alarm { AlarmName = GetAlarmName(entity, alarm.Name, groupSuffix), Resource = entity, Dimensions = dimensions, AlarmDefinition = alarm }; result.Add(model); } return(result); }
private async Task <IList <Alarm> > GetAlarms(IList <AlarmDefinition> alarms, ResourceThresholds awsResource, ServiceAlertingGroup group) { var result = new List <Alarm>(); var entity = await _tableSource.GetResourceAsync(awsResource.Name); if (entity == null) { throw new Exception($"Entity {awsResource.Name} not found"); } // expand dynamic thresholds foreach (var alarm in alarms) { alarm.Threshold = ExpandThreshold(entity.Resource, alarm.Threshold); var dimensions = _dimensions.GetDimensions(entity.Resource, alarm.DimensionNames); var model = new Alarm { AlarmName = GetAlarmName(entity, alarm.Name, group.AlarmNameSuffix), Resource = entity, AlarmDefinition = alarm, AlertingGroup = group, Dimensions = dimensions }; result.Add(model); } return(result); }
private async Task EnsureReadAlarms(AlarmTables alarmTables, Table table) { try { var tableResource = await _tableSource.GetResourceAsync(table.Name); if (tableResource == null) { _logger.Info($"Skipping named table {table.Name} as it does not exist"); return; } var tableDescription = tableResource.Resource; var threshold = table.Threshold ?? alarmTables.Threshold; await _tableAlarmCreator.EnsureReadCapacityAlarm(tableDescription, alarmTables.AlarmNameSuffix, threshold, alarmTables.SnsTopicArn, alarmTables.DryRun); var monitorThrottling = table.MonitorThrottling ?? alarmTables.MonitorThrottling; var throttlingThreshold = table.ThrottlingThreshold ?? alarmTables.ThrottlingThreshold; if (monitorThrottling) { await _tableAlarmCreator.EnsureReadThrottleAlarm(tableDescription, alarmTables.AlarmNameSuffix, throttlingThreshold, alarmTables.SnsTopicArn, alarmTables.DryRun); } foreach (var index in tableDescription.GlobalSecondaryIndexes) { await _indexAlarmCreator.EnsureReadCapacityAlarm(tableDescription, index, alarmTables.AlarmNameSuffix, threshold, alarmTables.SnsTopicArn, alarmTables.DryRun); if (monitorThrottling) { await _indexAlarmCreator.EnsureReadThrottleAlarm(tableDescription, index, alarmTables.AlarmNameSuffix, throttlingThreshold, alarmTables.SnsTopicArn, alarmTables.DryRun); } } } catch (Exception ex) { _logger.Error(ex, $"Error when creating table read alarm for {table.Name}"); throw; } }
private async Task <IList <Alarm> > CreateAlarmsForResource( ResourceThresholds <SqsResourceConfig> resource, AwsServiceAlarms <SqsResourceConfig> service, AlertingGroupParameters groupParameters) { var entity = await _queueSource.GetResourceAsync(resource.Name); if (entity == null) { throw new Exception($"Entity {resource.Name} not found"); } var queueResource = new AwsResource <QueueDataV2>(entity.Name, entity.Resource); var alarms = await BuildAlarmsForQueue(_defaultAlarms, resource, service, groupParameters, queueResource); return(alarms); }
private async Task <IList <Alarm> > CreateAlarmsForResource( ResourceThresholds <DynamoResourceConfig> resource, AwsServiceAlarms <DynamoResourceConfig> service, AlertingGroupParameters groupParameters) { var entity = await _tableSource.GetResourceAsync(resource.Name); if (entity == null) { throw new Exception($"Entity {resource.Name} not found"); } var result = await BuildTableAlarms(resource, service, groupParameters, entity); result.AddRange(await BuildIndexAlarms(resource, service, groupParameters, entity)); return(result); }
private async Task <IList <Alarm> > CreateAlarmsForResource( ResourceThresholds <TAlarmConfig> resource, AwsServiceAlarms <TAlarmConfig> service, AlertingGroupParameters groupParameters) { var entity = await _tableSource.GetResourceAsync(resource.Name); if (entity == null) { throw new Exception($"Entity {resource.Name} not found"); } var mergedConfig = service.Options.OverrideWith(resource.Options); var mergedValuesByAlarmName = service.Values.OverrideWith(resource.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.Resource, alarm.DimensionNames); var threshold = await ThresholdCalculator.ExpandThreshold(_attributeProvider, entity.Resource, mergedConfig, configuredThreshold); var built = alarm.CopyWith(threshold, values); var model = new Alarm { AlarmName = $"{resource.Name}-{built.Name}-{groupParameters.AlarmNameSuffix}", AlarmDescription = groupParameters.DefaultAlarmDescription(), Resource = entity, Dimensions = dimensions, AlarmDefinition = built }; result.Add(model); } return(result); }
private async Task <IList <Alarm> > CreateAlarmsForResource( ResourceThresholds <DynamoResourceConfig> resource, AwsServiceAlarms <DynamoResourceConfig> service, AlertingGroupParameters groupParameters) { var entity = await _tableSource.GetResourceAsync(resource.Name); if (entity == null) { _logger.Error($"Skipping table {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); }