add version command and add build information to metrics

Signed-off-by: David Christofas <dchristofas@owncloud.com>
This commit is contained in:
David Christofas
2020-09-25 13:06:26 +02:00
parent ff8fc23ce5
commit 9fc09cba43
9 changed files with 71 additions and 1 deletions
+2
View File
@@ -37,6 +37,7 @@ func Execute() error {
Flags: flagset.RootWithConfig(cfg),
Before: func(c *cli.Context) error {
cfg.Server.Version = version.String
return ParseConfig(c, cfg)
},
@@ -47,6 +48,7 @@ func Execute() error {
ListAccounts(cfg),
InspectAccount(cfg),
RemoveAccount(cfg),
PrintVersion(cfg),
},
}
+2
View File
@@ -43,6 +43,8 @@ func Server(cfg *config.Config) *cli.Command {
defer cancel()
mtrcs.BuildInfo.WithLabelValues(cfg.Server.Version).Set(1)
handler, err := svc.New(svc.Logger(logger), svc.Config(cfg))
if err != nil {
logger.Fatal().Err(err).Msg("could not initialize service handler")
+45
View File
@@ -0,0 +1,45 @@
package command
import (
"fmt"
"os"
"github.com/micro/cli/v2"
"github.com/micro/go-micro/v2/registry/mdns"
tw "github.com/olekukonko/tablewriter"
"github.com/owncloud/ocis/accounts/pkg/config"
"github.com/owncloud/ocis/accounts/pkg/flagset"
)
// PrintVersion prints the service versions of all running instances.
func PrintVersion(cfg *config.Config) *cli.Command {
return &cli.Command{
Name: "version",
Usage: "Print the versions of the running instances",
Flags: flagset.ListAccountsWithConfig(cfg),
Action: func(c *cli.Context) error {
reg := mdns.NewRegistry()
services, err := reg.GetService(cfg.GRPC.Namespace + "." + cfg.Server.Name)
if err != nil {
fmt.Println(fmt.Errorf("could not get accounts services from the registry: %v", err))
return err
}
if len(services) == 0 {
fmt.Println("No running accounts service found.")
return nil
}
table := tw.NewWriter(os.Stdout)
table.SetHeader([]string{"Version", "Address", "Id"})
table.SetAutoFormatHeaders(false)
for _, s := range services {
for _, n := range s.Nodes {
table.Append([]string{s.Version, n.Address, n.Id})
}
}
table.Render()
return nil
},
}
}