Skip to content

Commit

Permalink
Fix values for alarms dimensions
Browse files Browse the repository at this point in the history
  • Loading branch information
direnakkoc committed Feb 22, 2023
1 parent a033267 commit b896260
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 36 deletions.
3 changes: 2 additions & 1 deletion .eslintrc.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ module.exports = {
rules: {
'@typescript-eslint/no-var-requires': 0, // todo remove later complains for all js modules
'no-undef':0, // todo remove later
'@typescript-eslint/ban-ts-comment': 0 //todo remove ts-ignore in modules and remove this rule
'@typescript-eslint/ban-ts-comment': 0, //todo remove ts-ignore in modules and remove this rule
'@typescript-eslint/no-explicit-any' : 0 // used for dimensions value
},
ignorePatterns: ['core/coverage'],
}
14 changes: 7 additions & 7 deletions core/alarms/eventbridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ export default function eventsAlarms (eventsAlarmsConfig: EventsAlarmsConfig, co
function createFailedInvocationsAlarm (logicalId: string, ruleResource: Resource, config: AlarmProperties) {
const threshold = config.Threshold
const eventbridgeAlarmProperties:EventbridgeAlarm = {
AlarmName: `Events_FailedInvocationsAlarm_\${${logicalId}}` ,
AlarmName: `Events_FailedInvocationsAlarm_${logicalId}` ,
AlarmDescription: `EventBridge Failed Invocations for \${${logicalId}} breaches ${threshold}`,
RuleName: logicalId ,
RuleName: `${logicalId}`,
ComparisonOperator: config.ComparisonOperator,
Threshold: config.Threshold,
MetricName: 'FailedInvocations',
Expand All @@ -69,7 +69,7 @@ export default function eventsAlarms (eventsAlarmsConfig: EventsAlarmsConfig, co
EvaluationPeriods: config.EvaluationPeriods,
TreatMissingData: config.TreatMissingData,
Namespace: 'AWS/Events',
Dimensions: [{ Name: 'RuleName', Value: `\${${logicalId}}`}]
Dimensions: [{ Name: 'RuleName', Value: {Ref: logicalId} as any}]
}
return {
resourceName: `slicWatchEventsFailedInvocationsAlarm${logicalId}`,
Expand All @@ -80,9 +80,9 @@ export default function eventsAlarms (eventsAlarmsConfig: EventsAlarmsConfig, co
function createThrottledRulesAlarm (logicalId: string, ruleResource: Resource, config: AlarmProperties) {
const threshold = config.Threshold
const eventbridgeAlarmProperties:EventbridgeAlarm = {
AlarmName: `Events_ThrottledRulesAlarm_\${${logicalId}}`,
AlarmDescription: `EventBridge Throttled Rules for \${${logicalId}} breaches ${threshold}`,
RuleName: logicalId,
AlarmName: `Events_ThrottledRulesAlarm_${logicalId}`,
AlarmDescription: `EventBridge Throttled Rules for ${logicalId} breaches ${threshold}`,
RuleName: `${logicalId}`,
ComparisonOperator: config.ComparisonOperator,
Threshold: config.Threshold,
MetricName: 'ThrottledRules',
Expand All @@ -92,7 +92,7 @@ export default function eventsAlarms (eventsAlarmsConfig: EventsAlarmsConfig, co
EvaluationPeriods: config.EvaluationPeriods,
TreatMissingData: config.TreatMissingData,
Namespace: 'AWS/Events',
Dimensions: [{ Name: 'RuleName', Value: `\${${logicalId}}`}]
Dimensions: [{ Name: 'RuleName', Value: {Ref: logicalId} as any}]
}
return {
resourceName: `slicWatchEventsThrottledRulesAlarm${logicalId}`,
Expand Down
6 changes: 3 additions & 3 deletions core/alarms/kinesis.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,8 @@ export default function KinesisAlarms (kinesisAlarmProperties: KinesisAlarmPrope
function createStreamAlarm (streamLogicalId: string, streamResource: Resource, type: string, metric: string, config: AlarmProperties) {
const threshold = config.Threshold
const kinesisAlarmProperties: AlarmProperties = {
AlarmName: `Kinesis_${type}_\${${streamLogicalId}}`,
AlarmDescription: `Kinesis ${getStatisticName(config)} ${metric} for \${${streamLogicalId}} breaches ${threshold} milliseconds`,
AlarmName: `Kinesis_${type}_${streamLogicalId}`,
AlarmDescription: `Kinesis ${getStatisticName(config)} ${metric} for ${streamLogicalId} breaches ${threshold} milliseconds`,
ComparisonOperator: config.ComparisonOperator,
Threshold: config.Threshold,
MetricName: metric,
Expand All @@ -75,7 +75,7 @@ export default function KinesisAlarms (kinesisAlarmProperties: KinesisAlarmPrope
EvaluationPeriods: config.EvaluationPeriods,
TreatMissingData: config.TreatMissingData,
Namespace: 'AWS/Kinesis',
Dimensions:[{ Name: 'StreamName', Value: `\${${streamLogicalId}}`}]
Dimensions:[{ Name: 'StreamName', Value: {Ref: streamLogicalId} as any}]
}

return {
Expand Down
40 changes: 20 additions & 20 deletions core/alarms/lambda.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,9 @@ export default function LambdaAlarms (functionAlarmPropertiess: FunctionAlarmPro
function createIteratorAgeAlarm (funcLogicalId: string, funcResource: Resource, config: AlarmProperties) {
const threshold = config.Threshold
const lambdaAlarmProperties: LambdaAlarm = {
AlarmName: `Lambda_IteratorAge_\${${funcLogicalId}}`,
AlarmName: `Lambda_IteratorAge_${funcLogicalId}`,
AlarmDescription: `Iterator Age for ${funcLogicalId} breaches ${threshold}`,
FuncName: funcLogicalId,
FuncName: `${funcLogicalId}`,
ComparisonOperator: config.ComparisonOperator,
Threshold: threshold,
Metrics: null,
Expand All @@ -134,7 +134,7 @@ export default function LambdaAlarms (functionAlarmPropertiess: FunctionAlarmPro
EvaluationPeriods: config.EvaluationPeriods,
TreatMissingData: config.TreatMissingData,
Namespace: 'AWS/Lambda',
Dimensions: [{ Name: 'FunctionName', Value:`\${${funcLogicalId}}`}]
Dimensions: [{ Name: 'FunctionName', Value:`${funcLogicalId}`}]
}
return {
resourceName: `slicWatchLambdaIteratorAgeAlarm${funcLogicalId}`,
Expand All @@ -145,9 +145,9 @@ export default function LambdaAlarms (functionAlarmPropertiess: FunctionAlarmPro
function createLambdaErrorsAlarm (funcLogicalId: string, funcResource: Resource, config: AlarmProperties) {
const threshold = config.Threshold
const lambdaAlarmProperties: LambdaAlarm = {
AlarmName: `Lambda_Errors_\${${funcLogicalId}}`,
AlarmDescription: `Error count for \${${funcLogicalId}} breaches ${threshold}`,
FuncName: `\${${funcLogicalId}}`,
AlarmName: `Lambda_Errors_${funcLogicalId}`,
AlarmDescription: `Error count for ${funcLogicalId} breaches ${threshold}`,
FuncName: `${funcLogicalId}`,
ComparisonOperator: config.ComparisonOperator,
Threshold: threshold,
Metrics: null,
Expand All @@ -158,7 +158,7 @@ export default function LambdaAlarms (functionAlarmPropertiess: FunctionAlarmPro
EvaluationPeriods: config.EvaluationPeriods,
TreatMissingData: config.TreatMissingData,
Namespace: 'AWS/Lambda',
Dimensions: [{ Name: 'FunctionName', Value:`\${${funcLogicalId}}`}]
Dimensions: [{ Name: 'FunctionName', Value: { Ref: funcLogicalId } as any}]
}
return {
resourceName: `slicWatchLambdaErrorsAlarm${funcLogicalId}`,
Expand All @@ -183,7 +183,7 @@ export default function LambdaAlarms (functionAlarmPropertiess: FunctionAlarmPro
Metric: {
Namespace: 'AWS/Lambda',
MetricName: 'Throttles',
Dimensions: [{ Name: 'FunctionName', Value: `\${${funcLogicalId}}` }]
Dimensions: [{ Name: 'FunctionName', Value: { Ref: funcLogicalId } as any}]
},
Period: period,
Stat: config.Statistic
Expand All @@ -196,7 +196,7 @@ export default function LambdaAlarms (functionAlarmPropertiess: FunctionAlarmPro
Metric: {
Namespace: 'AWS/Lambda',
MetricName: 'Invocations',
Dimensions: [{ Name: 'FunctionName', Value: `\${${funcLogicalId}}` }]
Dimensions: [{ Name: 'FunctionName', Value: { Ref: funcLogicalId } as any}]
},
Period: period,
Stat: config.Statistic
Expand All @@ -205,9 +205,9 @@ export default function LambdaAlarms (functionAlarmPropertiess: FunctionAlarmPro
}
]
const lambdaAlarmProperties: LambdaAlarm = {
AlarmName: `Lambda_Throttles_\${${funcLogicalId}}` ,
AlarmDescription: `Throttles % for \${${funcLogicalId}} breaches ${threshold}`,
FuncName: `\${${funcLogicalId}}`,
AlarmName: `Lambda_Throttles_${funcLogicalId}` ,
AlarmDescription: `Throttles % for ${funcLogicalId} breaches ${threshold}`,
FuncName: `${funcLogicalId}`,
ComparisonOperator: config.ComparisonOperator,
Threshold: threshold,
Metrics: metrics,
Expand All @@ -225,9 +225,9 @@ export default function LambdaAlarms (functionAlarmPropertiess: FunctionAlarmPro
const funcTimeout = funcResource.Properties.Timeout || 3
const threshold = config.Threshold
const lambdaAlarmProperties: LambdaAlarm = {
AlarmName: `Lambda_Duration_\${${funcLogicalId}}`,
AlarmDescription: `Max duration for \${${funcLogicalId}} breaches ${threshold}% of timeout (${funcTimeout})`,
FuncName: funcLogicalId,
AlarmName: `Lambda_Duration_${funcLogicalId}`,
AlarmDescription: `Max duration for ${funcLogicalId} breaches ${threshold}% of timeout (${funcTimeout})`,
FuncName: `${funcLogicalId}`,
ComparisonOperator: config.ComparisonOperator,
// @ts-ignore
Threshold: (threshold * funcTimeout * 1000) / 100,
Expand All @@ -239,7 +239,7 @@ export default function LambdaAlarms (functionAlarmPropertiess: FunctionAlarmPro
EvaluationPeriods: config.EvaluationPeriods,
TreatMissingData: config.TreatMissingData,
Namespace: 'AWS/Lambda',
Dimensions: [{ Name: 'FunctionName', Value:`\${${funcLogicalId}}`}]
Dimensions: [{ Name: 'FunctionName', Value: { Ref: funcLogicalId } as any}]
}
return {
resourceName: `slicWatchLambdaDurationAlarm${funcLogicalId}`,
Expand All @@ -250,9 +250,9 @@ export default function LambdaAlarms (functionAlarmPropertiess: FunctionAlarmPro
function createLambdaInvocationsAlarm (funcLogicalId: string, funcResource: Resource, config: AlarmProperties) {
const threshold = config.Threshold
const lambdaAlarmProperties: LambdaAlarm = {
AlarmName: `Lambda_Invocations_\${${funcLogicalId}}`,
AlarmDescription: `Total invocations for \${${funcLogicalId}} breaches ${threshold}`,
FuncName: `\${${funcLogicalId}}`,
AlarmName: `Lambda_Invocations_${funcLogicalId}`,
AlarmDescription: `Total invocations for ${funcLogicalId} breaches ${threshold}`,
FuncName: `${funcLogicalId}`,
ComparisonOperator: config.ComparisonOperator,
Threshold: threshold,
Metrics: null,
Expand All @@ -263,7 +263,7 @@ export default function LambdaAlarms (functionAlarmPropertiess: FunctionAlarmPro
EvaluationPeriods: config.EvaluationPeriods,
TreatMissingData: config.TreatMissingData,
Namespace: 'AWS/Lambda',
Dimensions: [{ Name: 'FunctionName', Value:`\${${funcLogicalId}}`}]
Dimensions: [{ Name: 'FunctionName', Value: { Ref: funcLogicalId } as any}]
}
return {
resourceName: `slicWatchLambdaInvocationsAlarm${funcLogicalId}`,
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 @@ -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: `\${${logicalId}}`,
StateMachineArn: `${logicalId}`,
ComparisonOperator: config.ComparisonOperator,
Threshold: config.Threshold,
MetricName: metric,
Expand All @@ -55,7 +55,7 @@ export default function StatesAlarms (sfAlarmProperties: SfAlarmsConfig, context
EvaluationPeriods: config.EvaluationPeriods,
TreatMissingData: config.TreatMissingData,
Namespace: 'AWS/States',
Dimensions: [{ Name: 'StateMachineArn', Value:`\${${logicalId}}`}]
Dimensions: [{ Name: 'StateMachineArn', Value: {Ref: logicalId} as any }]
}
const alarmResource= createAlarm(smAlarmProperties, context)

Expand Down
5 changes: 4 additions & 1 deletion core/alarms/tests/kinesis.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,10 @@ test('Kinesis data stream alarms are created', (t) => {
t.same(al.Dimensions, [
{
Name: 'StreamName',
Value: '${stream}'
Value: {
'Ref': 'stream'
}

}
])
}
Expand Down
4 changes: 3 additions & 1 deletion core/alarms/tests/step-functions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,9 @@ test('Step Function alarms are created', (t) => {
t.same(al.Dimensions, [
{
Name: 'StateMachineArn',
Value: '${Workflow}'
Value: {
'Ref': 'Workflow'
}
}
])
}
Expand Down
2 changes: 1 addition & 1 deletion serverless-plugin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "serverless-slic-watch-plugin",
"version": "2.1.2",
"description": "Serverless plugin for automatic alarms and dashboards",
"main": "index.js",
"main": "dist/index.js",
"type": "module",
"repository": {
"type": "git",
Expand Down

0 comments on commit b896260

Please sign in to comment.