1
0
Fork 0
mirror of https://github.com/anyproto/any-sync.git synced 2025-06-10 18:10:54 +09:00

app.AnySyncVersion

This commit is contained in:
Sergey Cherepanov 2023-05-18 13:31:53 +02:00 committed by Mikhail Iudin
parent 0d72b3b671
commit b1ad0be3b4
No known key found for this signature in database
GPG key ID: FAAAA8BAABDFF1C0
2 changed files with 26 additions and 19 deletions

View file

@ -8,6 +8,7 @@ import (
"go.uber.org/zap" "go.uber.org/zap"
"os" "os"
"runtime" "runtime"
"runtime/debug"
"strings" "strings"
"sync" "sync"
"time" "time"
@ -54,11 +55,12 @@ type ComponentStatable interface {
// App is the central part of the application // App is the central part of the application
// It contains and manages all components // It contains and manages all components
type App struct { type App struct {
components []Component components []Component
mu sync.RWMutex mu sync.RWMutex
startStat Stat startStat Stat
stopStat Stat stopStat Stat
deviceState int deviceState int
anySyncVersion string
} }
// Name returns app name // Name returns app name
@ -315,3 +317,21 @@ func (app *App) SetDeviceState(state int) {
} }
} }
} }
var onceVersion sync.Once
func (app *App) AnySyncVersion() string {
onceVersion.Do(func() {
fmt.Println("111")
info, ok := debug.ReadBuildInfo()
if ok {
for _, mod := range info.Deps {
if mod.Path == "github.com/anytypeio/any-sync" {
app.anySyncVersion = mod.Version
break
}
}
}
})
return app.anySyncVersion
}

View file

@ -3,7 +3,6 @@ package metric
import ( import (
"github.com/anytypeio/any-sync/app" "github.com/anytypeio/any-sync/app"
"github.com/prometheus/client_golang/prometheus" "github.com/prometheus/client_golang/prometheus"
"runtime/debug"
) )
func newVersionsCollector(a *app.App) prometheus.Collector { func newVersionsCollector(a *app.App) prometheus.Collector {
@ -11,25 +10,13 @@ func newVersionsCollector(a *app.App) prometheus.Collector {
"anysync_versions", "anysync_versions",
"Build information about the main Go module.", "Build information about the main Go module.",
nil, prometheus.Labels{ nil, prometheus.Labels{
"anysync_version": anySyncVerion(), "anysync_version": a.AnySyncVersion(),
"app_name": a.AppName(), "app_name": a.AppName(),
"app_version": a.Version(), "app_version": a.Version(),
}, },
), prometheus.GaugeValue, 1)} ), prometheus.GaugeValue, 1)}
} }
func anySyncVerion() string {
info, ok := debug.ReadBuildInfo()
if ok {
for _, mod := range info.Deps {
if mod.Path == "github.com/anytypeio/any-sync" {
return mod.Version
}
}
}
return ""
}
type versionCollector struct { type versionCollector struct {
ver prometheus.Metric ver prometheus.Metric
} }