@@ -3,104 +3,148 @@ import RateLimitedDecrement from './RateLimitedDecrement';
3
3
import Throughput from './Throughput' ;
4
4
import { invariant } from '../src/Global' ;
5
5
6
+ // NOTES
7
+ // - 'adjustmentPercent' or 'adjustmentUnits' is used, which ever is bigger
8
+ // - 'min' and 'max' are hard limits
9
+ // - 'minAdjustment' is minimum possible downward adjustment, there is no point
10
+ // wasting 1 of 4 daily decrements on a small value
11
+
12
+ const config = {
13
+ readCapacity : {
14
+ min : 1 ,
15
+ max : 10 ,
16
+ increment : {
17
+ thresholdPercent : 90 ,
18
+ adjustmentPercent : 100 ,
19
+ adjustmentUnits : 3 ,
20
+ } ,
21
+ decrement : {
22
+ thresholdPercent : 30 ,
23
+ minAdjustment : 3 ,
24
+ minGracePeriodAfterLastIncrementMinutes : 60 ,
25
+ minGracePeriodAfterLastDecrementMinutes : 60 ,
26
+ } ,
27
+ } ,
28
+ writeCapacity : {
29
+ min : 1 ,
30
+ max : 10 ,
31
+ increment : {
32
+ adjustmentPercent : 100 ,
33
+ adjustmentUnits : 3 ,
34
+ } ,
35
+ decrement : {
36
+ thresholdPercent : 30 ,
37
+ minAdjustment : 3 ,
38
+ minGracePeriodAfterLastIncrementMinutes : 60 ,
39
+ minGracePeriodAfterLastDecrementMinutes : 60 ,
40
+ } ,
41
+ } ,
42
+ } ;
43
+
6
44
const provisioner = new ConfigurableProvisioner ( {
7
45
readCapacity : {
8
46
increment : {
9
47
isAdjustmentRequired : ( data , calcFunc ) => {
10
- invariant ( typeof data !== 'undefined' ,
11
- 'Parameter \'data\' is not set' ) ;
12
- invariant ( typeof calcFunc !== 'undefined' ,
13
- 'Parameter \'calcFunc\' is not set' ) ;
48
+ invariant ( typeof data !== 'undefined' , 'Parameter \'data\' is not set' ) ;
49
+ invariant ( typeof calcFunc !== 'undefined' , 'Parameter \'calcFunc\' is not set' ) ;
14
50
15
- return Throughput . getReadCapacityUtilisationPercent ( data ) > 90 ;
51
+ let isAboveThreshold = Throughput . getReadCapacityUtilisationPercent ( data ) >
52
+ config . readCapacity . increment . thresholdPercent ;
53
+
54
+ let isBelowMin = data . ProvisionedThroughput . ReadCapacityUnits <
55
+ config . readCapacity . min ;
56
+
57
+ return isAboveThreshold || isBelowMin ;
16
58
} ,
17
59
calculateValue : data => {
18
- invariant ( typeof data !== 'undefined' ,
19
- 'Parameter \'data\' is not set' ) ;
20
-
21
- // adjustmentPercent or adjustmentUnits is used, which ever is bigger
22
- const adjustmentPercent = 100 ;
23
- const adjustmentUnits = 3 ;
24
- // min and max hard limits
25
- const max = 10 ;
26
- const min = 1 ;
60
+ invariant ( typeof data !== 'undefined' , 'Parameter \'data\' is not set' ) ;
61
+
27
62
return Throughput . getPercentAdjustedReadCapacityUnits (
28
- data , adjustmentPercent , adjustmentUnits , max , min ) ;
63
+ data ,
64
+ config . readCapacity . increment . adjustmentPercent ,
65
+ config . readCapacity . increment . adjustmentUnits ,
66
+ config . readCapacity . max ,
67
+ config . readCapacity . min ) ;
29
68
} ,
30
69
} ,
31
70
decrement : {
32
71
isAdjustmentRequired : ( data , calcFunc ) => {
33
- invariant ( typeof data !== 'undefined' ,
34
- 'Parameter \'data\' is not set' ) ;
35
- invariant ( typeof calcFunc !== 'undefined' ,
36
- 'Parameter \'calcFunc\' is not set' ) ;
37
-
38
- // minimum possible downward adjustment, there is no point
39
- // wasting 1 of 4 daily decrements on a small value
40
- const minAdjustment = 3 ;
41
- const minGracePeriodAfterLastIncrementMinutes = 60 ;
42
- const minGracePeriodAfterLastDecrementMinutes = 60 ;
43
- return Throughput . getReadCapacityUtilisationPercent ( data ) < 30 &&
72
+ invariant ( typeof data !== 'undefined' , 'Parameter \'data\' is not set' ) ;
73
+ invariant ( typeof calcFunc !== 'undefined' , 'Parameter \'calcFunc\' is not set' ) ;
74
+
75
+ let isReadDecrementAllowed =
44
76
RateLimitedDecrement . isReadDecrementAllowed (
45
- data , calcFunc , minAdjustment ,
46
- minGracePeriodAfterLastIncrementMinutes ,
47
- minGracePeriodAfterLastDecrementMinutes ) ;
77
+ data ,
78
+ calcFunc ,
79
+ config . readCapacity . decrement . minAdjustment ,
80
+ config . readCapacity . decrement . minGracePeriodAfterLastIncrementMinutes ,
81
+ config . readCapacity . decrement . minGracePeriodAfterLastDecrementMinutes ) ;
82
+
83
+ let isBelowThreshold = Throughput . getReadCapacityUtilisationPercent ( data ) <
84
+ config . readCapacity . decrement . thresholdPercent ;
85
+
86
+ let isAboveMax = data . ProvisionedThroughput . ReadCapacityUnits >
87
+ config . readCapacity . max ;
88
+
89
+ return isReadDecrementAllowed && ( isBelowThreshold || isAboveMax ) ;
48
90
} ,
49
91
calculateValue : data => {
50
- invariant ( typeof data !== 'undefined' ,
51
- 'Parameter \'data\' is not set' ) ;
92
+ invariant ( typeof data !== 'undefined' , 'Parameter \'data\' is not set' ) ;
52
93
53
- return Math . max ( data . ConsumedThroughput . ReadCapacityUnits , 1 ) ;
94
+ return Math . max ( data . ConsumedThroughput . ReadCapacityUnits , config . readCapacity . min ) ;
54
95
} ,
55
96
}
56
97
} ,
57
98
writeCapacity : {
58
99
increment : {
59
100
isAdjustmentRequired : ( data , calcFunc ) => {
60
- invariant ( typeof data !== 'undefined' ,
61
- 'Parameter \'data\' is not set' ) ;
62
- invariant ( typeof calcFunc !== 'undefined' ,
63
- 'Parameter \'calcFunc\' is not set' ) ;
101
+ invariant ( typeof data !== 'undefined' , 'Parameter \'data\' is not set' ) ;
102
+ invariant ( typeof calcFunc !== 'undefined' , 'Parameter \'calcFunc\' is not set' ) ;
64
103
65
- return Throughput . getWriteCapacityUtilisationPercent ( data ) > 90 ;
104
+ let isAboveThreshold = Throughput . getWriteCapacityUtilisationPercent ( data ) >
105
+ config . writeCapacity . increment . thresholdPercent ;
106
+
107
+ let isBelowMin = data . ProvisionedThroughput . WriteCapacityUnits <
108
+ config . writeCapacity . min ;
109
+
110
+ return isAboveThreshold || isBelowMin ;
66
111
} ,
67
112
calculateValue : data => {
68
- invariant ( typeof data !== 'undefined' ,
69
- 'Parameter \'data\' is not set' ) ;
70
-
71
- // adjustmentPercent or adjustmentUnits is used, which ever is bigger
72
- const adjustmentPercent = 100 ;
73
- const adjustmentUnits = 3 ;
74
- // min and max hard limits
75
- const max = 10 ;
76
- const min = 1 ;
113
+ invariant ( typeof data !== 'undefined' , 'Parameter \'data\' is not set' ) ;
114
+
77
115
return Throughput . getPercentAdjustedWriteCapacityUnits (
78
- data , adjustmentPercent , adjustmentUnits , max , min ) ;
116
+ data ,
117
+ config . writeCapacity . increment . adjustmentPercent ,
118
+ config . writeCapacity . increment . adjustmentUnits ,
119
+ config . writeCapacity . max ,
120
+ config . writeCapacity . min ) ;
79
121
} ,
80
122
} ,
81
123
decrement : {
82
124
isAdjustmentRequired : ( data , calcFunc ) => {
83
- invariant ( typeof data !== 'undefined' ,
84
- 'Parameter \'data\' is not set' ) ;
85
- invariant ( typeof calcFunc !== 'undefined' ,
86
- 'Parameter \'calcFunc\' is not set' ) ;
87
-
88
- // minimum possible downward adjustment, there is no point
89
- // wasting 1 of 4 daily decrements on a small value
90
- const minAdjustment = 3 ;
91
- const minGracePeriodAfterLastIncrementMinutes = 60 ;
92
- const minGracePeriodAfterLastDecrementMinutes = 60 ;
93
- return Throughput . getWriteCapacityUtilisationPercent ( data ) < 30 &&
125
+ invariant ( typeof data !== 'undefined' , 'Parameter \'data\' is not set' ) ;
126
+ invariant ( typeof calcFunc !== 'undefined' , 'Parameter \'calcFunc\' is not set' ) ;
127
+
128
+ let isWriteDecrementAllowed =
94
129
RateLimitedDecrement . isWriteDecrementAllowed (
95
- data , calcFunc , minAdjustment ,
96
- minGracePeriodAfterLastIncrementMinutes ,
97
- minGracePeriodAfterLastDecrementMinutes ) ;
130
+ data ,
131
+ calcFunc ,
132
+ config . writeCapacity . decrement . minAdjustment ,
133
+ config . writeCapacity . decrement . minGracePeriodAfterLastIncrementMinutes ,
134
+ config . writeCapacity . decrement . minGracePeriodAfterLastDecrementMinutes ) ;
135
+
136
+ let isBelowThreshold = Throughput . getWriteCapacityUtilisationPercent ( data ) <
137
+ config . writeCapacity . decrement . thresholdPercent ;
138
+
139
+ let isAboveMax = data . ProvisionedThroughput . WriteCapacityUnits >
140
+ config . writeCapacity . max ;
141
+
142
+ return isWriteDecrementAllowed && ( isBelowThreshold || isAboveMax ) ;
98
143
} ,
99
144
calculateValue : data => {
100
- invariant ( typeof data !== 'undefined' ,
101
- 'Parameter \'data\' is not set' ) ;
145
+ invariant ( typeof data !== 'undefined' , 'Parameter \'data\' is not set' ) ;
102
146
103
- return Math . max ( data . ConsumedThroughput . WriteCapacityUnits , 1 ) ;
147
+ return Math . max ( data . ConsumedThroughput . WriteCapacityUnits , config . writeCapacity . min ) ;
104
148
} ,
105
149
}
106
150
}
@@ -125,8 +169,7 @@ export default {
125
169
}
126
170
} ,
127
171
getTableUpdate : ( description , consumedCapacityDescription ) => {
128
- invariant ( typeof description !== 'undefined' ,
129
- 'Parameter \'description\' is not set' ) ;
172
+ invariant ( typeof description !== 'undefined' , 'Parameter \'description\' is not set' ) ;
130
173
invariant ( typeof consumedCapacityDescription !== 'undefined' ,
131
174
'Parameter \'consumedCapacityDescription\' is not set' ) ;
132
175
0 commit comments