Skip to content

Commit 493b72b

Browse files
authored
Merge pull request #1 from time-loop/badge
chore: README updates
2 parents 8c0ea81 + 3bc0e5f commit 493b72b

File tree

3 files changed

+40
-21
lines changed

3 files changed

+40
-21
lines changed

README.md

Lines changed: 31 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,51 @@
1-
# LambdaEniUsageMetricPublisher
2-
A construct that creates an AWS Lambda function to publish ENI usage metrics to CloudWatch.
1+
[![codecov](https://codecov.io/gh/time-loop/cdk-redis-queue-depth-metric-publisher/graph/badge.svg?token=ks9w215OJm)](https://codecov.io/gh/time-loop/cdk-redis-queue-depth-metric-publisher)
2+
3+
# RedisQueueDepthMetricPublisher
4+
A construct that creates an AWS Lambda function to publish
5+
queue depths from a redis instance
36

47
## Usage
5-
To use the `LambdaEniUsageMetricPublisher` construct, simply import it into your AWS CDK stack and create a new instance of the construct:
8+
To use the `RedisQueueDepthMetricPublisher` construct, simply import it into your AWS CDK stack and create a new instance of the construct:
69

710
``` ts
811
import { Stack } from 'aws-cdk-lib';
9-
import { LambdaEniUsageMetricPublisher } from './lambda-eni-usage-metric-publisher';
10-
11-
const stack = new Stack(app, 'MyStack');
12-
13-
new LambdaEniUsageMetricPublisher(stack, 'MyLambdaEniUsageMetricPublisher', {
14-
publishFrequency: 5,
15-
regions: ['us-east-1', 'us-west-2'],
16-
cwNamespace: 'MyNamespace',
12+
import { RedisQueueDepthMetricPublisher } from './cdk-redis-queue-depth-metric-publisher';
13+
14+
let stack: Stack;
15+
16+
new RedisQueueDepthMetricPublisher(stack, 'RedisQueueDepthMetricPublisher', {
17+
cwNamespace: 'example',
18+
cloudwatchLogsRetention: RetentionDays.THREE_MONTHS,
19+
publishFrequency: Duration.minutes(5),
20+
queues: ['fakeQueue', 'fakeQueue2'],
21+
redisAddr: 'fakeRedisAddr',
22+
// redisPort: '123456', // Optional
23+
redisSecretArn: 'fakeRedisSecretArn',
24+
redisSecretKeyArn: 'fakeRedisSecretKeyArn',
25+
// redisSecretPasswordPath: 'fakeRedisSecretPasswordPath',
26+
// redisSecretUsernamePath: 'fakeRedisSecretUsernamePath',
1727
});
1828
```
1929

20-
This will create a new AWS Lambda function that publishes ENI usage metrics to CloudWatch every 5 minutes for the `us-east-1` and `us-west-2` regions, using the `MyNamespace` namespace.
30+
This will create a new AWS Lambda function that publishes queue depth metrics to CloudWatch every 5
31+
minutes. It pulls the information from the `fakeRedisAddr` redis instance on the default port.
32+
It will fetch login credentials from `redisSecretArn`, log into the redis instance and query
33+
the two queues `['fakeQueue', 'fakeQueue2']`, then publish the info to the `cwNamespace` with
34+
metric names that are identical to the queue names.
35+
NOTE: no mapping is currently supported for the queue names.
2136

2237
## API
23-
`LambdaEniUsageMetricPublisher(scope: Construct, id: string, props: LambdaEniUsageMetricPublisherProps)`
38+
`RedisQueueDepthMetricPublisher(scope: Construct, id: string, props: RedisQueueDepthMetricPublisherProps)`
2439

25-
Creates a new instance of the `LambdaEniUsageMetricPublisher` construct.
40+
Creates a new instance of the `RedisQueueDepthMetricPublisher` construct.
2641

2742
### Parameters
2843
- `scope` - The parent construct.
2944
- `id` - The ID of the construct.
3045
- `props` - The properties of the construct.
3146

47+
WRITEME FROM HERE DOWN
48+
3249
### Properties
3350
- `publishFrequency` - The time interval (in minutes) that the Lambda function will be triggered to publish metrics to CloudWatch.
3451
- `regions` - The list of AWS regions to publish ENI usage metrics for.

src/construct.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ export interface RedisQueueDepthMetricPublisherProps {
2121
readonly cwNamespace?: string;
2222
/**
2323
* Time intervals that Lambda will be triggered to publish metric in CloudWatch.
24-
* @default 1
24+
* @default Duration.minutes(1)
2525
*/
26-
readonly publishFrequency?: number;
26+
readonly publishFrequency?: Duration;
2727
/**
2828
* List of queues to measure depth for.
2929
*/
@@ -81,7 +81,7 @@ export interface RedisQueueDepthMetricPublisherProps {
8181
* A construct that creates an AWS Lambda function to publish ENI usage metrics to CloudWatch.
8282
*/
8383
export class RedisQueueDepthMetricPublisher extends Construct {
84-
readonly publishFrequency: number;
84+
readonly publishFrequency: Duration;
8585
readonly regions: string[];
8686
readonly handler: NodejsFunction;
8787
readonly rule: Rule;
@@ -96,7 +96,7 @@ export class RedisQueueDepthMetricPublisher extends Construct {
9696

9797
constructor(scope: Construct, id: Namer, props: RedisQueueDepthMetricPublisherProps) {
9898
super(scope, id.pascal);
99-
this.publishFrequency = props.publishFrequency ?? 1;
99+
this.publishFrequency = props.publishFrequency ?? Duration.minutes(1);
100100
this.cwNamespace = props.cwNamespace ?? 'RedisQueueDepth';
101101
const myConstruct = this;
102102

@@ -149,7 +149,7 @@ export class RedisQueueDepthMetricPublisher extends Construct {
149149
.addEnvironment('REDIS_SECRET_USERNAME_PATH', props.redisSecretUsernamePath ?? 'username')
150150

151151
this.rule = new Rule(this, 'rule', {
152-
schedule: Schedule.rate(Duration.minutes(this.publishFrequency)),
152+
schedule: Schedule.rate(this.publishFrequency),
153153
});
154154
this.rule.addTarget(new LambdaFunction(this.handler));
155155
}

test/construct.test.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
import { App, Stack } from 'aws-cdk-lib';
1+
import { App, Duration, Stack } from 'aws-cdk-lib';
22
import { Template } from 'aws-cdk-lib/assertions';
3+
import { RetentionDays } from 'aws-cdk-lib/aws-logs';
34
import { Namer } from 'multi-convention-namer';
45
import { RedisQueueDepthMetricPublisher, RedisQueueDepthMetricPublisherProps } from '../src/construct';
56

@@ -14,7 +15,8 @@ beforeEach(() => {
1415
let template: Template;
1516
const defaultRedisQueueDepthMetricPublisherProps: RedisQueueDepthMetricPublisherProps = {
1617
cwNamespace: 'example',
17-
cloudwatchLogsRetention: 7,
18+
cloudwatchLogsRetention: RetentionDays.TWO_WEEKS,
19+
publishFrequency: Duration.seconds(5),
1820
queues: ['fakeQueue', 'fakeQueue2'],
1921
redisAddr: 'fakeRedisAddr',
2022
redisPort: '123456',

0 commit comments

Comments
 (0)