From 95554074d837b1233d51e968814528b7dfbcc0b7 Mon Sep 17 00:00:00 2001 From: Julius Volz Date: Mon, 4 Nov 2019 09:17:50 +0100 Subject: [PATCH] React UI: Support custom path prefixes (#6264) * React UI: Support custom path prefixes The challenge was that the path prefix can be set dynamically as a flag on Prometheus, but the React app bundle is statically compiled in to expect a given path prefix. By adding a placeholder value to the React app's index.html and replacing it in Prometheus with the right path prefix during serving, this injects Prometheus's path prefix into the React app via a global const. Threading the path prefix into the different React components could have been done with React's Contexts (https://reactjs.org/docs/context.html), but I found the consumer side of context values to be a bit cumbersome (wrapping entire components in context consumers), so I ended up preferring direct threading of the path prefix values to components that needed them. Also, using contexts in tests is more verbose than just passing in path prefix values directly. Fixes https://github.com/prometheus/prometheus/issues/6163 Signed-off-by: Julius Volz * Review feedback Signed-off-by: Julius Volz --- web/ui/react-app/public/index.html | 8 + web/ui/react-app/src/App.test.tsx | 10 +- web/ui/react-app/src/App.tsx | 47 +- web/ui/react-app/src/Navbar.tsx | 25 +- web/ui/react-app/src/Panel.tsx | 9 +- web/ui/react-app/src/PathPrefixProps.ts | 5 + web/ui/react-app/src/index.tsx | 14 +- web/ui/react-app/src/pages/Alerts.tsx | 3 +- web/ui/react-app/src/pages/Config.tsx | 5 +- web/ui/react-app/src/pages/Flags.test.tsx | 8 +- web/ui/react-app/src/pages/Flags.tsx | 5 +- web/ui/react-app/src/pages/PanelList.tsx | 12 +- web/ui/react-app/src/pages/Rules.tsx | 3 +- web/ui/react-app/src/pages/Services.tsx | 3 +- web/ui/react-app/src/pages/Status.test.tsx | 8 +- web/ui/react-app/src/pages/Status.tsx | 30 +- web/ui/react-app/src/pages/Targets.tsx | 3 +- .../pages/__snapshots__/Status.test.tsx.snap | 834 +++++++++--------- web/web.go | 31 +- 19 files changed, 562 insertions(+), 501 deletions(-) create mode 100644 web/ui/react-app/src/PathPrefixProps.ts diff --git a/web/ui/react-app/public/index.html b/web/ui/react-app/public/index.html index 022e544cc..2e118e50d 100755 --- a/web/ui/react-app/public/index.html +++ b/web/ui/react-app/public/index.html @@ -8,6 +8,14 @@ content="width=device-width, initial-scale=1, shrink-to-fit=no" /> + + + +