/
dashboard-dynamodb.test.ts
196 lines (173 loc) · 7.31 KB
/
dashboard-dynamodb.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
import { merge } from 'lodash'
import { test } from 'tap'
import { type MetricWidgetProperties } from 'cloudwatch-dashboard-types'
import { type DynamoDB } from 'cloudform'
import { type ResourceType } from '../../cf-template'
import addDashboard from '../dashboard'
import defaultConfig from '../../inputs/default-config'
import { createTestCloudFormationTemplate, getDashboardFromTemplate, getDashboardWidgetsByTitle } from '../../tests/testing-utils'
test('dashboard contains configured DynamoDB resources', (t) => {
t.test('dashboards includes DynamoDB metrics', (t) => {
const template = createTestCloudFormationTemplate()
addDashboard(defaultConfig.dashboard, template)
const { dashboard } = getDashboardFromTemplate(template)
const widgets = getDashboardWidgetsByTitle(dashboard,
/ReadThrottleEvents Table /,
/ReadThrottleEvents GSI GSI1 in /,
/WriteThrottleEvents Table /,
/WriteThrottleEvents GSI GSI1 in /
)
for (const widget of widgets) {
t.ok(widget)
}
const [
readThrottlesWidget, readThrottlesGsiWidget, writeThrottlesWidget, writeThrottlesGsiWidget
] = widgets
t.match((readThrottlesWidget.properties as MetricWidgetProperties).metrics, [
['AWS/DynamoDB', 'ReadThrottleEvents', 'TableName', '${dataTable}', { stat: 'Sum', yAxis: 'left' }]
])
t.match((readThrottlesGsiWidget.properties as MetricWidgetProperties).metrics, [
['AWS/DynamoDB', 'ReadThrottleEvents', 'TableName', '${dataTable}', 'GlobalSecondaryIndex', 'GSI1', { stat: 'Sum', yAxis: 'left' }]
])
t.match((writeThrottlesWidget.properties as MetricWidgetProperties).metrics, [
['AWS/DynamoDB', 'WriteThrottleEvents', 'TableName', '${dataTable}', { stat: 'Sum', yAxis: 'left' }]
])
t.match((writeThrottlesGsiWidget.properties as MetricWidgetProperties).metrics, [
['AWS/DynamoDB', 'WriteThrottleEvents', 'TableName', '${dataTable}', 'GlobalSecondaryIndex', 'GSI1', { stat: 'Sum', yAxis: 'left' }]
])
for (const widget of widgets) {
const props: MetricWidgetProperties = widget.properties as MetricWidgetProperties
t.ok((props.metrics?.length ?? 0) > 0)
t.equal(props.period, 300)
t.equal(props.view, 'timeSeries')
}
t.end()
})
t.test('dashboards includes DynamoDB metrics without GSIs', (t) => {
const template = createTestCloudFormationTemplate()
delete ((template.Resources as ResourceType).dataTable as DynamoDB.Table).Properties.GlobalSecondaryIndexes
addDashboard(defaultConfig.dashboard, template)
const { dashboard } = getDashboardFromTemplate(template)
const widgets = getDashboardWidgetsByTitle(dashboard,
/ReadThrottleEvents Table /,
/ReadThrottleEvents GSI GSI1 in /,
/WriteThrottleEvents Table /,
/WriteThrottleEvents GSI GSI1 in /
)
const [
readThrottlesWidget, readThrottlesGsiWidget, writeThrottlesWidget, writeThrottlesGsiWidget
] = widgets
t.ok(readThrottlesWidget)
t.notOk(readThrottlesGsiWidget)
t.ok(writeThrottlesWidget)
t.notOk(writeThrottlesGsiWidget)
t.end()
})
t.test('service config overrides take precedence', (t) => {
const template = createTestCloudFormationTemplate()
const config = merge({}, defaultConfig.dashboard, {
widgets: {
DynamoDB: {
metricPeriod: 900,
width: 8,
height: 12,
ReadThrottleEvents: {
Statistic: ['ts80'],
yAxis: 'right',
enabled: false
},
WriteThrottleEvents: {
Statistic: ['ts80'],
yAxis: 'right'
}
}
}
})
addDashboard(config, template)
const { dashboard } = getDashboardFromTemplate(template)
const widgets = getDashboardWidgetsByTitle(dashboard,
/ReadThrottleEvents Table /,
/ReadThrottleEvents GSI GSI1 in /,
/WriteThrottleEvents Table /,
/WriteThrottleEvents GSI GSI1 in /
)
const [
readThrottlesWidget, readThrottlesGsiWidget, writeThrottlesWidget, writeThrottlesGsiWidget
] = widgets
t.ok(writeThrottlesWidget)
t.ok(writeThrottlesGsiWidget)
t.notOk(readThrottlesWidget)
t.notOk(readThrottlesGsiWidget)
t.match((writeThrottlesWidget.properties as MetricWidgetProperties).metrics, [
['AWS/DynamoDB', 'WriteThrottleEvents', 'TableName', '${dataTable}', { stat: 'ts80', yAxis: 'right' }]
])
t.match((writeThrottlesGsiWidget.properties as MetricWidgetProperties).metrics, [
['AWS/DynamoDB', 'WriteThrottleEvents', 'TableName', '${dataTable}', 'GlobalSecondaryIndex', 'GSI1', { stat: 'ts80', yAxis: 'right' }]
])
for (const widget of widgets.filter(w => Boolean(w))) {
const props: MetricWidgetProperties = widget.properties as MetricWidgetProperties
t.equal(props.period, 900)
t.equal(props.view, 'timeSeries')
t.equal(widget.width, 8)
t.equal(widget.height, 12)
}
t.end()
})
t.test('resource config overrides take precedence', (t) => {
const template = createTestCloudFormationTemplate();
(template.Resources as ResourceType).dataTable.Metadata = {
slicWatch: {
dashboard: {
ThrottledPutRecordCount: {
Statistic: ['Average'],
yAxis: 'right',
enabled: true
},
ReadThrottleEvents: {
enabled: false,
metricPeriod: 600
}
}
}
}
addDashboard(defaultConfig.dashboard, template)
const { dashboard } = getDashboardFromTemplate(template)
const widgets = getDashboardWidgetsByTitle(dashboard,
/ReadThrottleEvents Table /,
/ReadThrottleEvents GSI GSI1 in /,
/WriteThrottleEvents Table /,
/WriteThrottleEvents GSI GSI1 in /,
/ThrottledPutRecordCount Table /,
/ThrottledPutRecordCount GSI GSI1 in /
)
const [
readThrottlesWidget, readThrottlesGsiWidget, writeThrottlesWidget, writeThrottlesGsiWidget,
throttledPutRecordWidget, throttledPutRecordGsiWidget
] = widgets
t.ok(writeThrottlesWidget)
t.ok(writeThrottlesGsiWidget)
t.notOk(readThrottlesWidget)
t.notOk(readThrottlesGsiWidget)
t.ok(throttledPutRecordWidget)
t.ok(throttledPutRecordGsiWidget)
t.match((writeThrottlesWidget.properties as MetricWidgetProperties).metrics, [
['AWS/DynamoDB', 'WriteThrottleEvents', 'TableName', '${dataTable}', { stat: 'Sum', yAxis: 'left' }]
])
t.match((writeThrottlesGsiWidget.properties as MetricWidgetProperties).metrics, [
['AWS/DynamoDB', 'WriteThrottleEvents', 'TableName', '${dataTable}', 'GlobalSecondaryIndex', 'GSI1', { stat: 'Sum', yAxis: 'left' }]
])
const throttledPutRecordProps = throttledPutRecordWidget.properties as MetricWidgetProperties
t.equal(throttledPutRecordProps.period, 300)
t.equal(throttledPutRecordProps.view, 'timeSeries')
t.match(throttledPutRecordProps.metrics, [
['AWS/DynamoDB', 'ThrottledPutRecordCount', 'TableName', '${dataTable}', { stat: 'Average', yAxis: 'right' }]
])
const throttledPutRecordGsiProps = throttledPutRecordGsiWidget.properties as MetricWidgetProperties
t.equal(throttledPutRecordGsiProps.period, 300)
t.match(throttledPutRecordGsiProps.metrics, [
['AWS/DynamoDB', 'ThrottledPutRecordCount', 'TableName', '${dataTable}', 'GlobalSecondaryIndex', 'GSI1', { stat: 'Average', yAxis: 'right' }]
])
t.end()
})
t.end()
})