Skip to content

Commit d205cf8

Browse files
committed
app/vmui: show VictoriaLogs version in the vmui's footer (#116)
1 parent e300c83 commit d205cf8

File tree

5 files changed

+65
-1
lines changed

5 files changed

+65
-1
lines changed

app/vlselect/main.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"strings"
1010
"time"
1111

12+
"github.com/VictoriaMetrics/VictoriaMetrics/lib/buildinfo"
1213
"github.com/VictoriaMetrics/VictoriaMetrics/lib/cgroup"
1314
"github.com/VictoriaMetrics/VictoriaMetrics/lib/httpserver"
1415
"github.com/VictoriaMetrics/VictoriaMetrics/lib/httputil"
@@ -138,6 +139,27 @@ func RequestHandler(w http.ResponseWriter, r *http.Request) bool {
138139
func selectHandler(w http.ResponseWriter, r *http.Request, path string) bool {
139140
ctx := r.Context()
140141

142+
if path == "/select/buildinfo" {
143+
httpserver.EnableCORS(w, r)
144+
145+
if r.Method != http.MethodGet {
146+
w.Header().Set("Content-Type", "application/json")
147+
w.WriteHeader(http.StatusMethodNotAllowed)
148+
fmt.Fprintf(w, `{"status":"error","msg":"method %q isn't allowed"}`, r.Method)
149+
return true
150+
}
151+
152+
v := buildinfo.ShortVersion()
153+
if v == "" {
154+
// buildinfo.ShortVersion() may return empty result for builds without tags
155+
v = buildinfo.Version
156+
}
157+
158+
w.Header().Set("Content-Type", "application/json")
159+
fmt.Fprintf(w, `{"status":"success","data":{"version":%q}}`, v)
160+
return true
161+
}
162+
141163
if path == "/select/vmui" {
142164
// VMUI access via incomplete url without `/` in the end. Redirect to complete url.
143165
// Use relative redirect, since the hostname and path prefix may be incorrect if VictoriaMetrics
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export const getBuildInfoUrl = (server: string): string =>
2+
`${server}/select/buildinfo`;
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import { useAppState } from "../state/common/StateContext";
2+
import { useEffect, useState } from "preact/compat";
3+
import { ErrorTypes } from "../types";
4+
import { getBuildInfoUrl } from "../api/buildinfo";
5+
6+
const useGetVersion = () => {
7+
const { serverUrl } = useAppState();
8+
9+
const [version, setVersion] = useState("");
10+
const [isLoading, setIsLoading] = useState(false);
11+
const [error, setError] = useState<ErrorTypes | string>("");
12+
13+
useEffect(() => {
14+
const fetchVersion = async () => {
15+
setError("");
16+
setIsLoading(true);
17+
18+
try {
19+
const response = await fetch(getBuildInfoUrl(serverUrl));
20+
const result = await response.json();
21+
setVersion(result?.data?.version);
22+
} catch (e) {
23+
setIsLoading(false);
24+
if (e instanceof Error) setError(`${e.name}: ${e.message}`);
25+
}
26+
};
27+
28+
fetchVersion();
29+
}, [serverUrl]);
30+
31+
return { version, isLoading, error };
32+
};
33+
34+
export default useGetVersion;
35+

app/vmui/packages/vmui/src/layouts/Footer/Footer.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { FC, memo } from "preact/compat";
22
import { LogoShortIcon } from "../../components/Main/Icons";
33
import "./style.scss";
44
import { footerLinksToLogs } from "../../constants/footerLinks";
5+
import useGetVersion from "../../hooks/useGetVersion";
56

67
interface Props {
78
links?: {
@@ -13,6 +14,7 @@ interface Props {
1314

1415
const Footer: FC<Props> = memo(({ links = footerLinksToLogs }) => {
1516
const copyrightYears = `2019-${new Date().getFullYear()}`;
17+
const { version } = useGetVersion();
1618

1719
return <footer className="vm-footer">
1820
<a
@@ -37,7 +39,8 @@ const Footer: FC<Props> = memo(({ links = footerLinksToLogs }) => {
3739
</a>
3840
))}
3941
<div className="vm-footer__copyright">
40-
&copy; {copyrightYears} VictoriaMetrics
42+
&copy; {copyrightYears} VictoriaMetrics.
43+
{version && <span className="vm-footer__version">&nbsp;Version: {version}</span>}
4144
</div>
4245
</footer>;
4346
});

docs/victorialogs/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ according to the follosing docs:
2121

2222
## tip
2323

24+
* FEATURE: [vmui](https://docs.victoriametrics.com/victoriametrics/single-server-victoriametrics/#vmui): show VictoriaLogs version in the vmui's footer. See [#116](https://github.com/VictoriaMetrics/VictoriaLogs/issues/116).
25+
2426
## [v1.39.0](https://github.com/VictoriaMetrics/VictoriaLogs/releases/tag/v1.39.0)
2527

2628
Released at 2025-11-29

0 commit comments

Comments
 (0)