Skip to content

Commit

Permalink
fix: fixed throttle issue for getProvisionedConcurrency
Browse files Browse the repository at this point in the history
  • Loading branch information
theburningmonk committed Dec 10, 2020
1 parent 5114f9a commit 1c1bb2f
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
5 changes: 5 additions & 0 deletions package-lock.json

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

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"analytics-node": "^3.4.0-beta.1",
"async": "^3.1.0",
"async-retry": "^1.2.3",
"async-sema": "^3.1.0",
"aws-sdk": "^2.584.0",
"axios": "^0.19.0",
"bluebird": "^3.5.5",
Expand Down
9 changes: 6 additions & 3 deletions src/commands/analyze-lambda-cold-starts.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const { checkVersion } = require("../lib/version-check");
const Lambda = require("../lib/lambda");
const Retry = require("async-retry");
const { track } = require("../lib/analytics");
const { RateLimit } = require("async-sema");
require("colors");

const ONE_MIN_IN_MILLIS = 60 * 1000;
Expand Down Expand Up @@ -106,6 +107,7 @@ class AnalyzeLambdaColdStartsCommand extends Command {

const AWS = getAWSSDK();
const Lambda = new AWS.Lambda({ region });
const rateLimit = RateLimit(10); // rps

this.log(
`${region}: analyzing Provisioned Concurrency for ${functionNames.length} functions`
Expand All @@ -117,6 +119,7 @@ class AnalyzeLambdaColdStartsCommand extends Command {
qualifiers = [],
marker
) => {
await rateLimit();
const resp = await Lambda.listProvisionedConcurrencyConfigs({
FunctionName: functionName,
Marker: marker
Expand Down Expand Up @@ -171,7 +174,7 @@ class AnalyzeLambdaColdStartsCommand extends Command {
return _.fromPairs(pairs);
}

async utilizationMetric(functionName, qualifier) {
utilizationMetric(functionName, qualifier) {
return {
Id:
functionName.toLowerCase().replace(/\W/g, "") +
Expand Down Expand Up @@ -202,12 +205,12 @@ class AnalyzeLambdaColdStartsCommand extends Command {
async getProvisionedConcurrencyUtilization(region, functions) {
const AWS = getAWSSDK();
const CloudWatch = new AWS.CloudWatch({ region });

const startTime = new Date(Date.now() - global.minutes * ONE_MIN_IN_MILLIS);
const queries = _.flatMap(functions, ({ functionName, qualifiers }) =>
qualifiers.map(qualifier => this.utilizationMetric(functionName, qualifier))
);

// CloudWatch only allows 100 queries per request
const promises = _.chunk(queries, 100).map(async chunk => {
const resp = await CloudWatch.getMetricData({
Expand Down

0 comments on commit 1c1bb2f

Please sign in to comment.