Skip to content

Commit

Permalink
Show version in command-line and console (#240)
Browse files Browse the repository at this point in the history
* show router version

* add show version command to console

* add show version command
  • Loading branch information
Denchick authored Jul 23, 2023
1 parent 67fbf69 commit d6b85a5
Show file tree
Hide file tree
Showing 13 changed files with 344 additions and 289 deletions.
8 changes: 6 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
GIT_REVISION=`git rev-parse --short HEAD`
SPQR_VERSION=`git describe --tags --abbrev=0`
LDFLAGS=-ldflags "-X github.com/pg-sharding/spqr/pkg.GitRevision=${GIT_REVISION} -X github.com/pg-sharding/spqr/pkg.SpqrVersion=${SPQR_VERSION}"

.PHONY : run
.DEFAULT_GOAL := deps

Expand Down Expand Up @@ -26,7 +30,7 @@ build_coordinator:
go build -pgo=auto -o spqr-coordinator ./cmd/coordinator

build_router:
go build -pgo=auto -o spqr-router ./cmd/router
go build -pgo=auto -o spqr-router $(LDFLAGS) ./cmd/router

build_mover:
go build -pgo=auto -o spqr-mover ./cmd/mover
Expand Down Expand Up @@ -99,7 +103,7 @@ yaccgen:
gen: gogen yaccgen

package:
sed -i 's/SPQR_VERSION/${VERSION}/g' debian/changelog
sed -i 's/SPQR_VERSION/${SPQR_VERSION}/g' debian/changelog
dpkg-buildpackage -us -uc

.PHONY: build gen
41 changes: 21 additions & 20 deletions cmd/router/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"sync"
"syscall"

"github.com/pg-sharding/spqr/pkg"
"github.com/pg-sharding/spqr/pkg/config"
"github.com/pg-sharding/spqr/pkg/spqrlog"
router "github.com/pg-sharding/spqr/router"
Expand All @@ -22,28 +23,28 @@ import (
)

var (
rcfgPath string
cpuProfile bool
memProfile bool
profileFile string
daemonize bool
console bool
logLevel string
gomaxprocs int

rcfgPath string
cpuProfile bool
memProfile bool
profileFile string
daemonize bool
console bool
logLevel string
gomaxprocs int
pgprotoDebug bool
)

var rootCmd = &cobra.Command{
Use: "spqr-router run --config `path-to-config-folder`",
Short: "sqpr-router",
Long: "spqr-router",
CompletionOptions: cobra.CompletionOptions{
DisableDefaultCmd: true,
},
SilenceUsage: true,
SilenceErrors: true,
}
rootCmd = &cobra.Command{
Use: "spqr-router run --config `path-to-config-folder`",
Short: "sqpr-router",
Long: "spqr-router",
CompletionOptions: cobra.CompletionOptions{
DisableDefaultCmd: true,
},
Version: pkg.SpqrVersionRevision,
SilenceUsage: true,
SilenceErrors: true,
}
)

func init() {
rootCmd.PersistentFlags().StringVarP(&rcfgPath, "config", "c", "/etc/spqr/router.yaml", "path to config file")
Expand Down
2 changes: 1 addition & 1 deletion docker/spqr/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.20

COPY ./ /spqr
RUN cd /spqr && make && make build
RUN cd /spqr && make && make build GIT_REVISION=devel SPQR_VERSION=devel
18 changes: 17 additions & 1 deletion pkg/clientinteractor/interactor.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@ import (
"strconv"
"strings"

"github.com/pg-sharding/spqr/pkg"
"github.com/pg-sharding/spqr/pkg/models/dataspaces"
"github.com/pg-sharding/spqr/pkg/models/topology"
"github.com/pg-sharding/spqr/pkg/pool"
"github.com/pg-sharding/spqr/pkg/shard"
"github.com/pg-sharding/spqr/pkg/txstatus"
spqrparser "github.com/pg-sharding/spqr/yacc/console"
"github.com/pg-sharding/spqr/router/statistics"
spqrparser "github.com/pg-sharding/spqr/yacc/console"

"github.com/pg-sharding/spqr/pkg/client"
"github.com/pg-sharding/spqr/pkg/spqrlog"
Expand Down Expand Up @@ -143,6 +144,21 @@ func (pi *PSQLInteractor) Pools(_ context.Context, ps []pool.Pool) error {
return pi.CompleteMsg(len(ps))
}

func (pi *PSQLInteractor) Version(_ context.Context) error {
if err := pi.WriteHeader("SPQR version"); err != nil {
spqrlog.Zero.Error().Err(err).Msg("")
return err
}

msg := &pgproto3.DataRow{Values: [][]byte{[]byte(pkg.SpqrVersionRevision)}}
if err := pi.cl.Send(msg); err != nil {
spqrlog.Zero.Error().Err(err).Msg("")
return err
}

return pi.CompleteMsg(0)
}

func (pi *PSQLInteractor) AddShard(shard *datashards.DataShard) error {
if err := pi.WriteHeader("add datashard"); err != nil {
spqrlog.Zero.Error().Err(err).Msg("")
Expand Down
2 changes: 2 additions & 0 deletions pkg/meta/meta.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,8 @@ func ProcessShow(ctx context.Context, stmt *spqrparser.Show, mngr EntityMgr, ci
}

return cli.Pools(ctx, respPools)
case spqrparser.VersionStr:
return cli.Version(ctx)
default:
return unknownCoordinatorCommand
}
Expand Down
10 changes: 10 additions & 0 deletions pkg/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package pkg

import "fmt"

var (
// These variables are here only to show current version. They are set in makefile during build process
SpqrVersion = "devel"
GitRevision = "devel"
SpqrVersionRevision = fmt.Sprintf("%s-%s", SpqrVersion, GitRevision)
)
1 change: 1 addition & 0 deletions test/regress/schedule/console
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ test: show_shards
test: show_routers
test: show_key_ranges
test: show_sharding_rules
test: show_version
test: drop
test: add
test: teardown
13 changes: 13 additions & 0 deletions test/regress/tests/console/expected/show_version.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@

SQPR router admin console
Here you can configure your routing rules
------------------------------------------------
You can find documentation here
https://github.com/pg-sharding/spqr/tree/master/docs

SHOW version;
SPQR version
--------------
devel-devel
(1 row)

1 change: 1 addition & 0 deletions test/regress/tests/console/sql/show_version.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SHOW version;
1 change: 1 addition & 0 deletions yacc/console/ast.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ const (
PoolsStr = "pools"
BackendConnectionsStr = "backend_connections"
StatusStr = "status"
VersionStr = "version"
UnsupportedStr = "unsupported"
)

Expand Down
1 change: 1 addition & 0 deletions yacc/console/reserved_keyword.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ var reservedWords = map[string]int{
"all": ALL,
"shutdown": SHUTDOWN,
"split": SPLIT,
"version": VERSION,
"from": FROM,
"by": BY,
"to": TO,
Expand Down
Loading

0 comments on commit d6b85a5

Please sign in to comment.