Skip to content
This repository was archived by the owner on Dec 1, 2022. It is now read-only.

Commit bbe2c00

Browse files
committed
Improved logging
1 parent c7c2dbb commit bbe2c00

File tree

2 files changed

+105
-42
lines changed

2 files changed

+105
-42
lines changed

src/Config.js

Lines changed: 102 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -53,25 +53,32 @@ const provisioner = new ConfigurableProvisioner({
5353

5454
let readCapacityPercent = Throughput.getReadCapacityUtilisationPercent(data);
5555
let isAboveThreshold = readCapacityPercent > config.readCapacity.increment.thresholdPercent;
56-
let isBelowMin = data.ProvisionedThroughput.ReadCapacityUnits <
57-
config.readCapacity.min;
56+
let isBelowMin = data.ProvisionedThroughput.ReadCapacityUnits < config.readCapacity.min;
57+
let isAtMax = data.ProvisionedThroughput.ReadCapacityUnits >= config.readCapacity.max;
5858
let isAdjustmentRequired = isAboveThreshold || isBelowMin;
5959

60-
let logName = typeof data.IndexName === 'undefined' ? data.TableName :
60+
// Logging
61+
let logMessage = typeof data.IndexName === 'undefined' ? data.TableName :
6162
data.TableName + '.' + data.IndexName;
62-
63-
if (isAboveThreshold) {
64-
log(logName + ' is at ' + readCapacityPercent +
65-
'% read capacity and above threshold of ' +
66-
config.readCapacity.increment.thresholdPercent + '%');
67-
} else if (isBelowMin) {
68-
log(logName + ' is at ' + readCapacityPercent +
69-
'% read capacity and below minimum of ' + config.readCapacity.min + '%');
70-
} else if (readCapacityPercent > 0) {
71-
log(logName + ' is at ' + readCapacityPercent +
72-
'% read capacity and within minimum of ' + config.readCapacity.min +
73-
'% and threshold of ' + config.readCapacity.increment.thresholdPercent + '%');
63+
logMessage += ' is consuming ' + data.ConsumedThroughput.ReadCapacityUnits + ' of ' +
64+
data.ProvisionedThroughput.ReadCapacityUnits + ' (' + readCapacityPercent +
65+
'%) read capacity units';
66+
if (isAtMax) {
67+
logMessage += ' and is already at max allowed ' + config.readCapacity.max + ' units';
68+
}
69+
if (isAboveThreshold && !isAtMax) {
70+
logMessage += ' and is above maximum threshold of ' +
71+
config.readCapacity.increment.thresholdPercent + '%';
72+
}
73+
if (isBelowMin) {
74+
logMessage += ' and is below the min allowed ' + config.readCapacity.min + ' units';
75+
}
76+
if (isAdjustmentRequired) {
77+
logMessage += ' so an increment is REQUIRED';
78+
} else {
79+
logMessage += ' so an increment is not required';
7480
}
81+
log(logMessage);
7582

7683
return isAdjustmentRequired;
7784
},
@@ -101,11 +108,37 @@ const provisioner = new ConfigurableProvisioner({
101108

102109
let readCapacityPercent = Throughput.getReadCapacityUtilisationPercent(data);
103110
let isBelowThreshold = readCapacityPercent < config.readCapacity.decrement.thresholdPercent;
104-
let isAboveMax = data.ProvisionedThroughput.ReadCapacityUnits >
105-
config.readCapacity.max;
106-
107-
let isAdjustmentWanted = isBelowThreshold || isAboveMax;
111+
let isAboveMax = data.ProvisionedThroughput.ReadCapacityUnits > config.readCapacity.max;
112+
let isAtMin = data.ProvisionedThroughput.ReadCapacityUnits <= config.readCapacity.min;
113+
let isAdjustmentWanted = (isBelowThreshold || isAboveMax) && !isAtMin;
108114
let isAdjustmentRequired = isReadDecrementAllowed && isAdjustmentWanted;
115+
116+
// Logging
117+
let logMessage = typeof data.IndexName === 'undefined' ? data.TableName :
118+
data.TableName + '.' + data.IndexName;
119+
logMessage += ' is consuming ' + data.ConsumedThroughput.ReadCapacityUnits + ' of ' +
120+
data.ProvisionedThroughput.ReadCapacityUnits + ' (' + readCapacityPercent +
121+
'%) read capacity units';
122+
if (isAtMin) {
123+
logMessage += ' and is already at min allowed ' + config.readCapacity.min + ' units';
124+
}
125+
if (isBelowThreshold && !isAtMin) {
126+
logMessage += ' and is below minimum threshold of ' +
127+
config.readCapacity.decrement.thresholdPercent + '%';
128+
}
129+
if (isAboveMax) {
130+
logMessage += ' and is above the max allowed ' + config.readCapacity.max + ' units';
131+
}
132+
if (isAdjustmentWanted) {
133+
logMessage += ' so a decrement is REQUESTED';
134+
} else {
135+
logMessage += ' so a decrement is not required';
136+
}
137+
if (isAdjustmentWanted && !isReadDecrementAllowed) {
138+
logMessage += ' but has been DISALLOWED due to rate limiting';
139+
}
140+
log(logMessage);
141+
109142
return isAdjustmentRequired;
110143
},
111144
calculateValue: data => {
@@ -125,24 +158,32 @@ const provisioner = new ConfigurableProvisioner({
125158
let writeCapacityPercent = Throughput.getWriteCapacityUtilisationPercent(data);
126159
let isAboveThreshold = writeCapacityPercent >
127160
config.writeCapacity.increment.thresholdPercent;
161+
let isAtMax = data.ProvisionedThroughput.WriteCapacityUnits >= config.writeCapacity.max;
128162
let isBelowMin = data.ProvisionedThroughput.WriteCapacityUnits < config.writeCapacity.min;
129163
let isAdjustmentRequired = isAboveThreshold || isBelowMin;
130164

131-
let logName = typeof data.IndexName === 'undefined' ? data.TableName :
165+
// Logging
166+
let logMessage = typeof data.IndexName === 'undefined' ? data.TableName :
132167
data.TableName + '.' + data.IndexName;
133-
134-
if (isAboveThreshold) {
135-
log(logName + ' is at ' + writeCapacityPercent +
136-
'% write capacity and above threshold of ' +
137-
config.writeCapacity.increment.thresholdPercent + '%');
138-
} else if (isBelowMin) {
139-
log(logName + ' is at ' + writeCapacityPercent +
140-
'% write capacity and below minimum of ' + config.writeCapacity.min + '%');
141-
} else if (writeCapacityPercent > 0) {
142-
log(logName + ' is at ' + writeCapacityPercent +
143-
'% write capacity and within minimum of ' + config.writeCapacity.min +
144-
'% and threshold of ' + config.writeCapacity.increment.thresholdPercent + '%');
168+
logMessage += ' is consuming ' + data.ConsumedThroughput.WriteCapacityUnits + ' of ' +
169+
data.ProvisionedThroughput.WriteCapacityUnits + ' (' + writeCapacityPercent +
170+
'%) write capacity units';
171+
if (isAtMax) {
172+
logMessage += ' and is already at max allowed ' + config.writeCapacity.max + ' units';
173+
}
174+
if (isAboveThreshold && !isAtMax) {
175+
logMessage += ' and is above maximum threshold of ' +
176+
config.writeCapacity.increment.thresholdPercent + '%';
177+
}
178+
if (isBelowMin) {
179+
logMessage += ' and is below the min allowed ' + config.writeCapacity.min + ' units';
180+
}
181+
if (isAdjustmentRequired) {
182+
logMessage += ' so an increment is REQUIRED';
183+
} else {
184+
logMessage += ' so an increment is not required';
145185
}
186+
log(logMessage);
146187

147188
return isAdjustmentRequired;
148189
},
@@ -173,10 +214,37 @@ const provisioner = new ConfigurableProvisioner({
173214
let writeCapacityPercent = Throughput.getWriteCapacityUtilisationPercent(data);
174215
let isBelowThreshold = writeCapacityPercent <
175216
config.writeCapacity.decrement.thresholdPercent;
176-
217+
let isAtMin = data.ProvisionedThroughput.WriteCapacityUnits <= config.writeCapacity.min;
177218
let isAboveMax = data.ProvisionedThroughput.WriteCapacityUnits > config.writeCapacity.max;
178-
let isAdjustmentWanted = isBelowThreshold || isAboveMax;
219+
let isAdjustmentWanted = (isBelowThreshold || isAboveMax) && !isAtMin;
179220
let isAdjustmentRequired = isWriteDecrementAllowed && isAdjustmentWanted;
221+
222+
// Logging
223+
let logMessage = typeof data.IndexName === 'undefined' ? data.TableName :
224+
data.TableName + '.' + data.IndexName;
225+
logMessage += ' is consuming ' + data.ConsumedThroughput.WriteCapacityUnits + ' of ' +
226+
data.ProvisionedThroughput.WriteCapacityUnits + ' (' + writeCapacityPercent +
227+
'%) write capacity units';
228+
if (isAtMin) {
229+
logMessage += ' and is already at min allowed ' + config.writeCapacity.min + ' units';
230+
}
231+
if (isBelowThreshold && !isAtMin) {
232+
logMessage += ' and is below minimum threshold of ' +
233+
config.writeCapacity.decrement.thresholdPercent + '%';
234+
}
235+
if (isAboveMax) {
236+
logMessage += ' and is above the max allowed ' + config.writeCapacity.max + ' units';
237+
}
238+
if (isAdjustmentWanted) {
239+
logMessage += ' so a decrement is REQUESTED';
240+
} else {
241+
logMessage += ' so a decrement is not required';
242+
}
243+
if (isAdjustmentWanted && !isWriteDecrementAllowed) {
244+
logMessage += ' but has been DISALLOWED due to rate limiting';
245+
}
246+
log(logMessage);
247+
180248
return isAdjustmentRequired;
181249
},
182250
calculateValue: data => {

src/RateLimitedDecrement.js

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,8 @@ export default class RateLimitedDecrement {
2525
return false;
2626
}
2727

28-
let adjustment = data.ProvisionedThroughput.ReadCapacityUnits -
29-
calcNewValueFunc(data);
30-
31-
if (adjustment < minAdjustment &&
32-
this.getNowDate().valueOf() <
28+
let adjustment = data.ProvisionedThroughput.ReadCapacityUnits - calcNewValueFunc(data);
29+
if (adjustment < minAdjustment && this.getNowDate().valueOf() <
3330
this.getLastAllowedDecrementDate().valueOf()) {
3431
// Disallow if the adjustment is very small.
3532
// However, if we have crossed the last time
@@ -62,9 +59,7 @@ export default class RateLimitedDecrement {
6259
return false;
6360
}
6461

65-
let adjustment = data.ProvisionedThroughput.WriteCapacityUnits -
66-
calcNewValueFunc(data);
67-
62+
let adjustment = data.ProvisionedThroughput.WriteCapacityUnits - calcNewValueFunc(data);
6863
if (adjustment < minAdjustment && this.getNowDate().valueOf() <
6964
this.getLastAllowedDecrementDate().valueOf()) {
7065
// Disallow if the adjustment is very small.

0 commit comments

Comments
 (0)