stencil icon indicating copy to clipboard operation
stencil copied to clipboard

[93] fix: Connected Grafana Api to the response-time-interceptor

Open DarrenDsouza7273 opened this issue 1 year ago • 11 comments

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 axios and uuid packages as dependencies.
    • Included ConfigModule for environment configuration management.
    • Enhanced dashboard interaction with Grafana APIs.
  • Improvements

    • Updated the method of setting the content type in the metrics endpoint.
    • Refactored response time metrics collection to include error handling and additional metadata.
  • Bug Fixes

    • Corrected schematics collection reference in nest-cli.json.
  • Tests

    • Added unit tests for FastifyFileInterceptor focusing on file uploads and error scenarios.
  • Documentation

    • Updated example environment file with Grafana configuration variables.

DarrenDsouza7273 avatar Jul 04 '24 09:07 DarrenDsouza7273

[!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.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in 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?

❤️ Share
🪧 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 @coderabbitai in 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 @coderabbitai in 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 pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file 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.

coderabbitai[bot] avatar Jul 04 '24 09:07 coderabbitai[bot]

⚠️ 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
  1. Understand the implications of revoking this secret by investigating where it is used in your code.
  2. Replace and store your secrets safely. Learn here the best practices.
  3. Revoke and rotate these secrets.
  4. 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


🦉 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.

gitguardian[bot] avatar Jul 04 '24 09:07 gitguardian[bot]

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

DarrenDsouza7273 avatar Jul 04 '24 18:07 DarrenDsouza7273

  • [x] Global level inteceptor
  • [x] Controller level interceptor (Metrics arent updating)
  • [x] e2e tests
  • [x] Readme Updated

DarrenDsouza7273 avatar Jul 06 '24 11:07 DarrenDsouza7273

image

I have commented one of the test which isn't passing, can you point what can be the issue here?

Savio629 avatar Jul 27 '24 12:07 Savio629

Parent issue: #93

Savio629 avatar Aug 05 '24 14:08 Savio629

@Savio629 CI is failing on this.

techsavvyash avatar Aug 09 '24 19:08 techsavvyash

  1. Have we fixed the issue of each multiple dashboards? It should just be multiple panels in a single dashboard.

techsavvyash avatar Aug 09 '24 19:08 techsavvyash

@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

Savio629 avatar Aug 10 '24 14:08 Savio629

image

By tomorrow, will test it properly and update you

Savio629 avatar Sep 22 '24 19:09 Savio629

updated test & the interceptor image

Savio629 avatar Sep 24 '24 15:09 Savio629