Skip to content

Commit 46e58a6

Browse files
authored
Merge pull request prometheus#17713 from roidelapluie/roidelapluie/fix_ui_updates
web/ui: Add checks for Mantine UI PromQL docs and update generated files
2 parents 3da5588 + 68e2c8e commit 46e58a6

8 files changed

Lines changed: 2295 additions & 902 deletions

File tree

.github/workflows/ci.yml

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -202,20 +202,22 @@ jobs:
202202
if: ${{ contains(needs.*.result, 'failure') || contains(needs.*.result, 'cancelled') }}
203203
run: exit 1
204204
check_generated_parser:
205+
# Checks generated parser and UI functions list. Not renaming as it is a required check.
205206
name: Check generated parser
206207
runs-on: ubuntu-latest
208+
container:
209+
image: quay.io/prometheus/golang-builder:1.25-base
207210
steps:
208211
- name: Checkout repository
209212
uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1
210213
with:
211214
persist-credentials: false
212-
- name: Install Go
213-
uses: actions/setup-go@4dc6199c7b1a012772edbd06daecab0f50c9053c # v6.1.0
215+
- uses: prometheus/promci@c0916f0a41f13444612a8f0f5e700ea34edd7c19 # v0.5.3
216+
- uses: ./.github/promci/actions/setup_environment
214217
with:
215-
cache: false
216-
go-version: 1.25.x
217-
- name: Run goyacc and check for diff
218-
run: make install-goyacc check-generated-parser
218+
enable_npm: true
219+
- run: make install-goyacc check-generated-parser
220+
- run: make check-generated-promql-functions
219221
golangci:
220222
name: golangci-lint
221223
runs-on: ubuntu-latest

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ npm_licenses.tar.bz2
2626

2727
/vendor
2828
/.build
29+
/go.work.sum
2930

3031
/**/node_modules
3132

Makefile

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,20 @@ ui-lint:
7979
# new Mantine-based UI is fully integrated and the old app can be removed.
8080
cd $(UI_PATH)/react-app && npm run lint
8181

82+
.PHONY: generate-promql-functions
83+
generate-promql-functions: ui-install
84+
@echo ">> generating PromQL function signatures"
85+
@cd $(UI_PATH)/mantine-ui/src/promql/tools && $(GO) run ./gen_functions_list > ../functionSignatures.ts
86+
@echo ">> generating PromQL function documentation"
87+
@cd $(UI_PATH)/mantine-ui/src/promql/tools && $(GO) run ./gen_functions_docs $(CURDIR)/docs/querying/functions.md > ../functionDocs.tsx
88+
@echo ">> formatting generated files"
89+
@cd $(UI_PATH)/mantine-ui && npx prettier --write --print-width 120 src/promql/functionSignatures.ts src/promql/functionDocs.tsx
90+
91+
.PHONY: check-generated-promql-functions
92+
check-generated-promql-functions: generate-promql-functions
93+
@echo ">> checking generated PromQL functions"
94+
@git diff --exit-code -- $(UI_PATH)/mantine-ui/src/promql/functionSignatures.ts $(UI_PATH)/mantine-ui/src/promql/functionDocs.tsx || (echo "Generated PromQL function files are out of date. Please run 'make generate-promql-functions' and commit the changes." && false)
95+
8296
.PHONY: assets
8397
ifndef SKIP_UI_BUILD
8498
assets: check-node-version ui-install ui-build
@@ -194,6 +208,8 @@ GO_SUBMODULE_DIRS := documentation/examples/remote_storage internal/tools web/ui
194208
.PHONY: update-all-go-deps
195209
update-all-go-deps: update-go-deps
196210
$(foreach dir,$(GO_SUBMODULE_DIRS),$(MAKE) update-go-deps-in-dir DIR=$(dir);)
211+
@echo ">> syncing Go workspace"
212+
@$(GO) work sync
197213

198214
.PHONY: update-go-deps-in-dir
199215
update-go-deps-in-dir:

go.work

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
go 1.24.9
2+
3+
use (
4+
.
5+
./documentation/examples/remote_storage
6+
./internal/tools
7+
./web/ui/mantine-ui/src/promql/tools
8+
)

web/ui/mantine-ui/src/promql/functionDocs.tsx

Lines changed: 2093 additions & 803 deletions
Large diffs are not rendered by default.

web/ui/mantine-ui/src/promql/functionSignatures.ts

Lines changed: 135 additions & 79 deletions
Large diffs are not rendered by default.

web/ui/mantine-ui/src/promql/tools/gen_functions_docs/main.go

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,28 +18,31 @@ import (
1818
"fmt"
1919
"io"
2020
"log"
21-
"net/http"
21+
"os"
2222
"sort"
2323
"strings"
2424

2525
"github.com/grafana/regexp"
2626
"github.com/russross/blackfriday/v2"
2727
)
2828

29-
var funcDocsRe = regexp.MustCompile("^## `(.+)\\(\\)`\n$|^## (Trigonometric Functions)\n$")
29+
var funcDocsRe = regexp.MustCompile("^## `([^)]+)\\(\\)` and `([^)]+)\\(\\)`\n$|^## `(.+)\\(\\)`\n$|^## (Trigonometric Functions)\n$")
3030

3131
func main() {
32-
resp, err := http.Get("https://raw.githubusercontent.com/prometheus/prometheus/master/docs/querying/functions.md")
33-
if err != nil {
34-
log.Fatalln("Failed to fetch function docs:", err)
32+
// Read from local file instead of fetching from upstream.
33+
if len(os.Args) < 2 {
34+
log.Fatalln("Usage: gen_functions_docs <path-to-functions.md>")
3535
}
36-
if resp.StatusCode != 200 {
37-
log.Fatalln("Bad status code while fetching function docs:", resp.Status)
36+
functionsPath := os.Args[1]
37+
file, err := os.Open(functionsPath)
38+
if err != nil {
39+
log.Fatalln("Failed to open function docs:", err)
3840
}
41+
defer file.Close()
3942

4043
funcDocs := map[string]string{}
4144

42-
r := bufio.NewReader(resp.Body)
45+
r := bufio.NewReader(file)
4346
currentFunc := ""
4447
currentDocs := ""
4548

@@ -58,6 +61,11 @@ func main() {
5861
"last_over_time",
5962
"present_over_time",
6063
"mad_over_time",
64+
"first_over_time",
65+
"ts_of_first_over_time",
66+
"ts_of_last_over_time",
67+
"ts_of_max_over_time",
68+
"ts_of_min_over_time",
6169
} {
6270
funcDocs[fn] = currentDocs
6371
}
@@ -81,6 +89,12 @@ func main() {
8189
} {
8290
funcDocs[fn] = currentDocs
8391
}
92+
case "histogram_count_and_histogram_sum":
93+
funcDocs["histogram_count"] = currentDocs
94+
funcDocs["histogram_sum"] = currentDocs
95+
case "histogram_stddev_and_histogram_stdvar":
96+
funcDocs["histogram_stddev"] = currentDocs
97+
funcDocs["histogram_stdvar"] = currentDocs
8498
default:
8599
funcDocs[currentFunc] = currentDocs
86100
}
@@ -103,10 +117,16 @@ func main() {
103117
}
104118
currentDocs = ""
105119

106-
currentFunc = string(matches[1])
107-
if matches[2] != "" {
108-
// This is the case for "## Trigonometric Functions"
109-
currentFunc = matches[2]
120+
if matches[1] != "" && matches[2] != "" {
121+
// Combined functions: "## `function1()` and `function2()`"
122+
// Store as "function1_and_function2" and handle in saveCurrent.
123+
currentFunc = matches[1] + "_and_" + matches[2]
124+
} else if matches[3] != "" {
125+
// Single function: "## `function_name()`"
126+
currentFunc = string(matches[3])
127+
} else if matches[4] != "" {
128+
// Special section: "## Trigonometric Functions"
129+
currentFunc = matches[4]
110130
}
111131
} else {
112132
currentDocs += line

web/ui/mantine-ui/src/promql/tools/gen_functions_list/main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,10 @@ func main() {
4141
sort.Strings(fnNames)
4242
fmt.Println(`import { valueType, Func } from './ast';
4343
44-
export const functionSignatures: Record<string, Func> = {`)
44+
export const functionSignatures: Record<string, Func> = {`)
4545
for _, fnName := range fnNames {
4646
fn := parser.Functions[fnName]
4747
fmt.Printf(" %s: { name: '%s', argTypes: [%s], variadic: %d, returnType: %s },\n", fn.Name, fn.Name, formatValueTypes(fn.ArgTypes), fn.Variadic, formatValueType(fn.ReturnType))
4848
}
49-
fmt.Println("}")
49+
fmt.Println("};")
5050
}

0 commit comments

Comments
 (0)