Skip to content

Commit

Permalink
Fix dimension values in some modules
Browse files Browse the repository at this point in the history
- Fix some deployment issues
  • Loading branch information
direnakkoc committed Apr 6, 2023
1 parent dbdc89c commit 3c4f429
Show file tree
Hide file tree
Showing 10 changed files with 66 additions and 13 deletions.
6 changes: 4 additions & 2 deletions core/alarms/alb-target-group.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@ function createAlbTargetCfAlarm (targetGroupLogicalId: string, metrics: string[]
Statistic: config.Statistic,
Namespace: 'AWS/ApplicationELB',
Dimensions: [
{ Name: 'TargetGroup', Value: `\${${targetGroupLogicalId}.TargetGroupFullName}` },
{ Name: 'LoadBalancer', Value: `\${${loadBalancerLogicalId}.LoadBalancerFullName}` }
{ Name: 'TargetGroup', Value: { 'Fn::GetAtt': [targetGroupLogicalId, 'TargetGroupFullName'] } },
{ Name: 'LoadBalancer', Value: { 'Fn::GetAtt': [loadBalancerLogicalId, 'LoadBalancerFullName'] } as any }
],
...alarmProps
}
Expand All @@ -126,6 +126,8 @@ function createAlbTargetCfAlarm (targetGroupLogicalId: string, metrics: string[]
* @param albTargetAlarmsConfig The fully resolved alarm configuration
* @param context Deployment context (alarmActions)
* @param compiledTemplate A CloudFormation template object
*
* @returns ALB Target Group-specific CloudFormation Alarm resources
*/
export default function createALBTargetAlarms (albTargetAlarmsConfig: AlbTargetAlarmsConfig, context: Context, compiledTemplate: Template) {
const targetGroupResources = getResourcesByType('AWS::ElasticLoadBalancingV2::TargetGroup', compiledTemplate)
Expand Down
2 changes: 2 additions & 0 deletions core/alarms/api-gateway.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export interface ApiGwAlarmsConfig {
*
* @param restApiResource CloudFormation resource for a REST API
* @param restApiLogicalId The logical ID for the resouce
*
* @returns CloudFormation syntax for the API name
*/
export function resolveRestApiNameAsCfn (restApiResource: Resource, restApiLogicalId: string) {
Expand All @@ -46,6 +47,7 @@ export function resolveRestApiNameAsCfn (restApiResource: Resource, restApiLogic
*
* @param restApiResource CloudFormation resource for a REST API
* @param restApiLogicalId The logical ID for the resouce
*
* @returns Literal string or Sub variable syntax
*/
export function resolveRestApiNameForSub (restApiResource: Resource, restApiLogicalId: string) {
Expand Down
2 changes: 1 addition & 1 deletion core/alarms/appsync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ export default function createAppSyncAlarms (appSyncAlarmsConfig: AppSyncAlarmsC
MetricName: metric,
Namespace: 'AWS/AppSync',
Dimensions: [
{ Name: 'GraphQLAPIId', Value: `\${${appSyncLogicalId}.ApiId}}` }
{ Name: 'GraphQLAPIId', Value: { 'Fn::GetAtt': [appSyncLogicalId, 'ApiId'] } as any }
],
...alarmProps
}
Expand Down
1 change: 1 addition & 0 deletions core/alarms/ecs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export interface EcsAlarmsConfig {
* the cluster's name
*
* @param cluster CloudFormation syntax for an ECS cluster
*
* @returns CloudFormation syntax for the cluster's name
*/
export function resolveEcsClusterNameAsCfn (cluster: any): any {
Expand Down
12 changes: 12 additions & 0 deletions core/alarms/lambda.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,18 @@ export default function createLambdaAlarms (functionAlarmProperties: LambdaFunct
return resources
}

/**
* Create CloudFormation 'AWS::CloudWatch::Alarm' resources based on metrics for a specfic resources type
*
* @param config The fully resolved alarm configuration
* @param metric The Lambda metric name
* @param funcLogicalId The CloudFormation Logical ID of the Lambda resource
* @param compiledTemplate A CloudFormation template object
* @param context Deployment context (alarmActions)
*
* @returns Lambda-specific CloudFormation Alarm resources
*/

function createLambdaCfAlarm (config: SlicWatchAlarmConfig, metric: string, funcLogicalId: string | number, compiledTemplate: Template, context: Context) {
const { enabled, Period, Statistic, ...rest } = config

Expand Down
2 changes: 1 addition & 1 deletion core/alarms/sns.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const executionMetrics = ['NumberOfNotificationsFilteredOut-InvalidAttributes',
function createSnsTopicAlarmCfProperties (metric: string, snsLogicalId: string, config: SlicWatchAlarmConfig) {
return {
Namespace: 'AWS/SNS',
Dimensions: [{ Name: 'TopicName', Value: `\${${snsLogicalId}.TopicName}` }]
Dimensions: [{ Name: 'TopicName', Value: { 'Fn::GetAtt': [snsLogicalId, 'TopicName'] } as any }]
}
}

Expand Down
12 changes: 6 additions & 6 deletions core/dashboards/dashboard-types.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type FunctionProperties from 'cloudform-types/types/lambda/function'

// export type YAxis = 'left' | 'right'
export type YAxis = 'left' | 'right'

interface TimeRange {
start: string
Expand All @@ -12,31 +12,31 @@ export interface MetricDefs {
metric: string
dimensions: object
stat: string
yAxis?: string
yAxis?: YAxis
}
export interface Properties {
metrics: string
title: string
view: string
region: string
period?: number
yAxis?: string
yAxis?: YAxis
}

export interface CreateMetricWidget {
type: string
properties: Properties
width: number
height: number
yAxis?: string
yAxis?: YAxis
}

export interface Widgets {
enabled?: boolean
metricPeriod?: number
width?: number
height?: number
yAxis?: string
yAxis?: YAxis
Statistic?: string[]
Lambda?: LambdaDashboardBodyProperties
ApiGateway?: ApiGwDashboardBodyProperties
Expand All @@ -63,7 +63,7 @@ export interface DashboardBodyProperties {
metricPeriod?: number
width?: number
height?: number
yAxis?: string
yAxis?: YAxis
Statistic?: string[]
}

Expand Down
2 changes: 1 addition & 1 deletion core/dashboards/dashboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ export default function addDashboard (dashboardConfig: SlicWatchDashboardConfig,
namespace,
metric,
...Object.entries(dimensions).reduce(
(acc, [name, value]) => [...acc, name, value],
(acc: string[], [name, value]) => [...acc, name, value],
[]
),
{ stat, yAxis }
Expand Down
36 changes: 36 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions serverless-test-project/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@
"version": "2.1.2",
"description": "Test project for SLIC Watch serverless plugin",
"main": "basic-handler.js",
"type": "module",
"repository": {
"type": "git",
"url": "https://github.com/fourTheorem/slic-watch.git",
"directory": "serverless-test-project"
},
"license": "Apache",
"devDependencies": {
"axios": "^1.3.5",
"serverless": "^3.28.1",
"serverless-step-functions": "^3.12.1"
},
"scripts": {
"test": "ALARM_TOPIC=test sls package"
}
}
}

0 comments on commit 3c4f429

Please sign in to comment.