Skip to content

Commit 43539bb

Browse files
committed
fix: Grafana monitoring page iframe embedding and dynamic cluster configuration
This commit resolves multiple issues with Grafana integration in the dashboard: 1. **Fixed 405 Method Not Allowed on Grafana login** - Updated router.go to properly detect Grafana login requests - Added Content-Type header checking for POST login requests - Grafana uses application/json while ChatUI uses form data 2. **Fixed localhost redirect loop after Grafana login** - Added comprehensive Grafana server configuration - Set GF_SERVER_ROOT_URL to Grafana's own route - Added GF_SERVER_PROTOCOL=http to prevent HTTPS redirect loop - Enabled anonymous access to avoid login redirects in iframe 3. **Fixed frontend iframe redirect loop** - Removed two-step load process causing infinite redirects - Load dashboard directly via goto endpoint - Eliminated automatic redirect logic from useEffect 4. **Made Grafana configuration cluster-agnostic** - Changed deployment.yaml to use DYNAMIC_GRAFANA_ROUTE_URL placeholder - Updated deploy-to-openshift.sh to dynamically substitute route URL - Configuration now works across different OpenShift clusters Changes: - dashboard/backend/router/router.go: Enhanced login routing logic - dashboard/frontend/src/pages/MonitoringPage.tsx: Direct dashboard loading - deploy/openshift/observability/grafana/deployment.yaml: Dynamic URL configuration - deploy/openshift/deploy-to-openshift.sh: Added dynamic route URL substitution Signed-off-by: szedan <szedan@redhat.com>
1 parent bc80d0d commit 43539bb

File tree

3 files changed

+56
-34
lines changed

3 files changed

+56
-34
lines changed

dashboard/frontend/src/pages/MonitoringPage.tsx

Lines changed: 6 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -31,38 +31,15 @@ const MonitoringPage: React.FC = () => {
3131
return () => observer.disconnect()
3232
}, [theme])
3333

34-
// Build initial Grafana URL - load the root path first
35-
const buildInitialGrafanaUrl = () => {
36-
// Start with Grafana root path
37-
const url = `/embedded/grafana/?orgId=1&theme=${theme}`
38-
console.log('Initial Grafana URL:', url)
39-
return url
40-
}
41-
42-
// Build dashboard URL using goto endpoint - this is what Grafana uses internally
43-
const buildDashboardUrl = () => {
44-
// Use Grafana's goto endpoint to navigate by UID
45-
// This mimics the internal navigation when clicking Home
34+
// Build Grafana dashboard URL directly
35+
const buildGrafanaUrl = () => {
36+
// Load the dashboard directly using the goto endpoint
37+
// This is the cleanest approach and avoids redirect loops
4638
const url = `/embedded/grafana/goto/llm-router-metrics?orgId=1&theme=${theme}&refresh=30s`
47-
console.log('Dashboard goto URL:', url)
39+
console.log('Grafana URL:', url)
4840
return url
4941
}
5042

51-
// Add effect to handle automatic redirect to dashboard
52-
useEffect(() => {
53-
// After initial page load, wait a bit then redirect to dashboard using goto
54-
const timer = setTimeout(() => {
55-
if (iframeRef.current) {
56-
console.log('Redirecting to dashboard using goto...')
57-
// Use goto endpoint to navigate to dashboard (mimics clicking Home)
58-
iframeRef.current.src = buildDashboardUrl()
59-
}
60-
setLoading(false)
61-
}, 100) // Wait 0.1 seconds after initial load
62-
63-
return () => clearTimeout(timer)
64-
}, [theme])
65-
6643

6744

6845
const handleIframeLoad = () => {
@@ -95,7 +72,7 @@ const MonitoringPage: React.FC = () => {
9572
<iframe
9673
ref={iframeRef}
9774
key={`grafana-${theme}`}
98-
src={buildInitialGrafanaUrl()}
75+
src={buildGrafanaUrl()}
9976
className={styles.iframe}
10077
title="Grafana Dashboard"
10178
allowFullScreen

deploy/openshift/deploy-to-openshift.sh

Lines changed: 44 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -336,10 +336,51 @@ EOF
336336
oc apply -f "$SCRIPT_DIR/openwebui/route.yaml" -n "$NAMESPACE"
337337
success "OpenWebUI deployed"
338338

339-
# Deploy Grafana
339+
# Deploy Grafana with dynamic route URL
340340
log "Deploying Grafana..."
341-
oc apply -f "$SCRIPT_DIR/observability/grafana/" -n "$NAMESPACE"
342-
success "Grafana deployed"
341+
342+
# First apply Grafana resources to create the route
343+
oc apply -f "$SCRIPT_DIR/observability/grafana/pvc.yaml" -n "$NAMESPACE" 2>/dev/null || true
344+
oc apply -f "$SCRIPT_DIR/observability/grafana/service.yaml" -n "$NAMESPACE" 2>/dev/null || true
345+
oc apply -f "$SCRIPT_DIR/observability/grafana/route.yaml" -n "$NAMESPACE" 2>/dev/null || true
346+
oc apply -f "$SCRIPT_DIR/observability/grafana/configmaps.yaml" -n "$NAMESPACE" 2>/dev/null || true
347+
348+
# Wait for route to be created and get its URL
349+
log "Waiting for Grafana route to be created..."
350+
for i in {1..30}; do
351+
GRAFANA_ROUTE_URL=$(oc get route grafana -n "$NAMESPACE" -o jsonpath='{.spec.host}' 2>/dev/null || echo "")
352+
353+
if [[ -n "$GRAFANA_ROUTE_URL" ]]; then
354+
GRAFANA_ROUTE_URL="https://$GRAFANA_ROUTE_URL"
355+
success "Grafana route URL: $GRAFANA_ROUTE_URL"
356+
break
357+
fi
358+
359+
if [[ $i -eq 30 ]]; then
360+
error "Timeout waiting for Grafana route"
361+
exit 1
362+
fi
363+
364+
sleep 2
365+
done
366+
367+
# Generate Grafana deployment with dynamic route URL
368+
log "Generating Grafana deployment with dynamic route URL..."
369+
TEMP_GRAFANA_DEPLOYMENT="/tmp/grafana-deployment-dynamic.yaml"
370+
sed "s|DYNAMIC_GRAFANA_ROUTE_URL|$GRAFANA_ROUTE_URL|g" \
371+
"$SCRIPT_DIR/observability/grafana/deployment.yaml" > "$TEMP_GRAFANA_DEPLOYMENT"
372+
373+
# Verify the URL was substituted
374+
if ! grep -q "$GRAFANA_ROUTE_URL" "$TEMP_GRAFANA_DEPLOYMENT"; then
375+
error "Grafana route URL substitution failed!"
376+
exit 1
377+
fi
378+
379+
# Apply Grafana deployment with dynamic URL
380+
oc apply -f "$TEMP_GRAFANA_DEPLOYMENT" -n "$NAMESPACE"
381+
rm -f "$TEMP_GRAFANA_DEPLOYMENT"
382+
383+
success "Grafana deployed with dynamic route URL: $GRAFANA_ROUTE_URL"
343384

344385
# Deploy Prometheus
345386
log "Deploying Prometheus..."

deploy/openshift/observability/grafana/deployment.yaml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,15 @@ spec:
5151
- name: GF_SERVER_SERVE_FROM_SUB_PATH
5252
value: "true"
5353
- name: GF_SERVER_ROOT_URL
54-
value: "%(protocol)s://%(domain)s/embedded/grafana"
54+
value: "DYNAMIC_GRAFANA_ROUTE_URL"
55+
- name: GF_SERVER_PROTOCOL
56+
value: "http"
5557
- name: GF_SECURITY_ALLOW_EMBEDDING
5658
value: "true"
5759
- name: GF_AUTH_ANONYMOUS_ENABLED
58-
value: "false"
60+
value: "true"
61+
- name: GF_AUTH_ANONYMOUS_ORG_ROLE
62+
value: "Viewer"
5963
volumeMounts:
6064
- name: storage
6165
mountPath: /var/lib/grafana

0 commit comments

Comments
 (0)