-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Add feature to build and enable UI V2 #4974
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
7634209
c92d7b1
e261fab
b158b66
63c7487
bf54ae4
607a983
6686470
7a63a78
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,4 @@ | ||
| // Copyright 2023 Prometheus Team | ||
| // Copyright The Prometheus Authors | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
|
|
@@ -27,6 +27,7 @@ const ( | |
| FeatureUTF8StrictMode = "utf8-strict-mode" | ||
| FeatureAutoGOMEMLIMIT = "auto-gomemlimit" | ||
| FeatureAutoGOMAXPROCS = "auto-gomaxprocs" | ||
| FeatureUIV2 = "ui-v2" | ||
| ) | ||
|
|
||
| var AllowedFlags = []string{ | ||
|
|
@@ -36,6 +37,7 @@ var AllowedFlags = []string{ | |
| FeatureUTF8StrictMode, | ||
| FeatureAutoGOMEMLIMIT, | ||
| FeatureAutoGOMAXPROCS, | ||
| FeatureUIV2, | ||
| } | ||
|
|
||
| type Flagger interface { | ||
|
|
@@ -45,6 +47,7 @@ type Flagger interface { | |
| UTF8StrictMode() bool | ||
| EnableAutoGOMEMLIMIT() bool | ||
| EnableAutoGOMAXPROCS() bool | ||
| EnableUIV2() bool | ||
| } | ||
|
|
||
| type Flags struct { | ||
|
|
@@ -55,6 +58,7 @@ type Flags struct { | |
| utf8StrictMode bool | ||
| enableAutoGOMEMLIMIT bool | ||
| enableAutoGOMAXPROCS bool | ||
| enableUIV2 bool | ||
| } | ||
|
|
||
| func (f *Flags) EnableAlertNamesInMetrics() bool { | ||
|
|
@@ -81,6 +85,10 @@ func (f *Flags) EnableAutoGOMAXPROCS() bool { | |
| return f.enableAutoGOMAXPROCS | ||
| } | ||
|
|
||
| func (f *Flags) EnableUIV2() bool { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think UI is ready to be shipped with next release, so I would rather not include it in the release. Would it be possible for us to provide a separate build target instead? |
||
| return f.enableUIV2 | ||
| } | ||
|
|
||
| type flagOption func(flags *Flags) | ||
|
|
||
| func enableReceiverNameInMetrics() flagOption { | ||
|
|
@@ -119,6 +127,12 @@ func enableAlertNamesInMetrics() flagOption { | |
| } | ||
| } | ||
|
|
||
| func enableUIV2() flagOption { | ||
| return func(configs *Flags) { | ||
| configs.enableUIV2 = true | ||
| } | ||
| } | ||
|
|
||
| func NewFlags(logger *slog.Logger, features string) (Flagger, error) { | ||
| fc := &Flags{logger: logger} | ||
| opts := []flagOption{} | ||
|
|
@@ -147,6 +161,9 @@ func NewFlags(logger *slog.Logger, features string) (Flagger, error) { | |
| case FeatureAutoGOMAXPROCS: | ||
| opts = append(opts, enableAutoGOMAXPROCS()) | ||
| logger.Warn("Automatically set GOMAXPROCS to match Linux container CPU quota") | ||
| case FeatureUIV2: | ||
| opts = append(opts, enableUIV2()) | ||
| logger.Warn("Enable the new UI (UIv2) and disable the old UI (UIv1)") | ||
| default: | ||
| return nil, fmt.Errorf("unknown option '%s' for --enable-feature", feature) | ||
| } | ||
|
|
@@ -176,3 +193,5 @@ func (n NoopFlags) UTF8StrictMode() bool { return false } | |
| func (n NoopFlags) EnableAutoGOMEMLIMIT() bool { return false } | ||
|
|
||
| func (n NoopFlags) EnableAutoGOMAXPROCS() bool { return false } | ||
|
|
||
| func (n NoopFlags) EnableUIV2() bool { return false } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| #!/usr/bin/env bash | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We removed this file in #4617 do we need to add it back now again?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's used in prometheus for the bundling of static assets into a go file. I think we should keep it.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think we should add
So, we are missing out on the main benefit of compression: Reducing the number of TCP round trips.
❯ du -hs assets/index-D3YozeYE.js.gz assets/index-pOPVlMO9.css.gz index.html.gz
164K assets/index-D3YozeYE.js.gz
32K assets/index-pOPVlMO9.css.gz
4.0K index.html.gz
❯ du -hs assets/index-D3YozeYE.js assets/index-pOPVlMO9.css index.html
520K assets/index-D3YozeYE.js
216K assets/index-pOPVlMO9.css
4.0K index.htmlThus, your change will reduce the binary size by 500K . TLDR; We should keep it simple and not do any compression. If we want to do compression, we should do it properly, and support streaming the files compressed over the network.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The binary file saving are small right now because of tree shaking. There is very little in the UI if you compile it from this PR. As more features and functionality get added, this will grow. I don't have hard data around what that will be, but if there's consensus around embedding the uncompressed files, I'll pull this out. |
||
|
|
||
| # Copyright The Prometheus Authors | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| set -euo pipefail | ||
|
|
||
| export STATIC_DIR=static | ||
| PREBUILT_ASSETS_STATIC_DIR=${PREBUILT_ASSETS_STATIC_DIR:-} | ||
| if [ -n "$PREBUILT_ASSETS_STATIC_DIR" ]; then | ||
| STATIC_DIR=$(realpath $PREBUILT_ASSETS_STATIC_DIR) | ||
| fi | ||
|
|
||
| cd ui | ||
| cp embed.go.tmpl embed.go | ||
|
|
||
| GZIP_OPTS="-fkn" | ||
| # gzip option '-k' may not always exist in the latest gzip available on different distros. | ||
| if ! gzip -k -h &>/dev/null; then GZIP_OPTS="-fn"; fi | ||
|
|
||
| mkdir -p static | ||
| find static -type f -name '*.gz' -delete | ||
|
|
||
| # Compress files from the prebuilt static directory and replicate the structure in the current static directory | ||
| find "${STATIC_DIR}" -type f ! -name '*.gz' -exec bash -c ' | ||
| for file; do | ||
| dest="${file#${STATIC_DIR}}" | ||
| mkdir -p "static/$(dirname "$dest")" | ||
| gzip '"$GZIP_OPTS"' "$file" -c > "static/${dest}.gz" | ||
| done | ||
| ' bash {} + | ||
|
|
||
| # Append the paths of gzipped files to embed.go | ||
| find static -type f -name '*.gz' -print0 | sort -z | xargs -0 echo //go:embed >> embed.go | ||
|
|
||
| echo var EmbedFS embed.FS >> embed.go | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| *.gz | ||
| embed.go |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| // Copyright The Prometheus Authors | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| //go:build builtinassets | ||
|
|
||
| package ui | ||
|
|
||
| import ( | ||
| "net/http" | ||
|
|
||
| "github.com/prometheus/common/assets" | ||
| ) | ||
|
|
||
| var Assets = http.FS(assets.New(EmbedFS)) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| #!/bin/bash | ||
|
|
||
| # Copyright The Prometheus Authors | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
|
|
||
| set -e | ||
|
|
||
| if ! [[ -w $HOME ]] | ||
| then | ||
| export npm_config_cache=$(mktemp -d) | ||
| fi | ||
|
|
||
| assetsDir="./static" | ||
|
|
||
| function buildMantineUI() { | ||
| echo "build mantine-ui" | ||
| (cd mantine-ui && npm run build) | ||
| mkdir -p ${assetsDir} | ||
| rm -rf ${assetsDir}/mantine-ui | ||
| mv ./mantine-ui/dist ${assetsDir}/mantine-ui | ||
| } | ||
|
|
||
| buildMantineUI |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| // Copyright The Prometheus Authors | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
|
|
||
| //go:build builtinassets | ||
|
|
||
| package ui | ||
|
|
||
| import "embed" |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Currently the project ships pre-compiled assets bundle so UI does not have to be built each time.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should re-evaluate that for the mantine based UI. The build output has unique filenames per build. This will cause a lot of churn in git.