Skip to content

Commit

Permalink
Keep all properties names convenient
Browse files Browse the repository at this point in the history
  • Loading branch information
direnakkoc committed Feb 22, 2023
1 parent a6bc083 commit a033267
Show file tree
Hide file tree
Showing 14 changed files with 122 additions and 128 deletions.
2 changes: 1 addition & 1 deletion cf-macro/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import _ from 'lodash'
import Ajv from 'ajv'

import alarms from '../core/alarms/alarms'
import alarms from 'slic-watch-core/alarms/alarms'
import dashboard from 'slic-watch-core/dashboards/dashboard'
import CloudFormationTemplate from 'slic-watch-core/cf-template'
import defaultConfig from 'slic-watch-core/inputs/default-config'
Expand Down
25 changes: 10 additions & 15 deletions core/alarms/alb-target-group.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ export type AlbTargetAlarmProperties = AlarmProperties & {
}

export type AlbTargetAlarm = AlarmProperties & {
targetGroupResourceName: string
loadBalancerLogicalId: string
TargetGroupResourceName: string
LoadBalancerLogicalId: string
}

/**
Expand All @@ -38,12 +38,9 @@ export function findLoadBalancersForTargetGroup (targetGroupLogicalId: string, c

// First, find Listeners with _default actions_ referencing the target group
for (const listener of Object.values(listenerResources)) {
// @ts-ignore
for (const action of listener.Properties.DefaultActions || []) {
const targetGroupArn = action?.TargetGroupArn
// @ts-ignore
if (targetGroupArn?.Ref === targetGroupLogicalId) {
// @ts-ignore
const loadBalancerLogicalId = listener.Properties.LoadBalancerArn?.Ref
if (loadBalancerLogicalId) {
allLoadBalancerLogicalIds.add(loadBalancerLogicalId)
Expand All @@ -57,10 +54,8 @@ export function findLoadBalancersForTargetGroup (targetGroupLogicalId: string, c

// Second, find ListenerRules with actions referncing the target group, then follow to the rules' listeners
for (const [listenerRuleLogicalId, listenerRule ] of Object.entries(listenerRuleResources)) {
// @ts-ignore
for (const action of listenerRule.Properties.Actions || []) {
const targetGroupArn = action.TargetGroupArn
// @ts-ignore
if (targetGroupArn.Ref === targetGroupLogicalId) {
allListenerRules[listenerRuleLogicalId] = listenerRule
break
Expand Down Expand Up @@ -159,8 +154,8 @@ export default function ALBTargetAlarms (albTargetAlarmProperties: AlbTargetAlar
const albTargetAlarmProperties: AlbTargetAlarm = {
AlarmName: `LoadBalancerHTTPCodeTarget5XXCountAlarm_${targetGroupResourceName}`,
AlarmDescription: `LoadBalancer HTTP Code Target 5XX Count ${getStatisticName(config)} for ${targetGroupResourceName} breaches ${threshold}`,
targetGroupResourceName,
loadBalancerLogicalId,
TargetGroupResourceName: targetGroupResourceName,
LoadBalancerLogicalId:loadBalancerLogicalId,
ComparisonOperator: config.ComparisonOperator,
Threshold: config.Threshold,
MetricName: 'HTTPCode_Target_5XX_Count',
Expand All @@ -186,8 +181,8 @@ export default function ALBTargetAlarms (albTargetAlarmProperties: AlbTargetAlar
const albTargetAlarmProperties: AlbTargetAlarm = {
AlarmName: `LoadBalancerUnHealthyHostCountAlarm_${targetGroupResourceName}`,
AlarmDescription: `LoadBalancer UnHealthy Host Count ${getStatisticName(config)} for ${targetGroupResourceName} breaches ${threshold}`,
targetGroupResourceName,
loadBalancerLogicalId,
TargetGroupResourceName: targetGroupResourceName,
LoadBalancerLogicalId:loadBalancerLogicalId,
ComparisonOperator: config.ComparisonOperator,
Threshold: config.Threshold,
MetricName: 'UnHealthyHostCount',
Expand All @@ -213,8 +208,8 @@ export default function ALBTargetAlarms (albTargetAlarmProperties: AlbTargetAlar
const albTargetAlarmProperties: AlbTargetAlarm = {
AlarmName: `LoadBalancerLambdaInternalErrorAlarm_${targetGroupResourceName}`,
AlarmDescription: `LoadBalancer Lambda Internal Error ${getStatisticName(config)} for ${targetGroupResourceName} breaches ${threshold}`,
targetGroupResourceName,
loadBalancerLogicalId,
TargetGroupResourceName: targetGroupResourceName,
LoadBalancerLogicalId:loadBalancerLogicalId,
ComparisonOperator: config.ComparisonOperator,
Threshold: config.Threshold,
MetricName: 'LambdaInternalError',
Expand All @@ -240,8 +235,8 @@ export default function ALBTargetAlarms (albTargetAlarmProperties: AlbTargetAlar
const albTargetAlarmProperties: AlbTargetAlarm = {
AlarmName: `LoadBalancerLambdaUserErrorAlarm_${targetGroupResourceName}`,
AlarmDescription: `LoadBalancer Lambda User Error ${getStatisticName(config)} for ${targetGroupResourceName} breaches ${threshold}`,
targetGroupResourceName,
loadBalancerLogicalId,
TargetGroupResourceName: targetGroupResourceName,
LoadBalancerLogicalId:loadBalancerLogicalId,
ComparisonOperator: config.ComparisonOperator,
Threshold: config.Threshold,
MetricName: 'LambdaUserError',
Expand Down
6 changes: 3 additions & 3 deletions core/alarms/alb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export type AlbAlarmProperties = AlarmProperties & {
}

export type AlbAlarm = AlarmProperties & {
loadBalancerResourceName: string
LoadBalancerResourceName: string
}


Expand Down Expand Up @@ -62,7 +62,7 @@ export default function ALBAlarms (albAlarmProperties: AlbAlarmProperties, conte
const albAlarmProperties:AlbAlarm = {
AlarmName:`LoadBalancerHTTPCodeELB5XXCountAlarm_${loadBalancerResourceName}` ,
AlarmDescription: `LoadBalancer HTTP Code ELB 5XX Count ${getStatisticName(config)} for ${loadBalancerResourceName} breaches ${threshold}`,
loadBalancerResourceName,
LoadBalancerResourceName: loadBalancerResourceName,
ComparisonOperator: config.ComparisonOperator,
Threshold: config.Threshold,
MetricName: 'HTTPCode_ELB_5XX_Count',
Expand All @@ -87,7 +87,7 @@ export default function ALBAlarms (albAlarmProperties: AlbAlarmProperties, conte
const albAlarmProperties: AlbAlarm = {
AlarmName:`LoadBalancerRejectedConnectionCountAlarm_${loadBalancerResourceName}` ,
AlarmDescription: `LoadBalancer Rejected Connection Count ${getStatisticName(config)} for ${loadBalancerResourceName} breaches ${threshold}`,
loadBalancerResourceName,
LoadBalancerResourceName: loadBalancerResourceName,
ComparisonOperator: config.ComparisonOperator,
Threshold: config.Threshold,
MetricName: 'RejectedConnectionCount',
Expand Down
8 changes: 4 additions & 4 deletions core/alarms/api-gateway.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export type ApiGwAlarmProperties = AlarmProperties &{
}

export type ApiAlarm= AlarmProperties & {
apiName: string
ApiName: string
}

/**
Expand Down Expand Up @@ -126,7 +126,7 @@ export default function ApiGatewayAlarms (apiGwAlarmProperties: ApiGwAlarmProper
const apiAlarmProperties:ApiAlarm = {
AlarmName: `APIGW_5XXError_${apiNameForSub}` ,
AlarmDescription: `API Gateway 5XXError ${getStatisticName(config)} for ${apiNameForSub} breaches ${threshold}`,
apiName,
ApiName: apiName,
ComparisonOperator: config.ComparisonOperator,
Threshold: config.Threshold,
MetricName: '5XXError',
Expand All @@ -151,7 +151,7 @@ export default function ApiGatewayAlarms (apiGwAlarmProperties: ApiGwAlarmProper
const apiAlarmProperties:ApiAlarm = {
AlarmName: `APIGW_4XXError_${apiNameForSub}` ,
AlarmDescription: `API Gateway 4XXError ${getStatisticName(config)} for ${apiNameForSub} breaches ${threshold}`,
apiName,
ApiName: apiName,
ComparisonOperator: config.ComparisonOperator,
Threshold: config.Threshold,
MetricName: '4XXError',
Expand All @@ -176,7 +176,7 @@ export default function ApiGatewayAlarms (apiGwAlarmProperties: ApiGwAlarmProper
const apiAlarmProperties:ApiAlarm = {
AlarmName: `APIGW_Latency_${apiNameForSub}` ,
AlarmDescription: `API Gateway Latency ${getStatisticName(config)} for ${apiNameForSub} breaches ${threshold}`,
apiName,
ApiName: apiName,
ComparisonOperator: config.ComparisonOperator,
Threshold: config.Threshold,
MetricName: 'Latency',
Expand Down
8 changes: 3 additions & 5 deletions core/alarms/appsync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export type AppSyncAlarmProperties = AlarmProperties & {
}

export type AppSyncAlarm= AlarmProperties & {
appSyncResourceName: string
AppSyncResourceName: string
}

/**
Expand Down Expand Up @@ -65,7 +65,7 @@ export default function appSyncAlarms (appSyncAlarmProperties: AppSyncAlarmPrope
const appSyncAlarmProperties:AppSyncAlarm = {
AlarmName:`AppSync5XXErrorAlarm_${graphQLName}` ,
AlarmDescription: `AppSync 5XX Error ${getStatisticName(config)} for ${graphQLName} breaches ${threshold}`,
appSyncResourceName,
AppSyncResourceName:appSyncResourceName ,
ComparisonOperator: config.ComparisonOperator,
Threshold: config.Threshold,
MetricName: '5XXError',
Expand All @@ -80,7 +80,6 @@ export default function appSyncAlarms (appSyncAlarmProperties: AppSyncAlarmPrope
]
}
return {
// @ts-ignore
resourceName: makeResourceName('AppSync', graphQLName, '5XXError'),
resource: createAlarm(appSyncAlarmProperties, context)
}
Expand All @@ -92,7 +91,7 @@ export default function appSyncAlarms (appSyncAlarmProperties: AppSyncAlarmPrope
const appSyncAlarmProperties:AppSyncAlarm = {
AlarmName:`AppSyncLatencyAlarm_${graphQLName}` ,
AlarmDescription: `AppSync Latency ${getStatisticName(config)} for ${graphQLName} breaches ${threshold}`,
appSyncResourceName,
AppSyncResourceName: appSyncResourceName,
ComparisonOperator: config.ComparisonOperator,
Threshold: config.Threshold,
MetricName: 'Latency',
Expand All @@ -107,7 +106,6 @@ export default function appSyncAlarms (appSyncAlarmProperties: AppSyncAlarmPrope
]
}
return {
// @ts-ignore
resourceName: makeResourceName('AppSync', graphQLName, 'Latency'),
resource: createAlarm(appSyncAlarmProperties, context)
}
Expand Down
12 changes: 6 additions & 6 deletions core/alarms/ecs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ export type EcsAlarmsConfig = AlarmProperties & {
}

export type EcsAlarm = AlarmProperties & {
serviceName,
clusterName: string
ServiceName: string,
ClusterName: string
}

/**
Expand Down Expand Up @@ -85,8 +85,8 @@ export default function ecsAlarms (ecsAlarmsConfig: EcsAlarmsConfig, context: Co
const ecsAlarmProperties: EcsAlarm = {
AlarmName: `ECS_MemoryAlarm_\${${logicalId}.Name}`,
AlarmDescription: `ECS memory utilization for ${logicalId}.Name breaches ${threshold}`,
serviceName: { 'Fn::GetAtt': [logicalId, 'Name'] },
clusterName,
ServiceName: `\${${logicalId}.Name}`,
ClusterName:clusterName,
ComparisonOperator: config.ComparisonOperator,
Threshold: config.Threshold,
MetricName: 'MemoryUtilization',
Expand All @@ -112,8 +112,8 @@ export default function ecsAlarms (ecsAlarmsConfig: EcsAlarmsConfig, context: Co
const ecsAlarmProperties: EcsAlarm = {
AlarmName: `ECS_CPUAlarm_\${${logicalId}.Name}`,
AlarmDescription: `ECS CPU utilization for ${logicalId}.Name breaches ${threshold}`,
serviceName: { 'Fn::GetAtt': [logicalId, 'Name'] },
clusterName,
ServiceName: `\${${logicalId}.Name}`,
ClusterName: clusterName,
ComparisonOperator: config.ComparisonOperator,
Threshold: config.Threshold,
MetricName: 'CPUUtilization',
Expand Down
6 changes: 3 additions & 3 deletions core/alarms/eventbridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export type EventsAlarmsConfig = AlarmProperties &{
}

export type EventbridgeAlarm = AlarmProperties & {
ruleName: object
RuleName: string
}

/**
Expand Down Expand Up @@ -59,7 +59,7 @@ export default function eventsAlarms (eventsAlarmsConfig: EventsAlarmsConfig, co
const eventbridgeAlarmProperties:EventbridgeAlarm = {
AlarmName: `Events_FailedInvocationsAlarm_\${${logicalId}}` ,
AlarmDescription: `EventBridge Failed Invocations for \${${logicalId}} breaches ${threshold}`,
ruleName: { Ref: logicalId },
RuleName: logicalId ,
ComparisonOperator: config.ComparisonOperator,
Threshold: config.Threshold,
MetricName: 'FailedInvocations',
Expand All @@ -82,7 +82,7 @@ export default function eventsAlarms (eventsAlarmsConfig: EventsAlarmsConfig, co
const eventbridgeAlarmProperties:EventbridgeAlarm = {
AlarmName: `Events_ThrottledRulesAlarm_\${${logicalId}}`,
AlarmDescription: `EventBridge Throttled Rules for \${${logicalId}} breaches ${threshold}`,
ruleName: { Ref: logicalId },
RuleName: logicalId,
ComparisonOperator: config.ComparisonOperator,
Threshold: config.Threshold,
MetricName: 'ThrottledRules',
Expand Down
12 changes: 6 additions & 6 deletions core/alarms/lambda.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export type LambdaFunctionAlarmPropertiess = AlarmProperties & {
}

export type LambdaAlarm = AlarmProperties & {
funcName: object
FuncName: string
}
/**
* functionAlarmPropertiess The cascaded Lambda alarm configuration with
Expand Down Expand Up @@ -123,7 +123,7 @@ export default function LambdaAlarms (functionAlarmPropertiess: FunctionAlarmPro
const lambdaAlarmProperties: LambdaAlarm = {
AlarmName: `Lambda_IteratorAge_\${${funcLogicalId}}`,
AlarmDescription: `Iterator Age for ${funcLogicalId} breaches ${threshold}`,
funcName: { Ref: funcLogicalId },
FuncName: funcLogicalId,
ComparisonOperator: config.ComparisonOperator,
Threshold: threshold,
Metrics: null,
Expand All @@ -147,7 +147,7 @@ export default function LambdaAlarms (functionAlarmPropertiess: FunctionAlarmPro
const lambdaAlarmProperties: LambdaAlarm = {
AlarmName: `Lambda_Errors_\${${funcLogicalId}}`,
AlarmDescription: `Error count for \${${funcLogicalId}} breaches ${threshold}`,
funcName: { Ref: funcLogicalId },
FuncName: `\${${funcLogicalId}}`,
ComparisonOperator: config.ComparisonOperator,
Threshold: threshold,
Metrics: null,
Expand Down Expand Up @@ -207,7 +207,7 @@ export default function LambdaAlarms (functionAlarmPropertiess: FunctionAlarmPro
const lambdaAlarmProperties: LambdaAlarm = {
AlarmName: `Lambda_Throttles_\${${funcLogicalId}}` ,
AlarmDescription: `Throttles % for \${${funcLogicalId}} breaches ${threshold}`,
funcName: { Ref: funcLogicalId },
FuncName: `\${${funcLogicalId}}`,
ComparisonOperator: config.ComparisonOperator,
Threshold: threshold,
Metrics: metrics,
Expand All @@ -227,7 +227,7 @@ export default function LambdaAlarms (functionAlarmPropertiess: FunctionAlarmPro
const lambdaAlarmProperties: LambdaAlarm = {
AlarmName: `Lambda_Duration_\${${funcLogicalId}}`,
AlarmDescription: `Max duration for \${${funcLogicalId}} breaches ${threshold}% of timeout (${funcTimeout})`,
funcName: { Ref: funcLogicalId },
FuncName: funcLogicalId,
ComparisonOperator: config.ComparisonOperator,
// @ts-ignore
Threshold: (threshold * funcTimeout * 1000) / 100,
Expand All @@ -252,7 +252,7 @@ export default function LambdaAlarms (functionAlarmPropertiess: FunctionAlarmPro
const lambdaAlarmProperties: LambdaAlarm = {
AlarmName: `Lambda_Invocations_\${${funcLogicalId}}`,
AlarmDescription: `Total invocations for \${${funcLogicalId}} breaches ${threshold}`,
funcName: { Ref: funcLogicalId },
FuncName: `\${${funcLogicalId}}`,
ComparisonOperator: config.ComparisonOperator,
Threshold: threshold,
Metrics: null,
Expand Down
6 changes: 3 additions & 3 deletions core/alarms/sns.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export type SnsAlarmsConfig = AlarmProperties & {
}

export type SnsAlarm= AlarmProperties & {
topicName: string
TopicName: string
}

/**
Expand Down Expand Up @@ -59,7 +59,7 @@ export default function snsAlarms (snsAlarmsConfig: SnsAlarmsConfig, context: Co
const snsAlarmProperties: SnsAlarm = {
AlarmName: `SNS_NumberOfNotificationsFilteredOutInvalidAttributesAlarm_\${${topicLogicalId}.TopicName}`,
AlarmDescription: `Number of SNS Notifications Filtered out Invalid Attributes for \${${topicLogicalId}.TopicName} breaches (${threshold}`,
topicName: `\${${topicLogicalId}.TopicName}`,
TopicName: `\${${topicLogicalId}.TopicName}`,
ComparisonOperator: config.ComparisonOperator,
Threshold: config.Threshold,
MetricName: 'NumberOfNotificationsFilteredOut-InvalidAttributes',
Expand All @@ -82,7 +82,7 @@ export default function snsAlarms (snsAlarmsConfig: SnsAlarmsConfig, context: Co
const snsAlarmProperties: SnsAlarm = {
AlarmName: `SNS_NumberOfNotificationsFailedAlarm_\${${topicLogicalId}.TopicName}`,
AlarmDescription: `Number of Notifications failed for \${${topicLogicalId}.TopicName} breaches (${threshold}`,
topicName: `\${${topicLogicalId}.TopicName}`,
TopicName: `\${${topicLogicalId}.TopicName}`,
ComparisonOperator: config.ComparisonOperator,
Threshold: config.Threshold,
MetricName: 'NumberOfNotificationsFailed',
Expand Down
6 changes: 3 additions & 3 deletions core/alarms/sqs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export type SqsAlarmsConfig = AlarmProperties& {
}

export type SqsAlarm= AlarmProperties & {
queueName: object
QueueName: string
}

/**
Expand Down Expand Up @@ -74,7 +74,7 @@ export default function sqsAlarms (sqsAlarmsConfig: SqsAlarmsConfig, context: Co
const sqsAlarmProperties: SqsAlarm = {
AlarmName: `SQS_ApproximateNumberOfMessagesNotVisible_\${${logicalId}.QueueName}`,
AlarmDescription: `SQS in-flight messages for \${${logicalId}.QueueName} breaches ${thresholdValue} (${threshold}% of the hard limit of ${hardLimit})`,
queueName: { 'Fn::GetAtt': [logicalId, 'QueueName'] },
QueueName: `\${${logicalId}.QueueName}`,
ComparisonOperator: config.ComparisonOperator,
Threshold: thresholdValue,
MetricName: 'ApproximateNumberOfMessagesNotVisible',
Expand All @@ -97,7 +97,7 @@ export default function sqsAlarms (sqsAlarmsConfig: SqsAlarmsConfig, context: Co
const sqsAlarmProperties: SqsAlarm = {
AlarmName: `SQS_ApproximateAgeOfOldestMessage_\${${logicalId}.QueueName}`,
AlarmDescription: `SQS age of oldest message in the queue \${${logicalId}.QueueName} breaches ${threshold}`,
queueName: { 'Fn::GetAtt': [logicalId, 'QueueName'] },
QueueName: `\${${logicalId}.QueueName}`,
ComparisonOperator: config.ComparisonOperator,
Threshold: config.Threshold,
MetricName: 'ApproximateAgeOfOldestMessage',
Expand Down
4 changes: 2 additions & 2 deletions core/alarms/step-functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export type SfAlarmsConfig = AlarmProperties& {
}

export type SmAlarm= AlarmProperties & {
stateMachineArn: object
StateMachineArn: string
}

/**
Expand Down Expand Up @@ -45,7 +45,7 @@ export default function StatesAlarms (sfAlarmProperties: SfAlarmsConfig, context
const smAlarmProperties: SmAlarm = {
AlarmName: `StepFunctions_${metric}_\${${logicalId}.Name}` ,
AlarmDescription: `StepFunctions_${metric} ${config.Statistic} for \${${logicalId}.Name} breaches ${config.Threshold}`,
stateMachineArn: { Ref: logicalId },
StateMachineArn: `\${${logicalId}}`,
ComparisonOperator: config.ComparisonOperator,
Threshold: config.Threshold,
MetricName: metric,
Expand Down
Loading

0 comments on commit a033267

Please sign in to comment.