File tree 6 files changed +70
-8
lines changed
6 files changed +70
-8
lines changed Original file line number Diff line number Diff line change @@ -4,7 +4,7 @@ SERVER_BINARY = dblab-server
4
4
CLI_BINARY = dblab
5
5
GOARCH = amd64
6
6
7
- VERSION? =0.1
7
+ VERSION? =0.3. 1
8
8
BUILD_TIME? =$(shell date -u '+% Y% m% d-% H% M')
9
9
COMMIT? =no # $(shell git rev-parse HEAD)
10
10
BRANCH?=no # $(shell git rev-parse --abbrev-ref HEAD)
@@ -14,10 +14,10 @@ BUILD_DIR=${GOPATH}/${SERVER_BINARY}
14
14
15
15
# Setup the -ldflags option for go build here, interpolate the variable values
16
16
LDFLAGS = -ldflags "-s -w \
17
- -X main .version=${VERSION} \
17
+ -X gitlab.com/postgres-ai/database-lab/version .version=${VERSION} \
18
18
-X main.commit=${COMMIT} \
19
19
-X main.branch=${BRANCH}\
20
- -X main .buildTime=${BUILD_TIME}"
20
+ -X gitlab.com/postgres-ai/database-lab/version .buildTime=${BUILD_TIME}"
21
21
22
22
# Go tooling command aliases
23
23
GOBUILD = GO111MODULE=on GOARCH=${GOARCH} go build ${LDFLAGS}
Original file line number Diff line number Diff line change @@ -16,15 +16,12 @@ import (
16
16
"gitlab.com/postgres-ai/database-lab/cmd/cli/commands/snapshot"
17
17
"gitlab.com/postgres-ai/database-lab/cmd/cli/templates"
18
18
dblabLog "gitlab.com/postgres-ai/database-lab/pkg/log"
19
- )
20
-
21
- const (
22
- version = "v0.2.3"
19
+ "gitlab.com/postgres-ai/database-lab/version"
23
20
)
24
21
25
22
func main () {
26
23
app := & cli.App {
27
- Version : version ,
24
+ Version : version . GetVersion () ,
28
25
CommandNotFound : func (c * cli.Context , command string ) {
29
26
fmt .Fprintf (c .App .Writer , "[ERROR] Command %q not found.\n " , command )
30
27
},
Original file line number Diff line number Diff line change 1
1
package srv
2
2
3
3
import (
4
+ "encoding/json"
4
5
"fmt"
5
6
"net/http"
6
7
@@ -9,8 +10,14 @@ import (
9
10
10
11
"gitlab.com/postgres-ai/database-lab/pkg/client/dblabapi/types"
11
12
"gitlab.com/postgres-ai/database-lab/pkg/log"
13
+ "gitlab.com/postgres-ai/database-lab/version"
12
14
)
13
15
16
+ // HealthResponse represents a response for heath-check requests.
17
+ type HealthResponse struct {
18
+ Version string `json:"version"`
19
+ }
20
+
14
21
func (s * Server ) getInstanceStatus () http.HandlerFunc {
15
22
return func (w http.ResponseWriter , r * http.Request ) {
16
23
status , err := s .Cloning .GetInstanceState ()
@@ -136,3 +143,19 @@ func (s *Server) resetClone() http.HandlerFunc {
136
143
log .Dbg (fmt .Sprintf ("Clone ID=%s is being reset" , cloneID ))
137
144
}
138
145
}
146
+
147
+ // healthCheck provides a health check handler.
148
+ func (s * Server ) healthCheck (w http.ResponseWriter , _ * http.Request ) {
149
+ w .Header ().Set ("Content-Type" , "application/json; charset=utf-8" )
150
+
151
+ healthResponse := HealthResponse {
152
+ Version : version .GetVersion (),
153
+ }
154
+
155
+ if err := json .NewEncoder (w ).Encode (healthResponse ); err != nil {
156
+ http .Error (w , err .Error (), http .StatusInternalServerError )
157
+ log .Err (err )
158
+
159
+ return
160
+ }
161
+ }
Original file line number Diff line number Diff line change @@ -92,6 +92,9 @@ func (s *Server) Run() error {
92
92
r .HandleFunc ("/clone/{id}/reset" ,
93
93
authMW .authorized (s .resetClone ())).Methods (http .MethodPost )
94
94
95
+ // Health check.
96
+ r .HandleFunc ("/healthz" , s .healthCheck ).Methods (http .MethodGet )
97
+
95
98
// Show Swagger UI on index page.
96
99
if err := attachAPI (r ); err != nil {
97
100
log .Err (fmt .Sprintf ("Cannot load API description." ))
Original file line number Diff line number Diff line change
1
+ /*
2
+ 2019 © Postgres.ai
3
+ */
4
+
5
+ // Package version provides the Database Lab version info.
6
+ package version
7
+
8
+ import (
9
+ "fmt"
10
+ )
11
+
12
+ // ldflag variables.
13
+ var (
14
+ version string
15
+ buildTime string
16
+ )
17
+
18
+ // GetVersion return the app version info.
19
+ func GetVersion () string {
20
+ return fmt .Sprintf ("%s-%s" , version , buildTime )
21
+ }
Original file line number Diff line number Diff line change
1
+ /*
2
+ 2019 © Postgres.ai
3
+ */
4
+
5
+ package version
6
+
7
+ import (
8
+ "testing"
9
+
10
+ "github.com/stretchr/testify/assert"
11
+ )
12
+
13
+ func TestGetVersion (t * testing.T ) {
14
+ version = "0.0.1"
15
+ buildTime = "20200427-0551"
16
+
17
+ assert .Equal (t , "0.0.1-20200427-0551" , GetVersion ())
18
+ }
You can’t perform that action at this time.
0 commit comments