-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #42 from fourTheorem/kinesis-data-streams
Kinesis data streams
- Loading branch information
Showing
10 changed files
with
349 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
'use strict' | ||
|
||
const { makeResourceName } = require('./util') | ||
|
||
const kinesisAlarmTypes = { | ||
StreamIteratorAge: 'GetRecords.IteratorAgeMilliseconds', | ||
StreamReadThroughput: 'ReadProvisionedThroughputExceeded', | ||
StreamWriteThroughput: 'WriteProvisionedThroughputExceeded', | ||
StreamPutRecordSuccess: 'PutRecord.Success', | ||
StreamPutRecordsSuccess: 'PutRecords.Success', | ||
StreamGetRecordsSuccess: 'GetRecords.Success' | ||
} | ||
|
||
/** | ||
* @param {object} kinesisAlarmConfig The fully resolved alarm configuration for Kinesis Data Streams | ||
*/ | ||
module.exports = function KinesisAlarms (kinesisAlarmConfig, context) { | ||
return { | ||
createKinesisAlarms | ||
} | ||
|
||
/** | ||
* Add all required Kinesis Data Stream alarms to the provided CloudFormation template | ||
* based on the resources found within | ||
* | ||
* @param {CloudFormationTemplate} cfTemplate A CloudFormation template object | ||
*/ | ||
function createKinesisAlarms (cfTemplate) { | ||
const streamResources = cfTemplate.getResourcesByType( | ||
'AWS::Kinesis::Stream' | ||
) | ||
|
||
for (const [streamResourceName, streamResource] of Object.entries(streamResources)) { | ||
for (const [type, metric] of Object.entries(kinesisAlarmTypes)) { | ||
if (kinesisAlarmConfig[metric].enabled) { | ||
const alarm = createStreamAlarm( | ||
streamResourceName, | ||
streamResource, | ||
type, | ||
metric, | ||
kinesisAlarmConfig[metric] | ||
) | ||
cfTemplate.addResource(alarm.resourceName, alarm.resource) | ||
} | ||
} | ||
} | ||
} | ||
|
||
function createStreamAlarm (streamResourceName, streamResource, type, metric, config) { | ||
const streamName = streamResource.Properties.Name // TODO: Allow for Ref usage in resource names (see #14) | ||
const threshold = config.Threshold | ||
const metricProperties = { | ||
Dimensions: [{ Name: 'StreamName', Value: streamName }], | ||
MetricName: metric, | ||
Namespace: 'AWS/Kinesis', | ||
Period: config.Period, | ||
Statistic: config.Statistic, | ||
ExtendedStatistic: config.ExtendedStatistic | ||
} | ||
|
||
const resource = { | ||
Type: 'AWS::CloudWatch::Alarm', | ||
Properties: { | ||
ActionsEnabled: true, | ||
AlarmActions: [context.topicArn], | ||
AlarmName: `${type}_${streamName}`, | ||
AlarmDescription: `Kinesis ${config.Statistic} ${metric} for ${streamName} breaches ${threshold} milliseconds`, | ||
EvaluationPeriods: 1, | ||
ComparisonOperator: config.ComparisonOperator, | ||
Threshold: config.Threshold, | ||
TreatMissingData: config.TreatMissingData, | ||
...metricProperties | ||
} | ||
} | ||
return { | ||
resourceName: makeResourceName('kinesis', streamName, type), | ||
resource | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.