Skip to content

Commit 8c0ea81

Browse files
committed
WIP
1 parent c0735f2 commit 8c0ea81

16 files changed

+1366
-603
lines changed

.projen/deps.json

Lines changed: 23 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.projen/tasks.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.projenrc.ts

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,24 @@
11
import { clickupCdk } from '@time-loop/clickup-projen';
2+
3+
const name = 'cdk-lambda-eni-usage-metric-publisher';
24
const project = new clickupCdk.ClickUpCdkConstructLibrary({
3-
author: 'jose-clickup',
4-
authorAddress: 'jamoroso@clickup.com',
5-
cdkVersion: '2.99.0',
5+
author: 'Andrew Hammond',
6+
authorAddress: 'ahammond@clickup.com',
7+
cdkVersion: '2.107.0',
68
defaultReleaseBranch: 'main',
7-
devDeps: ['@time-loop/clickup-projen', '@aws-cdk/integ-tests-alpha', 'aws-sdk-mock'],
9+
devDeps: ['@types/aws-lambda', '@time-loop/clickup-projen', '@aws-cdk/integ-tests-alpha'],
810
jsiiVersion: '~5.0.0',
9-
name: 'cdk-lambda-eni-usage-metric-publisher',
11+
name,
1012
projenrcTs: true,
11-
repositoryUrl: 'https://github.com/time-loop/cdk-lambda-eni-usage-metric-publisher.git',
13+
repositoryUrl: `https://github.com/time-loop/${name}.git`,
1214
gitignore: ['.vscode/**'],
13-
bundledDeps: ['aws-sdk'],
15+
bundledDeps: [
16+
'@aws-lambda-powertools/metrics',
17+
'@aws-lambda-powertools/parameters',
18+
'@aws-sdk/client-ssm', // Might not need this. Will we be pulling from SSM in lambda?
19+
'@aws-sdk/client-secrets-manager',
20+
'ioredis',
21+
],
1422
peerDeps: ['multi-convention-namer'],
15-
// deps: [] /* Runtime dependencies of this module. */,
16-
// description: undefined, /* The description is just a string that helps people understand the purpose of the package. */
17-
// packageName: undefined, /* The "name" in package.json. */
1823
});
1924
project.synth();

package.json

Lines changed: 15 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/construct.handler.ts

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
import * as awsLambda from 'aws-lambda';
2+
3+
4+
import { getSecrets, getRedisConnection, getQueueDepth, publishMetrics } from './methods';
5+
6+
7+
export interface Result {
8+
region: string;
9+
vpcId: string;
10+
count: number;
11+
}
12+
13+
14+
export const handler = async () => {
15+
try {
16+
const host = process.env.REDIS_ADDR;
17+
if (!host) {
18+
throw new Error('REDIS_ADDR environment variable not set');
19+
}
20+
21+
const portStr = process.env.REDIS_PORT;
22+
if (!portStr) {
23+
throw new Error('REDIS_PORT environment variable not set');
24+
}
25+
const port = parseInt(portStr, 10);
26+
if (isNaN(port)) {
27+
throw new Error('REDIS_PORT environment variable does not parseInt');
28+
}
29+
30+
// parse queues
31+
const queuesBlob = process.env.QUEUES;
32+
if (!queuesBlob) {
33+
throw new Error('QUEUES environment variable not set');
34+
}
35+
const queues: string[] = JSON.parse(queuesBlob);
36+
37+
// get username/password
38+
const redisSecretArn = process.env.REDIS_SECRET_ARN;
39+
if (!redisSecretArn) {
40+
throw new Error('REDIS_SECRET_ARN environment variable not set');
41+
}
42+
43+
const redisSecretPasswordPath = process.env.REDIS_SECRET_PASSWORD_PATH;
44+
if (!redisSecretPasswordPath) {
45+
throw new Error('REDIS_SECRET_PASSWORD_PATH environment variable not set');
46+
}
47+
48+
const redisSecretUsernamePath = process.env.REDIS_SECRET_USERNAME_PATH;
49+
if (!redisSecretUsernamePath) {
50+
throw new Error('REDIS_SECRET_USERNAME_PATH environment variable not set');
51+
}
52+
53+
const { username, password } = await getSecrets({redisSecretArn, redisSecretPasswordPath, redisSecretUsernamePath });
54+
55+
// connect to redis instance, note this waits until the connection is 'ready'.
56+
const redisConnection = await getRedisConnection({
57+
connectionName: 'queueDepthMetricPublisher',
58+
host,
59+
port,
60+
username,
61+
password,
62+
tls: {}, // always use tls, but be easy about it.
63+
});
64+
65+
// capture the values for the queues
66+
const results = await Promise.all(queues.map(async(queueName) => {
67+
let depth = await getQueueDepth({redisConnection, queueName});
68+
if(!depth) {
69+
console.error(`Error fetching xlen for ${queueName}`);
70+
depth = -1;
71+
}
72+
return {queueName, depth};
73+
}));
74+
75+
if(results === undefined) {
76+
throw new Error('Error fetching ALL queue depths');
77+
}
78+
79+
// publish the metrics
80+
publishMetrics(results);
81+
82+
83+
} catch (error) {
84+
console.error('Error publishing metric data', error);
85+
throw error;
86+
}
87+
};

0 commit comments

Comments
 (0)