grafana / oncall

Developer-friendly incident response with brilliant Slack integration
GNU Affero General Public License v3.0
3.32k stars 262 forks source link

Allow OSS Configuration to Serve from Subpath #4302

Open sternma opened 2 months ago

sternma commented 2 months ago

What would you like to see!

At the moment, it seems to be impossible to serve OnCall from a subpath in OSS deployments. Grafana Cloud serves OnCall from /oncall, but there's no option to specify this in any config file.

Applying a similar approach to grafana/grafana, allowing a serve_from_subpath configuration in the config and exposing this as a value in the Helm chart would be incredibly useful.

For context, the lack of this feature completely breaks hooking up a Grafana instance with an OnCall instance when trying to serve them from the same domain. Grafana wants to route to /integrations from the root of the domain, but we serve OnCall from /oncall, meaning Grafana would need to route to /oncall/integrations (like Grafana Cloud). Therefore, the only way to integrate Grafana and OnCall in this same-domain Enterprise setup is by serving OnCall behind a reverse proxy and integrating it with Grafana via the Webhook integration.

Product Area

Other

Anything else to add?

No response

github-actions[bot] commented 2 months ago

The current version of Grafana OnCall, at the time this issue was opened, is v1.4.4. If your issue pertains to an older version of Grafana OnCall, please be sure to list it in the PR description. Thank you :smile:!

mderynck commented 2 months ago

This should be configurable by setting the BASE_URL environment variable

sternma commented 1 month ago

Hi @mderynck -

If deploying via Helm, would this be env.BASE_URL or the top-level base_url value? I was not able to accomplish this using the top-level field.

ChristianCiach commented 4 weeks ago

@mderynck Unfortunately, this doesn't work. I deploy my oncall-engine with this env variable:

BASE_URL=https://oncall.mycompany.de/oncall

This is my Ingress:

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: grafana-oncall
  annotations:
    traefik.ingress.kubernetes.io/router.tls: "true"
    traefik.ingress.kubernetes.io/router.entrypoints: websecure
spec:
  rules:
  - host: oncall.mycompany.de
    http:
      paths:
      - pathType: Prefix
        path: "/oncall"
        backend:
          service:
            name: oncall-engine
            port:
              number: 8080
      - pathType: Prefix
        path: "/"
        backend:
          service:
            name: grafana
            port:
              number: 8080

When I request something from https://oncall.mycompany.de/oncall, it does hit the oncall-engine pod, but it then logs a 404:

2024-06-06 12:55:04 source=engine:uwsgi status=404 method=GET path=/oncall/ latency=0.001922 google_trace_id=- protocol=HTTP/1.1 resp_size=450 req_body_size=0
ChristianCiach commented 4 weeks ago

You can workaround this via path rewriting at ingress level:

Oncall configuration:

BASE_URL=https://oncall.mycompany.de/oncall

Ingress with path-rewriting (using Traefik middleware, but works similarly with Nginx regex-replace):

apiVersion: traefik.io/v1alpha1
kind: Middleware
metadata:
  name: oncall-stripprefix
  namespace: oncall
spec:
  stripPrefix:
    prefixes:
      - /oncall
---
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  name: grafana-oncall
  namespace: oncall
  annotations:
    traefik.ingress.kubernetes.io/router.tls: "true"
    traefik.ingress.kubernetes.io/router.entrypoints: websecure
    traefik.ingress.kubernetes.io/router.middlewares: oncall-oncall-stripprefix@kubernetescrd
spec:
  rules:
  - host: oncall.mycompany.de
    http:
      paths:
      - pathType: Prefix
        path: "/oncall"
        backend:
          service:
            name: oncall-engine
            port:
              number: 8080
      - pathType: Prefix
        path: "/"
        backend:
          service:
            name: grafana
            port:
              number: 8080

Everything seems to work fine with this. I could even connect the Oncall mobile app to this instance by scanning the QR code. Integrations also seem to work fine, including their advertised URLs in Grafana UI.

Seeing that Grafana-Cloud serves the Oncall-API on /oncall, too, I guess they are doing something very similar.

mderynck commented 4 weeks ago

BASE_URL controls what the engine says the URL is when populating various responses. It does not change actual paths or routing, oncall engine is using uwsgi to serve the django app at /. As @ChristianCiach has shown path prefix is accomplished through a separate application proxy.