Skip to content

Commit

Permalink
TypeScript migration (#105)
Browse files Browse the repository at this point in the history
* Add AppSync Support

* Handle lifecycle hook

* Add alarms and dashboard widgets for AppSync
- Remove redundant resources

* Use different y-axes for metrics of different units
- Tidy up the branch

* Migrate TS from JS

* Restructure alarms and dashboards

* Use a library for alarm properties
- Lib is called cloudform which gives us ability to write less types and be certain about the types of each property

* Fix GitHub actions

* Refactor alarm modules and combine additional resources into compiledTemplate

* Manage packages, remove redundant use-strict
- 'use strict' can be manageble for each module  at top level as we use alwaysStrict in the tscofig
- Fix some types

* Sam requires esbuild to be installed globally
- Manage common packages at the top level
- Fix modules paths in cf-macro/index

* Edit alarm names by using intrinsic functions to retrieve actual data from cloudformation
- Manage packages, remove redundant use-strict line in each as we manage alwaysStrict at top level
- Instal cloudform lib at dependecy level as sam requires

* Macro requires handler to be async
Use intrinsic functions for alarm names and alarm descriptions to retrieve actual data from cloudformation

* Manage all AlarmName and AlarmDescription specific to each modules

* Upgrade node version for ALB and AppSync projects
- Make sure all AlarmName and AlarmDescription same as before

* Fix types confusion for the default config

* For input types use also cloudformation properties types

* Using generics to split the type into pre and post merged types. I've extended the config types too to allow the cascaded flow of properties to be typed

* Assign all missing config types
- Fix the unit-test

* Change the import path in index files

* Change back the import path for now

* Fix slic-watch-core workspace issue

* chore: update build to do TS compilation

* chore: update macro version sync to use CommonJS

* 3.0.0-rc1

* Version bump: 3.0.0-rc1

* chore: remove superfluous slic-watch-core dependency

* chore: add ALB project test to build workflow

* chore: include all package in version script

* chore: clean up deps

* chore: include all package in version script

* chore: ensure macro version change is committed and tagged

* 3.0.0-rc2

* This might work

* Converting to commonjs

* fixing lint

* finishing commonjs modules change

* Use tap to create coverage report, delete c8 report provider

* fixing up code coverage

* Update unit-test scripts

* adding the cf-macro v3

* Fix some coverage issues

* increased coverage to 100%

* chore: fix comment indent

* 3.0.0-rc3

* chore: update versions with audit fix

* chore: add TS build to release workflow

* chore: add TS build to build workflow

* bundling packages again

* fixing lambdas not configured bug

* 3.0.0-rc4

* Fixing issues around the resourceId naming

* Forcing update of alarm names which will redeploy all API Gateway alarms created by slic watch. This is to force a few naming fixing bugs

* 3.0.0-rc5

* chore: update to current Node LTS (18, 20)

* fix: restore logging in sls plugin, use Tap 18

* Allow incomplete coverage

- Node 18 is falsely reporting incomplete coverage, so we'll only
  use Node 20+ coverage reports for measurement in the automated build.
  (example:
https://github.com/fourTheorem/slic-watch/actions/runs/6705742466/job/18220791453)

* chore: ignore coveralls for 18.x

* chore: rename items and add more comments

* chore: use more consistent logical IDs for alarms

- This means new resources will be created, so Alarm names are altered
  too to prevent "already exists" deployment failures

* chore: use portable bucket names in test projects

* fix(docs): remove v2 supported label from README

---------

Co-authored-by: davidlynam <[email protected]>
Co-authored-by: Eoin Shanaghy <[email protected]>
  • Loading branch information
3 people authored Nov 2, 2023
1 parent 94eb90f commit 1f224f2
Show file tree
Hide file tree
Showing 142 changed files with 22,987 additions and 48,308 deletions.
14 changes: 0 additions & 14 deletions .eslintrc.js

This file was deleted.

25 changes: 25 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"root": true,
"plugins": [
"@typescript-eslint"
],
"extends": [
"standard-with-typescript"
],
"parserOptions": {
"project": "./tsconfig.json"
},
"rules": {
"@typescript-eslint/no-floating-promises": 0,
"no-template-curly-in-string": 0,
"@typescript-eslint/restrict-template-expressions": 0,
"@typescript-eslint/explicit-function-return-type": 0
},
"ignorePatterns": [
"core/coverage",
"cf-macro/coverage",
"serverless-plugin/dist/index.js",
"cf-macro/dist/index.js",
"**/dist/*"
]
}
36 changes: 21 additions & 15 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,31 +14,37 @@ jobs:

strategy:
matrix:
node-version: [14, 16, 18]
node-version: [18, 20]

steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v2
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}.x
- name: Ensure npm >= 7
run: npm i -g npm@^7
cache: 'npm'
- run: npm ci
- run: npm run audit
- run: npm test
- name: Coveralls Parallel
name: Run unit tests
- name: Build TypeScript
run: npm run build
- working-directory: ./serverless-test-project
run: npm test
name: Run Serverless Framework packaging test
- working-directory: ./serverless-test-project-alb
name: Run Serverless Framework packaging test for ALB test project
run: npm test
- working-directory: ./serverless-test-project-appsync
name: Run Serverless Framework packaging test for AppSync test project
run: npm test
- name: Coveralls
uses: coverallsapp/github-action@master
with:
github-token: ${{ secrets.github_token }}
flag-name: run-node-${{ matrix.node-version }}
parallel: true
path-to-lcov: coverage/lcov.info
- name: Package test project with Serverless v2
working-directory: ./serverless-test-project
run: |
npm i serverless@2
npm run test:v2
path-to-lcov: .tap/report/lcov.info
if: ${{ matrix.node-version != 18 }} # Node 18 is reporting inaccurate coverage data, so we ignore its report

finish:
needs: build
runs-on: ubuntu-latest
Expand All @@ -48,4 +54,4 @@ jobs:
with:
github-token: ${{ secrets.github_token }}
parallel-finished: true
path-to-lcov: coverage/lcov.info
path-to-lcov: .tap/report/lcov.info
4 changes: 3 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
- name: Set up Node.js
uses: actions/setup-node@v2
with:
node-version: 16.x
node-version: 18.x
registry-url: "https://registry.npmjs.org"
- name: Use npm 8
run: npm install -g npm@^8
Expand All @@ -39,6 +39,8 @@ jobs:
run: npm install esbuild -g
- name: Install dependencies
run: npm ci
- name: Build TypeScript
run: npm run build
- name: NPM security audit
run: npm run audit
- name: configure aws credentials
Expand Down
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ __pycache__/
build/
develop-eggs/
dist/
core/dist/
downloads/
eggs/
.eggs/
Expand Down Expand Up @@ -249,6 +250,7 @@ src/

node_modules/
.nyc_output/
.tap/
.serverless/
coverage/
.vscode/
Expand All @@ -257,4 +259,4 @@ lerna-debug*


samconfig.toml
packaged.yaml
packaged.yaml
32 changes: 25 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@

Automatic, best-practice CloudWatch **Dashboards** and **Alarms** for your SAM, CloudFormation, CDK and Serverless Framework applications.

SLIC Watch supports: _AWS Lambda, API Gateway, DynamoDB, Kinesis Data Streams, SQS Queues, Step Functions, ECS (Fargate or EC2), SNS, EventBridge and Application Load Balancer._
SLIC Watch supports: _AWS Lambda, API Gateway, DynamoDB, Kinesis Data Streams, SQS Queues, Step Functions, ECS (Fargate or EC2), SNS, EventBridge, Application Load Balancer and AppSync._

Supported tools include:
* ⚡️ **Serverless Framework** v2 and v3 via the [_SLIC Watch Serverless Plugin_](#getting-started-with-serverless-framework)
* ⚡️ **Serverless Framework** v3 via the [_SLIC Watch Serverless Plugin_](#getting-started-with-serverless-framework)
* 🐿 **AWS SAM**, 📦 **AWS CDK** and ☁️ **CloudFormation** using the [_CloudFormation Macro_](#getting-started-with-aws-sam-cdk-or-cloudformation), published in the Serverless Application Repository (SAR).

## Contents
Expand All @@ -33,6 +33,7 @@ Supported tools include:
- [SNS](#sns)
- [EventBridge](#eventbridge)
- [Application Load Balancer](#application-load-balancer)
- [AppSync](#appsync)
- [Configuration](#configuration)
- [Top-level configuration](#top-level-configuration)
- [Function-level configuration](#function-level-configuration)
Expand Down Expand Up @@ -96,6 +97,11 @@ The snippet of CloudFormation is as follows.
ApplicationId: arn:aws:serverlessrepo:eu-west-1:949339270388:applications~slic-watch-app
SemanticVersion: <enter latest version>
```
To determine the list of available versions, you can use the AWS CLI:
```bash
aws serverlessrepo list-application-versions \
--application-id arn:aws:serverlessrepo:eu-west-1:949339270388:applications/slic-watch-app
```
- **Option 3** (manual Macro deployment using SAM directly from source):
```bash
npm install
Expand All @@ -108,7 +114,7 @@ Once you have deployed the macro, you can start using SLIC Watch in SAM or Cloud
```yaml
Transform:
- ...
- SlicWatch-v2
- SlicWatch-v3
```

🪛 _Optionally_, add some configuration for the plugin to the `Metadata -> slicWatch` section of `template.yml`.
Expand All @@ -134,24 +140,24 @@ export class MyStack extends cdk.Stack {
constructor (scope: cdk.App, id: string, props?: cdk.StackProps) {
super(scope, id, props)
this.addTransform('SlicWatch-v2')
this.addTransform('SlicWatch-v3')
...
}
}
```

```python
# Python:
self.add_transform("SlicWatch-v2")
self.add_transform("SlicWatch-v3")
```
```csharp
// C#:
this.AddTransform("SlicWatch-v2")
this.AddTransform("SlicWatch-v3")
```

```java
// Java:
this.addTransform("SlicWatch-v2");
this.addTransform("SlicWatch-v3");
```

🪛 _Optionally_, add some configuration for the plugin as below:
Expand Down Expand Up @@ -303,6 +309,18 @@ Application Load Balancer dashboard widgets show:
|**UnHealthy Host Count**|**Lambda User Error**|**Lambda Internal Error**|
|![UnHealthyHostCount](https://raw.githubusercontent.com/fourtheorem/slic-watch/main/docs/unHealthyHostCount.png) |![LambdaUserError](https://raw.githubusercontent.com/fourtheorem/slic-watch/main/docs/lambdaUserError.png)| |

### AppSync
AppSync alarms are created for:
1. 5XX Error
2. Latency

AppSync dashboard widgets show:

|5XX Error, Latency, 4XX Error, Request|
|--|
|![API Widget](https://raw.githubusercontent.com/fourtheorem/slic-watch/main/docs/appsyncAPI.png)|
|**Connect Server Error**, **Disconnect Server Error**, **Subscribe Server Error**, **Unsubscribe Server Error**,**PublishDataMessageServerError**|
|![Real-time Subscriptions Widget](https://raw.githubusercontent.com/fourtheorem/slic-watch/main/docs/appsyncRealTimeSubscriptions.png)|
## Configuration

Configuration is entirely optional - SLIC Watch provides defaults that work out of the box.
Expand Down
6 changes: 3 additions & 3 deletions RELEASING.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

In order to release a new version of the project:

- update the package version with `npm version <version> -ws --include-workspace-root` to apply that version across all sub packages
- push these changes
- draft a new release in GitHub (the CI will do the publish to npm)
1. Update the package version with `npm version <version>` to apply that version across all sub packages. If the Major version has changed, the Macro name will be automatically updated by [the sync-macro-version script](scripts/sync-macro-version.cjs)
2. Push these changes (`git push --tags`)
3. Draft a new release in GitHub (the CI will do the publish to npm) with the same name as the version tag. If you select "pre-release", this will be published in NPM as a `next` label so it will only be installed by users who explictly request the `@next` version.
20 changes: 6 additions & 14 deletions cdk-test-project/package.json
Original file line number Diff line number Diff line change
@@ -1,25 +1,17 @@
{
"name": "cdk-test-project",
"version": "2.1.3",
"version": "3.0.0-rc5",
"scripts": {
"build": "tsc",
"watch": "tsc -w",
"test": "echo",
"cdk": "cdk"
},
"devDependencies": {
"@types/jest": "^27.5.2",
"@types/node": "10.17.27",
"@types/prettier": "2.6.0",
"aws-cdk": "2.37.0",
"eslint-config-standard-with-typescript": "^22.0.0",
"jest": "^27.5.1",
"ts-jest": "^27.1.4",
"ts-node": "^10.9.1",
"typescript": "~3.9.7"
},
"dependencies": {
"aws-cdk-lib": "2.37.0",
"constructs": "^10.0.0"
"aws-cdk-lib": "^2.67.0",
"constructs": "^10.1.266"
},
"devDependencies": {
"aws-cdk": "^2.67.0"
}
}
2 changes: 1 addition & 1 deletion cdk-test-project/source/ecs-stack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export class CdkECSStack extends cdk.Stack {
constructor (scope: cdk.App, id: string, props?: cdk.StackProps) {
super(scope, id, props)

this.addTransform('SlicWatch-v2')
this.addTransform('SlicWatch-v3')
this.templateOptions.metadata = {
slicWatch: {
enabled: true,
Expand Down
16 changes: 8 additions & 8 deletions cdk-test-project/source/general-stack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ import * as sns from 'aws-cdk-lib/aws-sns'
import * as dynamodb from 'aws-cdk-lib/aws-dynamodb'
import * as apigateway from 'aws-cdk-lib/aws-apigateway'
import * as sqs from 'aws-cdk-lib/aws-sqs'
import { CfnResource } from 'aws-cdk-lib'
import type { CfnResource } from 'aws-cdk-lib'
import * as events from 'aws-cdk-lib/aws-events'
import { LambdaFunction } from 'aws-cdk-lib/aws-events-targets'

export class CdkTestGeneralStack extends cdk.Stack {
constructor (scope: cdk.App, id: string, props?: cdk.StackProps) {
super(scope, id, props)

this.addTransform('SlicWatch-v2')
this.addTransform('SlicWatch-v3')
this.templateOptions.metadata = {
slicWatch: {
enabled: true,
Expand Down Expand Up @@ -44,7 +44,7 @@ export class CdkTestGeneralStack extends cdk.Stack {

const helloFunction = new lambda.Function(this, 'HelloHandler',
{
runtime: lambda.Runtime.NODEJS_16_X,
runtime: lambda.Runtime.NODEJS_18_X,
code: lambda.Code.fromAsset('lambda'),
handler: 'hello.handler'
})
Expand All @@ -64,7 +64,7 @@ export class CdkTestGeneralStack extends cdk.Stack {

const pingFunction = new lambda.Function(this, 'PingHandler',
{
runtime: lambda.Runtime.NODEJS_16_X,
runtime: lambda.Runtime.NODEJS_18_X,
code: lambda.Code.fromAsset('lambda'),
handler: 'hello.handler'
})
Expand All @@ -80,29 +80,29 @@ export class CdkTestGeneralStack extends cdk.Stack {

new lambda.Function(this, 'ThrottlerHandler',
{
runtime: lambda.Runtime.NODEJS_16_X,
runtime: lambda.Runtime.NODEJS_18_X,
code: lambda.Code.fromAsset('lambda'),
handler: 'hello.handler',
reservedConcurrentExecutions: 0
})

new lambda.Function(this, 'DriveStreamHandler',
{
runtime: lambda.Runtime.NODEJS_16_X,
runtime: lambda.Runtime.NODEJS_18_X,
code: lambda.Code.fromAsset('lambda'),
handler: 'stream-test-handler.handleDrive'
})

new lambda.Function(this, 'DriveQueueHandler',
{
runtime: lambda.Runtime.NODEJS_16_X,
runtime: lambda.Runtime.NODEJS_18_X,
code: lambda.Code.fromAsset('lambda'),
handler: 'hello.handler'
})

new lambda.Function(this, 'DriveTableHandler',
{
runtime: lambda.Runtime.NODEJS_16_X,
runtime: lambda.Runtime.NODEJS_18_X,
code: lambda.Code.fromAsset('lambda'),
handler: 'hello.handler'
})
Expand Down
7 changes: 4 additions & 3 deletions cdk-test-project/source/sfn-stack.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import * as cdk from 'aws-cdk-lib'
import * as lambda from 'aws-cdk-lib/aws-lambda'
import * as sns from 'aws-cdk-lib/aws-sns'
import { CfnResource, Duration } from 'aws-cdk-lib'
import { Duration } from 'aws-cdk-lib'
import type { CfnResource } from 'aws-cdk-lib'
import * as sfn from 'aws-cdk-lib/aws-stepfunctions'
import { LambdaInvoke } from 'aws-cdk-lib/aws-stepfunctions-tasks'

export class CdkSFNStack extends cdk.Stack {
constructor (scope: cdk.App, id: string, props?: cdk.StackProps) {
super(scope, id, props)

this.addTransform('SlicWatch-v2')
this.addTransform('SlicWatch-v3')
this.templateOptions.metadata = {
slicWatch: {
enabled: true,
Expand Down Expand Up @@ -41,7 +42,7 @@ export class CdkSFNStack extends cdk.Stack {

const hello = new lambda.Function(this, 'HelloHandler',
{
runtime: lambda.Runtime.NODEJS_16_X,
runtime: lambda.Runtime.NODEJS_18_X,
code: lambda.Code.fromAsset('lambda'),
handler: 'hello.handler'
})
Expand Down
Loading

0 comments on commit 1f224f2

Please sign in to comment.