[93] fix: Connected Grafana Api to the response-time-interceptor
Referene Issue : #76
https://github.com/SamagraX-Stencil/stencil/assets/130863032/2e25a72f-9d16-4b1b-8885-5f75abd3196b
Summary by CodeRabbit
-
New Features
- Introduced configuration for Grafana API token and base URL.
- Added
axiosanduuidpackages as dependencies. - Included
ConfigModulefor environment configuration management. - Enhanced dashboard interaction with Grafana APIs.
-
Improvements
- Updated the method of setting the content type in the
metricsendpoint. - Refactored response time metrics collection to include error handling and additional metadata.
- Updated the method of setting the content type in the
-
Bug Fixes
- Corrected schematics collection reference in
nest-cli.json.
- Corrected schematics collection reference in
-
Tests
- Added unit tests for
FastifyFileInterceptorfocusing on file uploads and error scenarios.
- Added unit tests for
-
Documentation
- Updated example environment file with Grafana configuration variables.
[!IMPORTANT]
Review skipped
Auto reviews are disabled on base/target branches other than the default branch.
Please check the settings in the CodeRabbit UI or the
.coderabbit.yamlfile in this repository. To trigger a single review, invoke the@coderabbitai reviewcommand.You can disable this status message by setting the
reviews.review_statustofalsein the CodeRabbit configuration file.
Walkthrough
This release introduces important updates across multiple files, focusing on enhancing functionality and code maintainability. Key changes include improvements in Prometheus metrics handling, updates to the response-time tracking interceptor for better Grafana integration, and addition of new utility functions for generating Grafana dashboard panels. Minor formatting updates and new unit tests for file upload interceptors are also included, along with updated configuration management using NestJS ConfigModule and new dependencies in package.json.
Changes
| Files | Change Summary |
|---|---|
packages/.../prometheus.controller.ts |
Updated method to use response.header instead of response.headers for setting content type. |
packages/.../file-upload.interceptor.ts, file-upload.interceptor.spec.ts |
Minor formatting changes and new unit tests for FastifyFileInterceptor. |
packages/.../response-time.interceptor.ts, packages/.../utils.ts |
Enhanced Grafana integration, new utility functions for dashboard management, and updated error handling. |
sample/02-monitoring/env-example, nest-cli.json, package.json |
Added env-example, updated Grafana API token and URL configurations, dependency updates. |
sample/02-monitoring/src/app.controller.ts |
Added @UseInterceptors decorator to AppController class. |
sample/02-monitoring/src/app.module.ts |
Included ConfigModule and initialized it in imports array. |
sample/02-monitoring/src/main.ts |
Introduced ConfigService to fetch configuration for Grafana integration in ResponseTimeInterceptor. |
Sequence Diagram(s)
sequenceDiagram
participant Client
participant AppController
participant ResponseTimeInterceptor
participant GrafanaAPI
participant PrometheusController
Client->>AppController: Send request
AppController->>ResponseTimeInterceptor: Intercept request
ResponseTimeInterceptor->>GrafanaAPI: Fetch or update dashboard
GrafanaAPI-->>ResponseTimeInterceptor: Return dashboard data
ResponseTimeInterceptor->>AppController: Proceed with request
AppController->>PrometheusController: Fetch metrics
PrometheusController->>Client: Return metrics with content-type header
Poem
In code we trust, a change of light,
From headers to header, metrics right.
Grafana's dash, a smoother play,
Configured paths now guide the way.
Fastify and tests spring to life,
In harmony, beyond all strife.
CodeRabbit's cheer, in each commit tight!
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?
🪧 Tips
Chat
There are 3 ways to chat with CodeRabbit:
- Review comments: Directly reply to a review comment made by CodeRabbit. Example:
I pushed a fix in commit <commit_id>, please review it.Generate unit testing code for this file.Open a follow-up GitHub issue for this discussion.
- Files and specific lines of code (under the "Files changed" tab): Tag
@coderabbitaiin a new review comment at the desired location with your query. Examples:@coderabbitai generate unit testing code for this file.@coderabbitai modularize this function.
- PR comments: Tag
@coderabbitaiin a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:@coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.@coderabbitai read src/utils.ts and generate unit testing code.@coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.@coderabbitai help me debug CodeRabbit configuration file.
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.
CodeRabbit Commands (Invoked using PR comments)
@coderabbitai pauseto pause the reviews on a PR.@coderabbitai resumeto resume the paused reviews.@coderabbitai reviewto trigger an incremental review. This is useful when automatic reviews are disabled for the repository.@coderabbitai full reviewto do a full review from scratch and review all the files again.@coderabbitai summaryto regenerate the summary of the PR.@coderabbitai resolveresolve all the CodeRabbit review comments.@coderabbitai configurationto show the current CodeRabbit configuration for the repository.@coderabbitai helpto get help.
Other keywords and placeholders
- Add
@coderabbitai ignoreanywhere in the PR description to prevent this PR from being reviewed. - Add
@coderabbitai summaryto generate the high-level summary at a specific location in the PR description. - Add
@coderabbitaianywhere in the PR title to generate the title automatically.
CodeRabbit Configuration File (.coderabbit.yaml)
- You can programmatically configure CodeRabbit by adding a
.coderabbit.yamlfile to the root of your repository. - Please see the configuration documentation for more information.
- If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation:
# yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json
Documentation and Community
- Visit our Documentation for detailed information on how to use CodeRabbit.
- Join our Discord Community to get help, request features, and share feedback.
- Follow us on X/Twitter for updates and announcements.
⚠️ GitGuardian has uncovered 8 secrets following the scan of your pull request.
Please consider investigating the findings and remediating the incidents. Failure to do so may lead to compromising the associated services or software components.
Since your pull request originates from a forked repository, GitGuardian is not able to associate the secrets uncovered with secret incidents on your GitGuardian dashboard. Skipping this check run and merging your pull request will create secret incidents on your GitGuardian dashboard.
🔎 Detected hardcoded secrets in your pull request
| GitGuardian id | GitGuardian status | Secret | Commit | Filename | |
|---|---|---|---|---|---|
| - | - | Grafana Service Account Token | 3b0e08ef5989b9935af08163fcc5d399be4a6222 | sample/02-monitoring/src/response.interceptor.ts | View secret |
| - | - | Grafana Service Account Token | 3b0e08ef5989b9935af08163fcc5d399be4a6222 | sample/02-monitoring/src/response.interceptor.ts | View secret |
| - | - | Grafana Service Account Token | f4ec971bb28d56fc02558af01b9990a7c049dcbe | sample/02-monitoring/src/response.interceptor.ts | View secret |
| - | - | Grafana Service Account Token | f4ec971bb28d56fc02558af01b9990a7c049dcbe | sample/02-monitoring/src/response.interceptor.ts | View secret |
| - | - | Grafana Service Account Token | 125e67d0f07ee49c2b61093f7ec889f88be7a5be | sample/02-monitoring/src/response.interceptor.ts | View secret |
| - | - | Grafana Token | 9154a6d0bbcc8fca6194e3c5fc4e57570e00a17b | sample/02-monitoring/README.md | View secret |
| - | - | Grafana Token | 3fa0a9c0f72b36817976b9494d4352e880fc2634 | sample/02-monitoring/README.md | View secret |
| - | - | Grafana Token | 9154a6d0bbcc8fca6194e3c5fc4e57570e00a17b | sample/02-monitoring/README.md | View secret |
🛠 Guidelines to remediate hardcoded secrets
- Understand the implications of revoking this secret by investigating where it is used in your code.
- Replace and store your secrets safely. Learn here the best practices.
- Revoke and rotate these secrets.
- If possible, rewrite git history. Rewriting git history is not a trivial act. You might completely break other contributing developers' workflow and you risk accidentally deleting legitimate data.
To avoid such incidents in the future consider
- following these best practices for managing and storing secrets including API keys and other credentials
- install secret detection on pre-commit to catch secret before it leaves your machine and ease remediation.
🦉 GitGuardian detects secrets in your source code to help developers and security teams secure the modern development process. You are seeing this because you or someone else with access to this repository has authorized GitGuardian to scan your pull request.
https://github.com/SamagraX-Stencil/stencil/assets/130863032/00822ec9-4dda-4140-ae8d-bfad0f44592b
https://github.com/SamagraX-Stencil/stencil/assets/130863032/447584f9-a5d7-4b51-b77c-8eb8289f8d23
- [x] Global level inteceptor
- [x] Controller level interceptor (Metrics arent updating)
- [x] e2e tests
- [x] Readme Updated
I have commented one of the test which isn't passing, can you point what can be the issue here?
Parent issue: #93
@Savio629 CI is failing on this.
- Have we fixed the issue of each multiple dashboards? It should just be multiple panels in a single dashboard.
@Savio629 CI is failing on this Fixed one of the failing ci.
test / test-sample (01-monitoring) (pull_request) is failing because package is not updated of @samagra-x/stencil with this pr changes
GitGuardian Security Checks is failing as key was push in this pr
Have we fixed the issue of each multiple dashboards? It should just be multiple panels in a single dashboard.
Yes
@techsavvyash
By tomorrow, will test it properly and update you
updated test & the interceptor