Skip to content

Conversation

oindrila-b
Copy link
Contributor

@oindrila-b oindrila-b commented Oct 15, 2025

Description

Added reverse proxy using NGINX for Grafana, so that users can now access Grafana using host-address/grafana endpoint.

Testing

Tested Locally

Additional Notes

NA

Summary by CodeRabbit

  • New Features

    • Grafana is now accessible via the web app at /grafana through the built-in reverse proxy.
  • Improvements

    • Configured Grafana’s server root URL so links render correctly behind the proxy.
    • Added an automatic redirect from /grafana to /grafana/ for smoother navigation.
    • Excluded Grafana paths from static-asset handling to prevent conflicts.
    • Improved proxy routing and headers for Grafana to enhance reliability.
    • Updated Grafana port mapping to use port 3000.

Modified docker compose and nginx config to reverse proxy grafana
Modified docker compose and nginx config to reverse proxy grafana
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 15, 2025

Note

Other AI code review bot(s) detected

CodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review.

Walkthrough

Adds GF_SERVER_ROOT_URL to Grafana services in two docker-compose files, changes Grafana port mapping, and updates NGINX to add a Grafana upstream, exclude /grafana from static-file matching, redirect /grafana/grafana/, and proxy /grafana/ to the Grafana backend with standard proxy headers and websocket handling.

Changes

Cohort / File(s) Summary
Grafana env & port
deployment/portable/docker-compose.infrastructure.yml, deployment/portable/docker-compose.infrastructure-cpu.yml
Add environment GF_SERVER_ROOT_URL=%(protocol)s://%(domain)s:%(http_port)s/grafana to the grafana service; change grafana port mapping from 3002:3000 to 3000.
NGINX Grafana routing
deployment/portable/nginx.conf
Add upstream grafana_backend { server xyne-grafana:3000; keepalive 16; }; exclude /grafana/ from static asset regex; add location = /grafana 301 → /grafana/; add location /grafana/ to proxy_pass to grafana_backend with Host, X-Real-IP, X-Forwarded-* headers and Upgrade/Connection handling.

Sequence Diagram(s)

sequenceDiagram
    autonumber
    participant U as Browser
    participant N as NGINX
    participant G as Grafana (xyne-grafana:3000)

    rect rgba(235,245,255,0.6)
    Note over U,N: Requesting Grafana root
    U->>N: GET /grafana
    N-->>U: 301 /grafana/ (redirect)
    end

    U->>N: GET /grafana/
    alt Static asset? (excluded)
        N->>G: Proxy /grafana/... (Host, X-Real-IP, X-Forwarded-For, X-Forwarded-Proto)
        G-->>N: 200 OK
        N-->>U: 200 OK
    else WebSocket / Upgrade
        N->>G: Proxy with Upgrade/Connection headers
        G-->>N: Upgraded stream
        N-->>U: Stream
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Suggested reviewers

  • zereraz
  • kalpadhwaryu
  • junaid-shirur
  • devesh-juspay

Poem

I hop through configs, whiskers twitch,
A /grafana path gets fixed and stitched.
NGINX nudges dashboards to the stream,
Env set right — the panels gleam.
Hop, deploy, and crunch those metrics! 🥕📊

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The pull request title "Added reverse proxy using nginx for grafana" accurately describes the primary architectural change in this changeset. The modifications span three files but center on implementing an NGINX reverse proxy configuration that enables access to Grafana through a /grafana endpoint, which is the core objective stated in the PR description. The supporting changes to docker-compose files (updating ports and adding environment variables) are secondary to this main goal. The title is clear, concise, and specific enough to convey the essential change to someone reviewing the commit history.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/grafana_port_access

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 503e32f and 17921d2.

📒 Files selected for processing (1)
  • deployment/portable/nginx.conf (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • deployment/portable/nginx.conf

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @oindrila-b, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request implements a reverse proxy for Grafana using NGINX, allowing users to access the Grafana dashboard through a consistent and user-friendly URL (/grafana). This change streamlines the developer experience by integrating Grafana more seamlessly into the application's access patterns, ensuring proper routing and configuration for the monitoring tool.

Highlights

  • Grafana Access via Reverse Proxy: Grafana is now accessible through a reverse proxy via the host-address/grafana endpoint, improving accessibility and integration within the existing infrastructure.
  • Docker Compose Configuration: The GF_SERVER_ROOT_URL environment variable has been added to the Grafana service in both docker-compose.infrastructure-cpu.yml and docker-compose.infrastructure.yml to correctly configure Grafana's root URL for the reverse proxy setup.
  • NGINX Configuration Updates: The nginx.conf file has been updated to include a new upstream block for the Grafana backend, a redirect for /grafana to /grafana/, and a dedicated location block to proxy requests to Grafana. Additionally, static file caching rules were adjusted to exclude Grafana paths.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request adds an Nginx reverse proxy for Grafana, allowing access via the /grafana subpath. The changes in the docker-compose files correctly configure Grafana's root URL, and the nginx.conf is updated to handle the proxying. My review includes a few suggestions: a high-severity recommendation to remove the directly exposed Grafana port to enforce access through Nginx, and a couple of medium-severity improvements for the Nginx configuration regarding redirect status codes, formatting consistency, and file termination. Overall, the changes are well-structured to achieve the goal. Addressing the feedback will improve the robustness and consistency of the configuration.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
deployment/portable/docker-compose.infrastructure.yml (1)

229-248: Add grafana service dependency to nginx.

The nginx service should depend on the grafana service to ensure proper startup order. Without this dependency, nginx might start before Grafana is ready, causing initial connection failures.

Add the grafana dependency to the nginx service:

     depends_on:
       - livekit
+      - grafana
     volumes:
deployment/portable/docker-compose.infrastructure-cpu.yml (1)

227-246: Add grafana service dependency to nginx.

The nginx service should depend on the grafana service to ensure proper startup order and avoid initial connection failures.

Add the grafana dependency:

     depends_on:
       - livekit
+      - grafana
     volumes:
🧹 Nitpick comments (1)
deployment/portable/nginx.conf (1)

230-240: Add explicit timeout settings for Grafana queries.

While the proxy configuration correctly handles WebSocket upgrades and standard headers, consider adding explicit timeout settings for long-running Grafana queries and dashboard loads.

Add timeout configurations:

         location /grafana/ {
             proxy_pass http://grafana_backend/;
             proxy_http_version 1.1;
             proxy_set_header Host $host;
             proxy_set_header X-Real-IP $remote_addr;
             proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
             proxy_set_header X-Forwarded-Proto $scheme;
             proxy_set_header Upgrade $http_upgrade;
             proxy_set_header Connection $connection_upgrade;
+            proxy_read_timeout 300;
+            proxy_connect_timeout 30;
+            proxy_send_timeout 300;
         }
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 1cb30d8 and fc55afd.

📒 Files selected for processing (3)
  • deployment/portable/docker-compose.infrastructure-cpu.yml (1 hunks)
  • deployment/portable/docker-compose.infrastructure.yml (1 hunks)
  • deployment/portable/nginx.conf (3 hunks)
🔇 Additional comments (5)
deployment/portable/docker-compose.infrastructure.yml (1)

52-52: LGTM! Grafana root URL configuration is correct.

The GF_SERVER_ROOT_URL template format is appropriate for Grafana. The template variables %(protocol)s, %(domain)s, and %(http_port)s will be dynamically resolved by Grafana at runtime to construct the proper root URL.

deployment/portable/docker-compose.infrastructure-cpu.yml (1)

52-52: LGTM! Grafana root URL configuration is correct.

The GF_SERVER_ROOT_URL configuration is consistent with the GPU variant and properly formatted for Grafana's runtime template resolution.

deployment/portable/nginx.conf (3)

83-87: LGTM! Grafana upstream configuration is correct.

The upstream configuration properly references the Grafana container name and internal port, with appropriate keepalive settings.


210-223: LGTM! Static files regex correctly excludes Grafana paths.

The negative lookahead (?!grafana/) properly ensures that Grafana's static assets are not intercepted by this location block, allowing them to be handled by the Grafana proxy location instead.


225-228: LGTM! Trailing slash redirect is appropriate.

The 302 redirect from /grafana to /grafana/ ensures proper path handling and is the safer choice for deployments compared to a permanent 301 redirect.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

♻️ Duplicate comments (3)
deployment/portable/nginx.conf (3)

83-87: Remove trailing whitespace on line 85.

There appears to be trailing whitespace after 3000; on line 85. This was flagged in a previous review. Please remove it for consistency.


225-228: LGTM: Permanent redirect is correctly implemented.

The 301 (permanent) redirect is the appropriate choice for canonicalizing the URL by adding a trailing slash. This addresses the previous review feedback and will improve performance as browsers cache permanent redirects.


242-242: Ensure file ends with a newline.

As noted in a previous review, the file should end with a newline character to comply with POSIX standards and prevent issues with text processing tools.

🧹 Nitpick comments (1)
deployment/portable/nginx.conf (1)

230-230: Consider clarifying the location ordering comment.

The comment states "must come after static files to ensure proper handling," but nginx location matching follows precedence rules rather than file order. The /grafana/ prefix match will be evaluated before the ~* regex match for static files, regardless of their position in the config. If the comment refers to logical organization for readability, consider clarifying that.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between fc55afd and 503e32f.

📒 Files selected for processing (3)
  • deployment/portable/docker-compose.infrastructure-cpu.yml (1 hunks)
  • deployment/portable/docker-compose.infrastructure.yml (1 hunks)
  • deployment/portable/nginx.conf (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • deployment/portable/docker-compose.infrastructure-cpu.yml
  • deployment/portable/docker-compose.infrastructure.yml
🔇 Additional comments (1)
deployment/portable/nginx.conf (1)

210-211: Static file exclusion pattern is correct.

The negative lookahead (?!grafana/) correctly excludes Grafana paths from being cached by this location block, ensuring Grafana's static assets are handled by the dedicated Grafana location block.

@shivamashtikar shivamashtikar merged commit 066b844 into main Oct 16, 2025
3 of 4 checks passed
@shivamashtikar shivamashtikar deleted the fix/grafana_port_access branch October 16, 2025 10:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants