1
0
Fork 0
mirror of https://github.com/anyproto/any-sync.git synced 2025-06-09 17:45:03 +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"
"os"
"runtime"
"runtime/debug"
"strings"
"sync"
"time"
@ -54,11 +55,12 @@ type ComponentStatable interface {
// App is the central part of the application
// It contains and manages all components
type App struct {
components []Component
mu sync.RWMutex
startStat Stat
stopStat Stat
deviceState int
components []Component
mu sync.RWMutex
startStat Stat
stopStat Stat
deviceState int
anySyncVersion string
}
// 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 (
"github.com/anytypeio/any-sync/app"
"github.com/prometheus/client_golang/prometheus"
"runtime/debug"
)
func newVersionsCollector(a *app.App) prometheus.Collector {
@ -11,25 +10,13 @@ func newVersionsCollector(a *app.App) prometheus.Collector {
"anysync_versions",
"Build information about the main Go module.",
nil, prometheus.Labels{
"anysync_version": anySyncVerion(),
"anysync_version": a.AnySyncVersion(),
"app_name": a.AppName(),
"app_version": a.Version(),
},
), 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 {
ver prometheus.Metric
}