mirror of
https://github.com/akvorado/akvorado.git
synced 2025-12-11 22:14:02 +01:00
Instead of trying to copy Akvorado version around, move it to a single place, which can be imported by everything else.
73 lines
1.8 KiB
Go
73 lines
1.8 KiB
Go
// SPDX-FileCopyrightText: 2022 Free Mobile
|
|
// SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
package cmd
|
|
|
|
import (
|
|
"net/http"
|
|
"runtime"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
"github.com/spf13/cobra"
|
|
"golang.org/x/exp/slices"
|
|
|
|
"akvorado/common/helpers"
|
|
"akvorado/common/reporter"
|
|
"akvorado/common/schema"
|
|
)
|
|
|
|
func init() {
|
|
RootCmd.AddCommand(versionCmd)
|
|
}
|
|
|
|
var versionCmd = &cobra.Command{
|
|
Use: "version",
|
|
Short: "Print version",
|
|
Long: `Display version and build information about akvorado.`,
|
|
RunE: func(cmd *cobra.Command, _ []string) error {
|
|
cmd.Printf("akvorado %s\n", helpers.AkvoradoVersion)
|
|
cmd.Printf(" Built with: %s\n", runtime.Version())
|
|
cmd.Println()
|
|
|
|
sch, err := schema.New(schema.DefaultConfiguration())
|
|
if err != nil {
|
|
return err
|
|
}
|
|
cmd.Println("Can be disabled:")
|
|
for k := schema.ColumnTimeReceived; k < schema.ColumnLast; k++ {
|
|
column, ok := sch.LookupColumnByKey(k)
|
|
if ok && !column.Disabled && !column.NoDisable && !slices.Contains(sch.ClickHousePrimaryKeys(), column.Name) {
|
|
cmd.Printf("- %s\n", column.Name)
|
|
}
|
|
}
|
|
cmd.Println()
|
|
cmd.Println("Can be enabled:")
|
|
for k := schema.ColumnTimeReceived; k < schema.ColumnLast; k++ {
|
|
column, ok := sch.LookupColumnByKey(k)
|
|
if ok && column.Disabled {
|
|
cmd.Printf("- %s", column.Name)
|
|
if column.ClickHouseMainOnly {
|
|
cmd.Print(" (main table only)")
|
|
}
|
|
cmd.Println()
|
|
}
|
|
}
|
|
return nil
|
|
},
|
|
}
|
|
|
|
func versionHandler(c *gin.Context) {
|
|
c.JSON(http.StatusOK, gin.H{
|
|
"version": helpers.AkvoradoVersion,
|
|
"compiler": runtime.Version(),
|
|
})
|
|
}
|
|
|
|
func versionMetrics(r *reporter.Reporter) {
|
|
r.GaugeVec(reporter.GaugeOpts{
|
|
Name: "info",
|
|
Help: "Akvorado build information",
|
|
}, []string{"version", "compiler"}).
|
|
WithLabelValues(helpers.AkvoradoVersion, runtime.Version()).Set(1)
|
|
}
|