1
0
mirror of https://github.com/netdata/netdata.git synced 2021-06-06 23:03:21 +03:00

Use a prefix for the old dashboard. (#8752)

* Use a prefix for the old dashboard.

This switches the code for handling of the new React dashboard to use a
prefix for accessing the old dashboard instead of relying on a switching
script to handle selecting the desired dashboard implementation.

It also adds proper support to the packaging code to bundle the React
dashboard.

* Fixed typos in web/gui/Makefile.am.

* Tidy up prefixed dashboard.

This is based on discussion with cakrit about how to handle this more
sanely.

* use /old suffix for streamed nodes links in dropdown menu

* fix fetching dynamic vendor files with /old suffix

Co-authored-by: Jacek Kolasa <jacek.kolasa@gmail.com>
This commit is contained in:
Austin S. Hemmelgarn
2020-04-24 07:11:30 -04:00
committed by GitHub
parent 8eb9278aa8
commit d34f3ce1fc
9 changed files with 1360 additions and 97 deletions

View File

@@ -72,6 +72,7 @@ override_dh_install: debian/netdata.postinst
# Move files that local user shouldn't be editing to /usr/share/netdata
#
packaging/bundle-dashboard.sh . ${TOP}/var/lib/netdata/www
mkdir -p "$(TOP)/usr/share/netdata/www"
for D in $$(find "$(TOP)/var/lib/netdata/www/" -maxdepth 1 -type d -printf '%f '); do \
echo Relocating $$D; \

View File

@@ -1022,22 +1022,15 @@ fi
# -----------------------------------------------------------------------------
copy_react_dashboard() {
run rm -rf "${NETDATA_WEB_DIR}-react"
run rm -rf "${NETDATA_WEB_DIR}-classic"
run cp -a "${1}/" "${NETDATA_WEB_DIR}-react"
run cp -a "${NETDATA_WEB_DIR}/dashboard_info.js" "${NETDATA_WEB_DIR}-react"
run cp -a "${NETDATA_WEB_DIR}/dashboard.slate.css" "${NETDATA_WEB_DIR}-react"
run cp -a "${NETDATA_WEB_DIR}/dashboard.css" "${NETDATA_WEB_DIR}-react"
run cp -a "${NETDATA_WEB_DIR}/main.css" "${NETDATA_WEB_DIR}-react"
run echo "$(cd ${NETDATA_WEB_DIR}-react && find . -type f | sed -e 's/\.\///')" > "${NETDATA_WEB_DIR}-react/.files"
run cp -a "${NETDATA_WEB_DIR}" "${NETDATA_WEB_DIR}-classic"
run echo "$(find web/gui -type f | sed -e "s/web\/gui\///")" > "${NETDATA_WEB_DIR}-classic/.files"
run chown -R "${NETDATA_WEB_USER}:${NETDATA_WEB_GROUP}" "${NETDATA_WEB_DIR}-react"
run cp -a $(find ${1} -mindepth 1 -maxdepth 1) "${NETDATA_WEB_DIR}"
run chown -R "${NETDATA_WEB_USER}:${NETDATA_WEB_GROUP}" "${NETDATA_WEB_DIR}"
}
install_react_dashboard() {
progress "Fetching and installing dashboard"
clean_existing_dashboard
DASHBOARD_PACKAGE_VERSION="$(cat packaging/dashboard.version)"
tmp="$(mktemp -d -t netdata-dashboard-XXXXXX)"
@@ -1053,13 +1046,7 @@ install_react_dashboard() {
copy_react_dashboard "${tmp}/build" && \
rm -rf "${tmp}"
then
if run "${NETDATA_PREFIX}/usr/libexec/netdata/netdata-switch-dashboard.sh" "${NETDATA_SELECTED_DASHBOARD:-react}" ; then
run_ok "React dashboard installed."
else
run_failed "Failed to switch to React dashboard."
run rm -rf "${NETDATA_WEB_DIR}"
run cp -a "${NETDATA_WEB_DIR}-classic" "${NETDATA_WEB_DIR}"
fi
run_ok "React dashboard installed."
else
run_failed "Failed to install React dashboard. The install process will continue, but you will not be able to use the new dashboard."
fi
@@ -1620,7 +1607,6 @@ REINSTALL_OPTIONS="${REINSTALL_OPTIONS}"
RELEASE_CHANNEL="${RELEASE_CHANNEL}"
IS_NETDATA_STATIC_BINARY="${IS_NETDATA_STATIC_BINARY}"
NETDATA_LIB_DIR="${NETDATA_LIB_DIR}"
NETDATA_SELECTED_DASHBOARD="${NETDATA_SELECTED_DASHBOARD:-react}"
EOF
run chmod 0644 "${NETDATA_USER_CONFIG_DIR}/.environment"

View File

@@ -407,6 +407,8 @@ install_go() {
install_go
install -m 0640 -p go.d.plugin "${RPM_BUILD_ROOT}%{_libexecdir}/%{name}/plugins.d/go.d.plugin"
${RPM_BUILD_DIR}/%{name}-%{version}/packaging/bundle-dashboard.sh ${RPM_BUILD_DIR}/%{name}-%{version} ${RPM_BUILD_ROOT}%{_datadir}/%{name}/web
%pre
# User/Group creations, as needed

18
packaging/bundle-dashboard.sh Executable file
View File

@@ -0,0 +1,18 @@
#!/bin/sh
SRCDIR="${1}"
WEBDIR="${2}"
DASHBOARD_TARBALL="dashboard.tar.gz"
DASHBOARD_VERSION="$(cat "${SRCDIR}/packaging/dashboard.version")"
mkdir -p "${SRCDIR}/tmp"
curl -sSL --connect-timeout 10 --retry 3 "https://github.com/netdata/dashboard/releases/download/${DASHBOARD_VERSION}/${DASHBOARD_TARBALL}" > "${DASHBOARD_TARBALL}" || exit 1
sha256sum -c "${SRCDIR}/packaging/dashboard.checksums" || exit 1
tar -xzf "${DASHBOARD_TARBALL}" -C "${SRCDIR}/tmp" || exit 1
# shellcheck disable=SC2046
cp -a $(find "${SRCDIR}/tmp" -mindepth 1 -maxdepth 1) "${WEBDIR}"
cp -a "${WEBDIR}/old/dashboard_info.js" "${WEBDIR}"
cp -a "${WEBDIR}/old/dashboard.slate.css" "${WEBDIR}"
cp -a "${WEBDIR}/old/dashboard.css" "${WEBDIR}"
cp -a "${WEBDIR}/old/main.css" "${WEBDIR}"

View File

@@ -9,20 +9,8 @@ SUBDIRS = \
server \
$(NULL)
CLEANFILES = \
netdata-switch-dashboard.sh \
$(NULL)
usersslconfigdir=$(configdir)/ssl
include $(top_srcdir)/build/subst.inc
SUFFIXES = .in
scriptsdir=${prefix}/libexec/netdata
scripts_SCRIPTS = \
netdata-switch-dashboard.sh \
$(NULL)
# Explicitly install directories to avoid permission issues due to umask
install-exec-local:
$(INSTALL) -d $(DESTDIR)$(usersslconfigdir)
@@ -31,5 +19,4 @@ dist_noinst_DATA = \
README.md \
gui/confluence/README.md \
gui/custom/README.md \
netdata-switch-dashboard.sh.in \
$(NULL)

View File

@@ -71,6 +71,11 @@ dist_web_DATA = \
version.txt \
$(NULL)
webolddir=$(webdir)/old
dist_webold_DATA = \
old/index.html \
$(NULL)
webstaticdir=$(webdir)/static/img
dist_webstatic_DATA = \
static/img/netdata-logomark.svg \

View File

@@ -499,10 +499,12 @@ function toggleAgentItem(e, guid) {
// When you stream metrics from netdata to netdata, the recieving netdata now
// has multiple host databases. It's own, and multiple mirrored. Mirrored databases
// can be accessed with <http://localhost:19999/host/NAME/>
const OLD_DASHBOARD_SUFFIX = "old"
function renderStreamedHosts(options) {
let html = `<div class="info-item">Databases streamed to this agent</div>`;
var base = document.location.origin.toString() + document.location.pathname.toString();
var base = document.location.origin.toString() +
document.location.pathname.toString().replace(`/${OLD_DASHBOARD_SUFFIX}`, "");
if (base.endsWith("/host/" + options.hostname + "/")) {
base = base.substring(0, base.length - ("/host/" + options.hostname + "/").toString().length);
}
@@ -536,10 +538,10 @@ function renderStreamedHosts(options) {
displayedDatabases = true;
if (hostname === master) {
url = `${base}/`;
url = `${base}/${OLD_DASHBOARD_SUFFIX}/`;
icon = 'home';
} else {
url = `${base}/host/${hostname}/`;
url = `${base}/host/${hostname}/${OLD_DASHBOARD_SUFFIX}/`;
icon = 'window-restore';
}
@@ -1932,7 +1934,7 @@ function renderChartsAndMenu(data) {
function loadJs(url, callback) {
$.ajax({
url: url,
url: `../${url}`,
cache: true,
dataType: "script",
xhrFields: { withCredentials: true } // required for the cookie
@@ -1979,7 +1981,7 @@ function loadBootstrapSlider(callback) {
if (bootstrapSliderLoaded === false) {
bootstrapSliderLoaded = true;
loadJs('lib/bootstrap-slider-10.0.0.min.js', function () {
NETDATA._loadCSS('css/bootstrap-slider-10.0.0.min.css');
NETDATA._loadCSS('../css/bootstrap-slider-10.0.0.min.css');
callback();
});
} else {

1322
web/gui/old/index.html Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -1,60 +0,0 @@
#!/bin/sh
# SPDX-License-Identifier: GPL-3.0-or-later
# (c) 2020 Netdata Incorporated
set -e
webdir="@webdir_POST@"
configdir="@configdir_POST@"
usage() {
cat << EOF
USAGE: switch-netdata-dashboard.sh <dashboard-name>
<dashboard-name> is required, it specifies which dashboard to use. Valid
arguments are 'react' to use the new React dashboard, and 'classic'
to use the old dashboard.
Once run, you can use the new dashboard by performing a valdiating reload
in your browser (Ctrl-Shift-R in most browsers).
EOF
exit 1
}
switch_dashboard() {
new="${1}"
path="${webdir}-${new}"
echo "Switching to ${new} dashboard..."
for dashboard in classic react ; do
# shellcheck disable=SC2013
for item in $(cat ${webdir}-${dashboard}/.files) ; do
rm -f "${webdir}/${item}"
done
done
cp -a "${path}/." "${webdir}"
if [ -e "${configdir}/.environment" ] ; then
if grep -q NETDATA_SELECTED_DASHBOARD "${configdir}/.environment" ; then
sed -E "s/^NETDATA_SELECTED_DASHBOARD=\".*\"$/NETDATA_SELECTED_DASHBOARD=\"${new}\"/" "${configdir}/.environment"
else
echo "NETDATA_SELECTED_DASHBOARD=\"${new}\"" >> "${configdir}/.environment"
fi
fi
exit 0
}
case "${1}" in
react)
switch_dashboard react
;;
classic)
switch_dashboard classic
;;
*)
usage
;;
esac