mirror of
https://github.com/1f349/dendrite.git
synced 2024-11-08 10:06:55 +00:00
Add revision to version string (#3147)
Since the removal of `build.sh`, we don't include any information about the revision Dendrite was build from. Since go1.18, the revision a binary was build from is automatically included, so we can try to get that instead. This also adds a `dendrite_up` metric showing the current version (`dendrite_up{version="0.13.1+c796f20"} 1`) Closes #2993
This commit is contained in:
parent
69b2069dea
commit
99f94fc735
@ -1,3 +1,2 @@
|
|||||||
bin
|
bin
|
||||||
*.wasm
|
*.wasm
|
||||||
.git
|
|
@ -4,7 +4,7 @@
|
|||||||
# base installs required dependencies and runs go mod download to cache dependencies
|
# base installs required dependencies and runs go mod download to cache dependencies
|
||||||
#
|
#
|
||||||
FROM --platform=${BUILDPLATFORM} docker.io/golang:1.20-alpine AS base
|
FROM --platform=${BUILDPLATFORM} docker.io/golang:1.20-alpine AS base
|
||||||
RUN apk --update --no-cache add bash build-base curl
|
RUN apk --update --no-cache add bash build-base curl git
|
||||||
|
|
||||||
#
|
#
|
||||||
# build creates all needed binaries
|
# build creates all needed binaries
|
||||||
|
@ -26,6 +26,7 @@ import (
|
|||||||
"github.com/matrix-org/dendrite/setup/jetstream"
|
"github.com/matrix-org/dendrite/setup/jetstream"
|
||||||
"github.com/matrix-org/dendrite/setup/process"
|
"github.com/matrix-org/dendrite/setup/process"
|
||||||
"github.com/matrix-org/gomatrixserverlib/fclient"
|
"github.com/matrix-org/gomatrixserverlib/fclient"
|
||||||
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
|
|
||||||
"github.com/matrix-org/dendrite/appservice"
|
"github.com/matrix-org/dendrite/appservice"
|
||||||
@ -187,6 +188,16 @@ func main() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
upCounter := prometheus.NewCounter(prometheus.CounterOpts{
|
||||||
|
Namespace: "dendrite",
|
||||||
|
Name: "up",
|
||||||
|
ConstLabels: map[string]string{
|
||||||
|
"version": internal.VersionString(),
|
||||||
|
},
|
||||||
|
})
|
||||||
|
upCounter.Add(1)
|
||||||
|
prometheus.MustRegister(upCounter)
|
||||||
|
|
||||||
// Expose the matrix APIs directly rather than putting them under a /api path.
|
// Expose the matrix APIs directly rather than putting them under a /api path.
|
||||||
go func() {
|
go func() {
|
||||||
basepkg.SetupAndServeHTTP(processCtx, cfg, routers, httpAddr, nil, nil)
|
basepkg.SetupAndServeHTTP(processCtx, cfg, routers, httpAddr, nil, nil)
|
||||||
|
@ -2,6 +2,7 @@ package internal
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"runtime/debug"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -19,6 +20,8 @@ const (
|
|||||||
VersionMinor = 13
|
VersionMinor = 13
|
||||||
VersionPatch = 1
|
VersionPatch = 1
|
||||||
VersionTag = "" // example: "rc1"
|
VersionTag = "" // example: "rc1"
|
||||||
|
|
||||||
|
gitRevLen = 7 // 7 matches the displayed characters on github.com
|
||||||
)
|
)
|
||||||
|
|
||||||
func VersionString() string {
|
func VersionString() string {
|
||||||
@ -37,7 +40,30 @@ func init() {
|
|||||||
if branch != "" {
|
if branch != "" {
|
||||||
parts = append(parts, branch)
|
parts = append(parts, branch)
|
||||||
}
|
}
|
||||||
if len(parts) > 0 {
|
|
||||||
version += "+" + strings.Join(parts, ".")
|
defer func() {
|
||||||
|
if len(parts) > 0 {
|
||||||
|
version += "+" + strings.Join(parts, ".")
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
|
||||||
|
// Try to get the revision Dendrite was build from.
|
||||||
|
// If we can't, e.g. Dendrite wasn't built (go run) or no VCS version is present,
|
||||||
|
// we just use the provided version above.
|
||||||
|
info, ok := debug.ReadBuildInfo()
|
||||||
|
if !ok {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, setting := range info.Settings {
|
||||||
|
if setting.Key == "vcs.revision" {
|
||||||
|
revLen := len(setting.Value)
|
||||||
|
if revLen >= gitRevLen {
|
||||||
|
parts = append(parts, setting.Value[:gitRevLen])
|
||||||
|
} else {
|
||||||
|
parts = append(parts, setting.Value[:revLen])
|
||||||
|
}
|
||||||
|
break
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user