Skip to content

Commit

Permalink
Have current published version instead of undefined
Browse files Browse the repository at this point in the history
  • Loading branch information
tapaswenipathak committed May 29, 2018
1 parent c9a5f97 commit f7bdbc4
Show file tree
Hide file tree
Showing 2 changed files with 133 additions and 28 deletions.
25 changes: 13 additions & 12 deletions lib/template.js
@@ -1,7 +1,8 @@
'use strict';

const cf = require('@mapbox/cloudfriend');
var pkg = require(path.resolve(__dirname, '..', 'package.json'));
const path = require('path');
const pkg = require(path.resolve(__dirname, '..', 'package.json'));

/**
* Builds Watchbot resources for you to include in a CloudFormation template
Expand Down Expand Up @@ -107,7 +108,7 @@ module.exports = (options = {}) => {
options = Object.assign(
{
prefix: 'Watchbot',
watchbotVersion: 'v' + pkg.version;
watchbotVersion: 'v' + pkg.version,
reservation: {},
env: {},
messageTimeout: 600,
Expand All @@ -116,9 +117,9 @@ module.exports = (options = {}) => {
mounts: '',
privileged: false,
family: options.service,
errorThreshold: 1,
alarmThreshold: 1,
alarmPeriods: 1,
errorThreshold: 10,
alarmThreshold: 40,
alarmPeriods: 24,
failedPlacementAlarmPeriods: 1
},
options
Expand Down Expand Up @@ -534,7 +535,7 @@ module.exports = (options = {}) => {
EvaluationPeriods: 1,
Statistic: 'Minimum',
Threshold: 1,
Period: 60,
Period: '60',
ComparisonOperator: 'GreaterThanOrEqualToThreshold',
Namespace: 'AWS/SQS',
Dimensions: [
Expand All @@ -545,7 +546,7 @@ module.exports = (options = {}) => {
}
};

Resources[prefixed('FailedWorkerPlacementMetric')] = {
Resources[prefixed('FailedWorkerPlacementMetric')] = {
Type: 'AWS::Logs::MetricFilter',
Properties: {
FilterPattern: '{ $.failedPlacement = true }',
Expand All @@ -567,16 +568,16 @@ module.exports = (options = {}) => {
`https://github.com/mapbox/ecs-watchbot/blob/${options.watchbotVersion}/docs/alarms.md#failedworkerplacement`,
EvaluationPeriods: options.failedPlacementAlarmPeriods,
Statistic: 'Sum',
Threshold: 1,
Period: 10,
Threshold: 5,
Period: '60',
ComparisonOperator: 'GreaterThanThreshold',
Namespace: 'Mapbox/ecs-watchbot',
MetricName: cf.join([prefixed('FailedWorkerPlacement-'), cf.stackName]),
AlarmActions: [notify]
}
};

Resources[prefixed('WorkerErrorsMetric')] = {
Resources[prefixed('WorkerErrorsMetric')] = {
Type: 'AWS::Logs::MetricFilter',
Properties: {
FilterPattern: '"[failure]"',
Expand All @@ -598,7 +599,7 @@ module.exports = (options = {}) => {
EvaluationPeriods: 1,
Statistic: 'Sum',
Threshold: options.errorThreshold,
Period: 10,
Period: '60',
ComparisonOperator: 'GreaterThanThreshold',
Namespace: 'Mapbox/ecs-watchbot',
MetricName: cf.join([prefixed('WorkerErrors-'), cf.stackName]),
Expand All @@ -615,7 +616,7 @@ module.exports = (options = {}) => {
EvaluationPeriods: options.alarmPeriods,
Statistic: 'Average',
Threshold: options.alarmThreshold,
Period: 60,
Period: '300',
ComparisonOperator: 'GreaterThanThreshold',
Namespace: 'AWS/SQS',
MetricName: 'ApproximateNumberOfMessagesVisible',
Expand Down
136 changes: 120 additions & 16 deletions test/__snapshots__/template.jest.js.snap
Expand Up @@ -33,9 +33,9 @@ Object {
},
],
"EvaluationPeriods": 1,
"MetricName": "ApproximateNumberOfMessagesNotVisible",
"MetricName": "ApproximateNumberOfMessagesVisible",
"Namespace": "AWS/SQS",
"Period": 60,
"Period": "60",
"Statistic": "Minimum",
"Threshold": 1,
},
Expand All @@ -60,14 +60,40 @@ Object {
},
"Type": "AWS::SQS::Queue",
},
"SoupFailedWorkerPlacementMetric": Object {
"Properties": Object {
"FilterPattern": "{ $.failedPlacement = true }",
"LogGroupName": Object {
"Ref": "SoupLogs",
},
"MetricTransformations": Array [
Object {
"MetricName": Object {
"Fn::Join": Array [
"",
Array [
"SoupFailedWorkerPlacement-",
Object {
"Ref": "AWS::StackName",
},
],
],
},
"MetricNamespace": "Mapbox/ecs-watchbot",
"MetricValue": 1,
},
],
},
"Type": "AWS::Logs::MetricFilter",
},
"SoupFailedworkerPlacementAlarm": Object {
"Properties": Object {
"AlarmActions": Array [
Object {
"Ref": "SoupNotificationTopic",
},
],
"AlarmDescription": "https://github.com/mapbox/ecs-watchbot/blob/undefined/docs/alarms.md#failedworkerplacement",
"AlarmDescription": "https://github.com/mapbox/ecs-watchbot/blob/v3.5.1/docs/alarms.md#failedworkerplacement",
"AlarmName": Object {
"Fn::Sub": "\${AWS::StackName}-failed-worker-placement",
},
Expand All @@ -85,7 +111,7 @@ Object {
],
},
"Namespace": "Mapbox/ecs-watchbot",
"Period": 60,
"Period": "60",
"Statistic": "Sum",
"Threshold": 5,
},
Expand Down Expand Up @@ -185,7 +211,7 @@ Object {
"Ref": "SoupNotificationTopic",
},
],
"AlarmDescription": "https://github.com/mapbox/ecs-watchbot/blob/undefined/docs/alarms.md#queuesize",
"AlarmDescription": "https://github.com/mapbox/ecs-watchbot/blob/v3.5.1/docs/alarms.md#queuesize",
"AlarmName": Object {
"Fn::Sub": "\${AWS::StackName}-queue-size",
},
Expand All @@ -204,7 +230,7 @@ Object {
"EvaluationPeriods": 24,
"MetricName": "ApproximateNumberOfMessagesVisible",
"Namespace": "AWS/SQS",
"Period": 300,
"Period": "300",
"Statistic": "Average",
"Threshold": 40,
},
Expand Down Expand Up @@ -624,7 +650,7 @@ Object {
"Ref": "SoupNotificationTopic",
},
],
"AlarmDescription": "https://github.com/mapbox/ecs-watchbot/blob/undefined/docs/alarms.md#workererrors",
"AlarmDescription": "https://github.com/mapbox/ecs-watchbot/blob/v3.5.1/docs/alarms.md#workererrors",
"AlarmName": Object {
"Fn::Sub": "\${AWS::StackName}-worker-errors",
},
Expand All @@ -642,12 +668,38 @@ Object {
],
},
"Namespace": "Mapbox/ecs-watchbot",
"Period": 60,
"Period": "60",
"Statistic": "Sum",
"Threshold": 10,
},
"Type": "AWS::CloudWatch::Alarm",
},
"SoupWorkerErrorsMetric": Object {
"Properties": Object {
"FilterPattern": "\\"[failure]\\"",
"LogGroupName": Object {
"Ref": "SoupLogs",
},
"MetricTransformations": Array [
Object {
"MetricName": Object {
"Fn::Join": Array [
"",
Array [
"SoupWorkerErrors-",
Object {
"Ref": "AWS::StackName",
},
],
],
},
"MetricNamespace": "Mapbox/ecs-watchbot",
"MetricValue": 1,
},
],
},
"Type": "AWS::Logs::MetricFilter",
},
},
}
`;
Expand Down Expand Up @@ -685,9 +737,9 @@ Object {
},
],
"EvaluationPeriods": 1,
"MetricName": "ApproximateNumberOfMessagesNotVisible",
"MetricName": "ApproximateNumberOfMessagesVisible",
"Namespace": "AWS/SQS",
"Period": 60,
"Period": "60",
"Statistic": "Minimum",
"Threshold": 1,
},
Expand All @@ -712,14 +764,40 @@ Object {
},
"Type": "AWS::SQS::Queue",
},
"WatchbotFailedWorkerPlacementMetric": Object {
"Properties": Object {
"FilterPattern": "{ $.failedPlacement = true }",
"LogGroupName": Object {
"Ref": "WatchbotLogs",
},
"MetricTransformations": Array [
Object {
"MetricName": Object {
"Fn::Join": Array [
"",
Array [
"WatchbotFailedWorkerPlacement-",
Object {
"Ref": "AWS::StackName",
},
],
],
},
"MetricNamespace": "Mapbox/ecs-watchbot",
"MetricValue": 1,
},
],
},
"Type": "AWS::Logs::MetricFilter",
},
"WatchbotFailedworkerPlacementAlarm": Object {
"Properties": Object {
"AlarmActions": Array [
Object {
"Ref": "WatchbotNotificationTopic",
},
],
"AlarmDescription": "https://github.com/mapbox/ecs-watchbot/blob/undefined/docs/alarms.md#failedworkerplacement",
"AlarmDescription": "https://github.com/mapbox/ecs-watchbot/blob/v3.5.1/docs/alarms.md#failedworkerplacement",
"AlarmName": Object {
"Fn::Sub": "\${AWS::StackName}-failed-worker-placement",
},
Expand All @@ -737,7 +815,7 @@ Object {
],
},
"Namespace": "Mapbox/ecs-watchbot",
"Period": 60,
"Period": "60",
"Statistic": "Sum",
"Threshold": 5,
},
Expand Down Expand Up @@ -837,7 +915,7 @@ Object {
"Ref": "WatchbotNotificationTopic",
},
],
"AlarmDescription": "https://github.com/mapbox/ecs-watchbot/blob/undefined/docs/alarms.md#queuesize",
"AlarmDescription": "https://github.com/mapbox/ecs-watchbot/blob/v3.5.1/docs/alarms.md#queuesize",
"AlarmName": Object {
"Fn::Sub": "\${AWS::StackName}-queue-size",
},
Expand All @@ -856,7 +934,7 @@ Object {
"EvaluationPeriods": 24,
"MetricName": "ApproximateNumberOfMessagesVisible",
"Namespace": "AWS/SQS",
"Period": 300,
"Period": "300",
"Statistic": "Average",
"Threshold": 40,
},
Expand Down Expand Up @@ -1228,7 +1306,7 @@ Object {
"Ref": "WatchbotNotificationTopic",
},
],
"AlarmDescription": "https://github.com/mapbox/ecs-watchbot/blob/undefined/docs/alarms.md#workererrors",
"AlarmDescription": "https://github.com/mapbox/ecs-watchbot/blob/v3.5.1/docs/alarms.md#workererrors",
"AlarmName": Object {
"Fn::Sub": "\${AWS::StackName}-worker-errors",
},
Expand All @@ -1246,12 +1324,38 @@ Object {
],
},
"Namespace": "Mapbox/ecs-watchbot",
"Period": 60,
"Period": "60",
"Statistic": "Sum",
"Threshold": 10,
},
"Type": "AWS::CloudWatch::Alarm",
},
"WatchbotWorkerErrorsMetric": Object {
"Properties": Object {
"FilterPattern": "\\"[failure]\\"",
"LogGroupName": Object {
"Ref": "WatchbotLogs",
},
"MetricTransformations": Array [
Object {
"MetricName": Object {
"Fn::Join": Array [
"",
Array [
"WatchbotWorkerErrors-",
Object {
"Ref": "AWS::StackName",
},
],
],
},
"MetricNamespace": "Mapbox/ecs-watchbot",
"MetricValue": 1,
},
],
},
"Type": "AWS::Logs::MetricFilter",
},
},
}
`;

0 comments on commit f7bdbc4

Please sign in to comment.