|
9 | 9 | "strings" |
10 | 10 | "time" |
11 | 11 |
|
| 12 | + "github.com/VictoriaMetrics/VictoriaMetrics/lib/buildinfo" |
12 | 13 | "github.com/VictoriaMetrics/VictoriaMetrics/lib/cgroup" |
13 | 14 | "github.com/VictoriaMetrics/VictoriaMetrics/lib/httpserver" |
14 | 15 | "github.com/VictoriaMetrics/VictoriaMetrics/lib/httputil" |
@@ -138,6 +139,27 @@ func RequestHandler(w http.ResponseWriter, r *http.Request) bool { |
138 | 139 | func selectHandler(w http.ResponseWriter, r *http.Request, path string) bool { |
139 | 140 | ctx := r.Context() |
140 | 141 |
|
| 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 | + |
141 | 163 | if path == "/select/vmui" { |
142 | 164 | // VMUI access via incomplete url without `/` in the end. Redirect to complete url. |
143 | 165 | // Use relative redirect, since the hostname and path prefix may be incorrect if VictoriaMetrics |
|
0 commit comments