Skip to content

Commit

Permalink
Merge afe9974 into e14b436
Browse files Browse the repository at this point in the history
  • Loading branch information
eoinsha committed May 31, 2022
2 parents e14b436 + afe9974 commit 08921c3
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 8 deletions.
8 changes: 4 additions & 4 deletions serverless-plugin/alarms-api-gateway.js
@@ -1,6 +1,6 @@
'use strict'

const { makeResourceName } = require('./util')
const { makeResourceName, getStatisticName } = require('./util')

/**
* @param {object} apiGwAlarmConfig The fully resolved alarm configuration
Expand Down Expand Up @@ -99,7 +99,7 @@ module.exports = function ApiGatewayAlarms (apiGwAlarmConfig, context) {
resourceName: makeResourceName('Api', apiName, 'Availability'),
resource: createApiAlarm(
`ApiAvailability_${apiName}`,
`API 5XXError ${config.Statistic} for ${apiName} breaches ${threshold}`,
`API 5XXError ${getStatisticName(config)} for ${apiName} breaches ${threshold}`,
apiName,
config.ComparisonOperator,
threshold,
Expand All @@ -120,7 +120,7 @@ module.exports = function ApiGatewayAlarms (apiGwAlarmConfig, context) {
resourceName: makeResourceName('Api', apiName, '4XXError'),
resource: createApiAlarm(
`Api4XXError_${apiName}`,
`API 4XXError ${config.Statistic} for ${apiName} breaches ${threshold}`,
`API 4XXError ${getStatisticName(config)} for ${apiName} breaches ${threshold}`,
apiName,
config.ComparisonOperator,
threshold,
Expand All @@ -141,7 +141,7 @@ module.exports = function ApiGatewayAlarms (apiGwAlarmConfig, context) {
resourceName: makeResourceName('Api', apiName, 'Latency'),
resource: createApiAlarm(
`ApiLatency_${apiName}`,
`API Latency ${config.Statistic} for ${apiName} breaches ${threshold}`,
`API Latency ${getStatisticName(config)} for ${apiName} breaches ${threshold}`,
apiName,
config.ComparisonOperator,
threshold,
Expand Down
4 changes: 2 additions & 2 deletions serverless-plugin/alarms-kinesis.js
@@ -1,6 +1,6 @@
'use strict'

const { makeResourceName } = require('./util')
const { makeResourceName, getStatisticName } = require('./util')

const kinesisAlarmTypes = {
StreamIteratorAge: 'GetRecords.IteratorAgeMilliseconds',
Expand Down Expand Up @@ -64,7 +64,7 @@ module.exports = function KinesisAlarms (kinesisAlarmConfig, context) {
ActionsEnabled: true,
AlarmActions: context.alarmActions,
AlarmName: `${type}_${streamName}`,
AlarmDescription: `Kinesis ${config.Statistic} ${metric} for ${streamName} breaches ${threshold} milliseconds`,
AlarmDescription: `Kinesis ${getStatisticName(config)} ${metric} for ${streamName} breaches ${threshold} milliseconds`,
EvaluationPeriods: config.EvaluationPeriods,
ComparisonOperator: config.ComparisonOperator,
Threshold: config.Threshold,
Expand Down
10 changes: 9 additions & 1 deletion serverless-plugin/tests/util.test.js
Expand Up @@ -5,7 +5,8 @@ const { test } = require('tap')
const {
filterObject,
resolveEcsClusterNameAsCfn,
resolveEcsClusterNameForSub
resolveEcsClusterNameForSub,
getStatisticName
} = require('../util')

test('filterObject filters out', (t) => {
Expand Down Expand Up @@ -76,3 +77,10 @@ test('resolveEcsClusterNameForSub', (t) => {
t.same(fromUnexpected, unexpected)
t.end()
})

test('getStatisticName chooses Statistic then ExtendedStatistic property', (t) => {
t.equal(getStatisticName({ Statistic: 'Sum' }), 'Sum')
t.equal(getStatisticName({ ExtendedStatistic: 'p99' }), 'p99')
t.equal(getStatisticName({ Statistic: 'Average', ExtendedStatistic: 'p99' }), 'Average')
t.end()
})
12 changes: 11 additions & 1 deletion serverless-plugin/util.js
Expand Up @@ -66,9 +66,19 @@ function resolveEcsClusterNameForSub (cluster) {
return cluster
}

/*
* Determine the presentation name for an alarm statistic
*
* @param {*} alarmConfig Alarm configuration
*/
function getStatisticName (alarmConfig) {
return alarmConfig.Statistic || alarmConfig.ExtendedStatistic
}

module.exports = {
filterObject,
makeResourceName,
resolveEcsClusterNameAsCfn,
resolveEcsClusterNameForSub
resolveEcsClusterNameForSub,
getStatisticName
}

0 comments on commit 08921c3

Please sign in to comment.