Skip to content

Commit

Permalink
Merge branch 'dev' of https://github.com/Savio629/stencil into check-ip
Browse files Browse the repository at this point in the history
  • Loading branch information
Savio629 committed Sep 3, 2024
2 parents 5850424 + 2fc1105 commit a4cafe9
Show file tree
Hide file tree
Showing 322 changed files with 4,084 additions and 9,165 deletions.
16 changes: 16 additions & 0 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
## Checklist
Make sure you have
- [ ] Added relevant `@nestjs/swagger` decorators wherever required
- [ ] Added test cases (unit and integration) wherever required

## Description
*Describe the aim/objective of this PR*

## Steps to test
*Add steps to run and test teh desired changes*

## References
*Add relevant links and screenshots outlining the working status of this PR*

## Demo
*If relevant to your change, attach a screen recording showcasing that the change is working and giving desired results.*
59 changes: 59 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
name: "test"

on:
pull_request:
branches:
- main
- dev

push:
branches:
- '*'

jobs:
test-package:
runs-on: ubuntu-latest

steps:
- name: Checkout Repository
uses: actions/checkout@v4.1.7

- name: Use Node.js
uses: actions/setup-node@v4

- name: Install Dependencies for packages/common
run: yarn install --frozen-lockfile
working-directory: packages/common

- name: Unit tests for packages/common
run: yarn run test:cov
working-directory: packages/common/test/

test-sample:
runs-on: ubuntu-latest
strategy:
matrix:
dir:
- '01-monitoring'
# - '02-response-formatting'
- '03-temporal-package'
- '04-file-upload'

steps:
- name: Checkout Repository
uses: actions/checkout@v4

- name: Use Node.js
uses: actions/setup-node@v4

- name: Install Dependencies for ${{ matrix.dir }}
run: yarn install
working-directory: sample/${{ matrix.dir }}

- name: Run Unit Tests
run: yarn run test:cov
working-directory: sample/${{ matrix.dir }}

- name: Run E2E Tests
run: yarn run test:e2e
working-directory: sample/${{ matrix.dir }}
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -128,3 +128,6 @@ dist
.yarn/build-state.yml
.yarn/install-state.gz
.pnp.*

data
dist
58 changes: 58 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# Contributing Guide
* [Ways to Contribute](#ways-to-contribute)
* [Find an Issue](#find-an-issue)
* [Pull Request Lifecycle](#pull-request-lifecycle)
* [Development Environment Setup](#development-environment-setup)


## Repository Structure
```
.
├── docker-compose/
├── docs/
├── packages/
├── sample/
├── CONTRIBUTING.md
├── LICENSE
├── README.md
├── package-lock.json
├── package.json
└── yarn.lock
```
- `packages` directory is where the main code resides, it is where all the custom components published and provided by `@samagra-x/stencil` package can be found. All the featuers that you code will be implemented here.
- `sample` directory contains reference applications showcasing individual functionalities and how they can setup or migrated in your nest application via stencil.
- `docker-compose` directory contains the commonly used docker-compose setups which we find handy.
- `docs` this folder contains the documentation for the framework. This is a docusaurus app which can be started for easy reference.


## Ways to Contribute

- As a first time contributor, navigating through the project, it can be quite daunting for you. Please make sure to go through the [repository structure](#repository-structure) to understand the project a bit better, if you want to understand the project better.

- Open a issue ticket for any gap in documentation or bug or feature requests that you have, opening up issue tickets is always a good way to contribute.

- You can help review open PRs for best backend and devops realted code practices and help the contributors out.

- Lastly and the most obvious one feel free to pick up open issue tickets and raise a PR for it resolving the bug, feature or documentation request.

## Community Issue Assignment Policy

Ideally all the tickets are open for the open source and C4GT Community to contribute to, but the assignment of a issue comes only after the contributor has raised a draft PR implementing the partial functionality required by the issue ticket.

## Guidelines

- Please don't spam the comments on an issue tickets with assignment requests, keep the comment sections clean and only ask questions/clarifications regarding the issue ticket, the assignment policy has been clearly stated in the [community-issue-assignment-policy](#community-issue-assignment-policy) section.

- Make sure to populate all the relevant and required fields of the PR template while raising the PR.


## Resources

In case you're unfamiliar with the technology being used for the project and how to understand the project better this section will act as a repository to provide some base material around them to help you get started

* [Prometheus](https://youtube.com/playlist?list=PLy7NrYWoggjxCF3av5JKwyG7FFF9eLeL4&si=3st6TLqgku1xrP_p)
* [Monitor on Ubuntu Server](https://www.youtube.com/watch?v=94JMdueq2SA)
* [Monitor on Windows](https://www.youtube.com/watch?v=jatcPHvChfI&t=763s)
* [Prometheus and Grafana Tutorial](https://www.youtube.com/watch?v=9TJx7QTrTyo&t=2s)
* [More about Prometheus](https://prometheus.io/docs/prometheus/latest/getting_started/)
* [More about Grafana](https://grafana.com/docs/grafana/latest/)
4 changes: 4 additions & 0 deletions docs/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,7 @@ yarn-debug.log*
yarn-error.log*

static/**/node_modules/


dist
data
2 changes: 1 addition & 1 deletion docs/docs/cli/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ title: Setup
install the package

```
npm install -g @soorajk1/stencil-cli
npm install -g @samagra-x/stencil-cli
```

## USAGE
Expand Down
6 changes: 4 additions & 2 deletions docs/docs/cli/introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,16 @@ title: Introduction

While developing this cli, many custom schematics were created to assist the cli in file generation.

The following new commands are available to the user if they wish to expedite a manual setup of their server
In this CLI tool, several new commands have been added to expedite the manual setup of a server environment. Let's delve deeper into each of these commands and understand how they can benefit users:

1. `service-prisma` : Creates a new `prisma.service.ts` and adds it as a provider to `app.module.ts`
2. `prisma` : Adds a sample `User` model to the `schema.prisma` file
3. `service-user` : Adds the necessary imports for `@techsavvyash/user-service` in `app.module.ts`
3. `service-user` : Adds the necessary imports for `@samagra-x/user-service` in `app.module.ts`
4. `fixtures` : Generate the docker related files along with the shell sciripts needed to run the `pre-commit` file in husky
5. `husky` : Creates the `pre-commit` file in the `.husky` folder
6. `github` : Creates a new `.github` folder and the `ISSUE_TEMPLATE` and `Workflow` subdirectory in it.
7. `devcontainer` : Generates the `devcontainer.json` in the .devcontainer directory.

Overall, these commands enhance the usability of your CLI tool by automating repetitive and error-prone tasks, enabling developers to set up their server environments quickly and efficiently. By leveraging these custom schematics, developers can focus more on writing code and less on manual setup, ultimately improving productivity and code quality which is the prime goal for this setup.

</p>
42 changes: 29 additions & 13 deletions docs/docs/monitoring/nestjs-monitor.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,21 +9,37 @@ title: NestJS-Monitor

## Introduction

`stencil` comes with out of the box support for creating `grafana dashboards` automatically using custom made `NestJS Interceptors` which generate the dashboard JSONs automatically.
`stencil` offers seamless integration with NestJS to automate the creation of `Grafana dashboards`. By leveraging custom NestJS Interceptors, the platform can generate dashboard JSONs automatically, ensuring real-time monitoring and visualization of application performance metrics.

## Features
1. Automatic Grafana Panel Creation
stencil simplifies the process of creating Grafana panels. Each time a new instance of the ResponseTimeInterceptor is added to a NestJS application, stencil generates corresponding dashboard panels automatically. This feature eliminates the manual effort involved in setting up performance dashboards, allowing developers to focus on their core application logic.

1. Automatic creation of `grafana` panels.
2. Automatic updation of panel JSONs upon addition of new instances of `ResponseTimeInterceptor` in the NestJS app.
3. Each instance of `ResponseTimeInterceptor` corresponds to a new `row` in the response_times `dashboard`.
4. Each row has the following 5 panels.
- **Heatmap response times:** This is a heatmap of all the response times for a particular instance of the `ResponseTimeInterceptor`.
- **Guage for number of requests**: This gauage tells the number of requests that have arrived at each endpoint being captured by a particular instance of `ResponseTimeInterceptor`.
- **Average response time graph**: This graph gives out information about the average response time for the requests coming through the interceptor.
- **Total number of requests graph**: This graph tells the total number of requests being received at a particular point of time.
- **Number of requests by status codes graph**: This graph gives out information about the number of requests grouped by the response HTTP status codes.
2. Dynamic Panel Updates
Whenever a new ResponseTimeInterceptor instance is introduced, stencil dynamically updates the panel JSONs. This ensures that the dashboards always reflect the latest performance metrics and application changes. Each interceptor instance adds a new row to the response_times dashboard, providing granular insights into different parts of the application.

3. Detailed Performance Panels
Each row in the dashboard contains the following five panels:

- **Heatmap Response Times:** This panel visualizes the distribution of response times for requests captured by a particular ResponseTimeInterceptor instance. It provides a clear overview of performance patterns and helps identify outliers. The heatmap allows for quick identification of latency issues, and the color intensity indicates the frequency of specific response times. Additionally, it can highlight periods of high and low activity, aiding in performance tuning and resource allocation.

- **Gauge for Number of Requests:** This gauge displays the total number of requests received by each endpoint monitored by the interceptor. It offers a quick snapshot of traffic volume and endpoint activity. The gauge can indicate sudden spikes in traffic, helping in identifying potential DDoS attacks. Furthermore, it provides real-time feedback on the effectiveness of scaling policies. By monitoring the gauge, you can ensure that your endpoints handle the expected load efficiently.

- **Average Response Time Graph:** This graph tracks the average response times for requests processed by the interceptor. It helps in monitoring the overall performance and responsiveness of the application over time. Analyzing the trends in this graph can help pinpoint bottlenecks and inefficiencies in the application. The graph can also be used to measure the impact of performance optimizations. Additionally, it provides insights into how different endpoints perform under varying loads.

- **Total Number of Requests Graph:** This panel provides a timeline view of the total number of requests received at different points in time. It is useful for identifying traffic trends and peak usage periods. This information can be crucial for capacity planning and scaling decisions. The graph can also highlight seasonal or event-driven traffic patterns. Moreover, it helps in understanding user behavior and the application's usage patterns.

- **Number of Requests by Status Codes Graph:** This graph categorizes the requests based on their HTTP status codes. It offers insights into the success and failure rates of requests, helping in diagnosing issues and ensuring robust application performance. The graph can help in quickly identifying and addressing frequent errors or anomalies. It also provides a breakdown of client-side versus server-side errors. Additionally, the graph can be used to track the effectiveness of fixes and improvements over time.

To read more about how the interceptor can be used, refer [here](https://github.com/techsavvyash/nestjs-monitor#usage)
To learn more about NestJS interceptor you can refer official NestJS documentation [here](https://docs.nestjs.com/interceptors)
A small demo showcasing these `interceptors` in action can be found [here](https://drive.google.com/file/d/1KSxZdQzUU8SJmpmLHPpUSrRpnsL4aQY2/view?usp=sharing)
</p>

For additional information on NestJS interceptors, refer to the official NestJS documentation [here](https://docs.nestjs.com/interceptors)

## Demo

A small demo showcasing these `interceptors` in action can be found [here](https://drive.google.com/file/d/1KSxZdQzUU8SJmpmLHPpUSrRpnsL4aQY2/view?usp=sharing). This demonstration provides a practical example of how the interceptors work and the kind of insights they can offer.

By integrating stencil with your NestJS application, you can achieve comprehensive, automated performance monitoring with minimal effort, ensuring your application runs smoothly and efficiently.

</p>

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
14 changes: 14 additions & 0 deletions packages/common/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
testMatch: ['**/test/**/*.spec.ts'],
moduleFileExtensions: ['ts', 'tsx', 'js', 'json'],
transform: {
'^.+\\.(t|j)s$': [
'ts-jest',
{
tsconfig: 'tsconfig.json',
},
],
},
};
47 changes: 17 additions & 30 deletions packages/common/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"dependencies": {
"@nestjs/cache-manager": "^2.1.0",
"@nestjs/common": "^10.0.0",
"@nestjs/config": "^3.2.2",
"@nestjs/core": "^10.0.0",
"@nestjs/platform-express": "^10.0.0",
"@nestjs/platform-fastify": "^10.3.0",
Expand All @@ -44,24 +45,26 @@
"axios": "^1.7.4",
"cache-manager": "^5.2.4",
"cache-manager-redis-store": "2",
"fastify": "^4.25.2",
"fastify": "^4.27.0",
"fastify-multer": "^2.0.3",
"fastify-multipart": "^5.4.0",
"geolib": "^3.3.4",
"minio": "^7.1.3",
"multer": "^1.4.5-lts.1",
"nestjs-temporal": "^2.0.1",
"prom-client": "^15.1.0",
"prom-client": "^15.1.2",
"redis": "^4.6.10",
"reflect-metadata": "^0.1.13",
"rxjs": "^7.8.1"
"rxjs": "^7.8.1",
"urlencode": "^2.0.0"
},
"devDependencies": {
"@nestjs/cli": "^10.0.0",
"@nestjs/schematics": "^10.0.0",
"@nestjs/testing": "^10.0.0",
"@types/express": "^4.17.17",
"@types/jest": "^29.5.2",
"@types/jest": "^29.5.12",
"@types/mocha": "^10.0.6",
"@types/node": "^20.3.1",
"@types/supertest": "^2.0.12",
"@typescript-eslint/eslint-plugin": "^6.0.0",
Expand All @@ -70,42 +73,26 @@
"eslint-config-prettier": "^9.0.0",
"eslint-plugin-prettier": "^5.1.3",
"husky": "^7.0.2",
"jest": "^29.5.0",
"jest": "^29.7.0",
"mocha": "^10.4.0",
"prettier": "^3.0.0",
"source-map-support": "^0.5.21",
"supertest": "^6.3.3",
"ts-jest": "^29.1.0",
"ts-jest": "^29.1.3",
"ts-loader": "^9.4.3",
"ts-node": "^10.9.1",
"tsconfig-paths": "^4.2.0",
"typescript": "^5.3.3"
},
"jest": {
"moduleFileExtensions": [
"js",
"json",
"ts"
],
"rootDir": "src",
"testRegex": ".*\\.spec\\.ts$",
"transform": {
"^.+\\.(t|j)s$": "ts-jest"
},
"collectCoverageFrom": [
"**/*.(t|j)s"
],
"coverageDirectory": "../coverage",
"testEnvironment": "node"
},
"husky": {
"hooks": {
"pre-commit": "lint-staged"
}
"hooks": {
"pre-commit": "lint-staged"
}
},
"lint-staged": {
"*.{js,jsx,ts,tsx,json,css,scss,md}": [
"eslint --fix",
"prettier --write"
]
"*.{js,jsx,ts,tsx,json,css,scss,md}": [
"eslint --fix",
"prettier --write"
]
}
}
Loading

0 comments on commit a4cafe9

Please sign in to comment.