github.com/grafana/pyroscope@v1.18.0/pkg/util/build/build.go (about) 1 package build 2 3 import ( 4 "encoding/json" 5 "net/http" 6 "runtime" 7 8 "github.com/prometheus/common/version" 9 prom "github.com/prometheus/prometheus/web/api/v1" 10 ) 11 12 // Version information passed to Prometheus version package. 13 // Package path as used by linker changes based on vendoring being used or not, 14 // so it's easier just to use stable Pyroscope path, and pass it to 15 // Prometheus in the code. 16 var ( 17 Version string 18 Revision string 19 Branch string 20 BuildUser string 21 BuildDate string 22 GoVersion string 23 ) 24 25 func init() { 26 version.Version = Version 27 version.Revision = Revision 28 version.Branch = Branch 29 version.BuildUser = BuildUser 30 version.BuildDate = BuildDate 31 version.GoVersion = runtime.Version() 32 } 33 34 func GetVersion() prom.PrometheusVersion { 35 return prom.PrometheusVersion{ 36 Version: version.Version, 37 Revision: version.Revision, 38 Branch: version.Branch, 39 BuildUser: version.BuildUser, 40 BuildDate: version.BuildDate, 41 GoVersion: version.GoVersion, 42 } 43 } 44 45 func BuildInfoHandler(rw http.ResponseWriter, req *http.Request) { 46 resp := struct { 47 Status string `json:"status"` 48 Data interface{} `json:"data,omitempty"` 49 }{ 50 Status: "success", 51 Data: GetVersion(), 52 } 53 rw.Header().Add("Content-Type", "application/json") 54 _ = json.NewEncoder(rw).Encode(&resp) 55 }