Skip to content

Commit

Permalink
Merge pull request #14 from piotrkowalczuk/feature/readiness-and-live…
Browse files Browse the repository at this point in the history
…ness-check-endpoints

readiness and liveness check endpoints plus grpc upgrade
  • Loading branch information
piotrkowalczuk authored Aug 24, 2018
2 parents 5f3f474 + 46c6257 commit c7195c9
Show file tree
Hide file tree
Showing 22 changed files with 276 additions and 92 deletions.
28 changes: 22 additions & 6 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,4 @@

[[constraint]]
name = "google.golang.org/grpc"
version = "^1.8.0"
version = "^1.14.0"
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ get:
dep ensure

publish: build
ifneq ($(skiplogin),true)
docker login
endif
docker build \
--build-arg VCS_REF=${VCS_REF} \
--build-arg BUILD_DATE=`date -u +"%Y-%m-%dT%H:%M:%SZ"` \
Expand Down
1 change: 1 addition & 0 deletions cmd/mnemosyned/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ func main() {
debugListener := initListener(l, config.host, config.port+1)

daemon, err := mnemosyned.NewDaemon(&mnemosyned.DaemonOpts{
Version: version,
SessionTTL: config.session.ttl,
SessionTTC: config.session.ttc,
Storage: config.storage,
Expand Down
21 changes: 12 additions & 9 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@ services:
container_name: mnemosyned-1
image: piotrkowalczuk/mnemosyne:latest
ports:
- 10010:8080
- 10011:8081
- 20010:8080
- 20011:8081
environment:
MNEMOSYNED_MONITORING: "true"
MNEMOSYNED_LOG_ENVIRONMENT: development
MNEMOSYNED_LOG_LEVEL: debug
MNEMOSYNED_CLUSTER_LISTEN: mnemosyned-1:8080
MNEMOSYNED_CLUSTER_SEEDS: mnemosyned-2:8080,mnemosyned-3:8080
MNEMOSYNED_POSTGRES_SCHEMA: mnemosyne1
Expand All @@ -29,10 +30,11 @@ services:
container_name: mnemosyned-2
image: piotrkowalczuk/mnemosyne:latest
ports:
- 10020:8080
- 10021:8081
- 20020:8080
- 20021:8081
environment:
MNEMOSYNED_MONITORING: "true"
MNEMOSYNED_LOG_ENVIRONMENT: development
MNEMOSYNED_LOG_LEVEL: debug
MNEMOSYNED_CLUSTER_LISTEN: mnemosyned-2:8080
MNEMOSYNED_CLUSTER_SEEDS: mnemosyned-1:8080,mnemosyned-3:8080
MNEMOSYNED_POSTGRES_SCHEMA: mnemosyne2
Expand All @@ -46,10 +48,11 @@ services:
container_name: mnemosyned-3
image: piotrkowalczuk/mnemosyne:latest
ports:
- 10030:8080
- 10031:8081
- 20030:8080
- 20031:8081
environment:
MNEMOSYNED_MONITORING: "true"
MNEMOSYNED_LOG_ENVIRONMENT: development
MNEMOSYNED_LOG_LEVEL: debug
MNEMOSYNED_CLUSTER_LISTEN: mnemosyned-3:8080
MNEMOSYNED_CLUSTER_SEEDS: mnemosyned-1:8080,mnemosyned-2:8080
MNEMOSYNED_POSTGRES_SCHEMA: mnemosyne3
Expand Down
19 changes: 17 additions & 2 deletions internal/cluster/cluster.go
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
package cluster

import (
"context"
"sort"

"github.com/piotrkowalczuk/mnemosyne/internal/jump"
"github.com/piotrkowalczuk/mnemosyne/mnemosynerpc"
"go.uber.org/zap"
"google.golang.org/grpc"
"google.golang.org/grpc/health/grpc_health_v1"
)

// Node ...
type Node struct {
Addr string
Client mnemosynerpc.SessionManagerClient
Health grpc_health_v1.HealthClient
}

// Cluster ...
Expand Down Expand Up @@ -66,7 +69,7 @@ func New(opts Opts) (csr *Cluster, err error) {
}

// Connect ...
func (c *Cluster) Connect(opts ...grpc.DialOption) error {
func (c *Cluster) Connect(ctx context.Context, opts ...grpc.DialOption) error {
for i, n := range c.nodes {
if n.Addr == c.listen {
continue
Expand All @@ -76,7 +79,7 @@ func (c *Cluster) Connect(opts ...grpc.DialOption) error {
c.logger.Debug("cluster node attempt to connect", zap.String("address", n.Addr), zap.Int("index", i))
}

conn, err := grpc.Dial(n.Addr, opts...)
conn, err := grpc.DialContext(ctx, n.Addr, opts...)
if err != nil {
return err
}
Expand All @@ -86,7 +89,9 @@ func (c *Cluster) Connect(opts ...grpc.DialOption) error {
}

n.Client = mnemosynerpc.NewSessionManagerClient(conn)
n.Health = grpc_health_v1.NewHealthClient(conn)
}

return nil
}

Expand All @@ -106,6 +111,16 @@ func (c *Cluster) Nodes() []*Node {
return c.nodes
}

// ExternalNodes returns all available nodes except host.
func (c *Cluster) ExternalNodes() (res []*Node) {
for _, n := range c.nodes {
if n.Addr != c.listen {
res = append(res, n)
}
}
return
}

// Len returns number of nodes.
func (c *Cluster) Len() int {
return c.buckets
Expand Down
5 changes: 3 additions & 2 deletions internal/cluster/cluster_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package cluster_test

import (
"context"
"flag"
"fmt"
"os"
Expand Down Expand Up @@ -148,7 +149,7 @@ func TestCluster_GetOther(t *testing.T) {
c, cancel := testCluster(t)
defer cancel()

if err := c.Connect(grpc.WithInsecure(), grpc.WithBlock()); err != nil {
if err := c.Connect(context.TODO(), grpc.WithInsecure(), grpc.WithBlock()); err != nil {
t.Fatalf("unexpected error: %s", err.Error())
}

Expand All @@ -168,7 +169,7 @@ func TestCluster_GetOther(t *testing.T) {
func TestCluster_Connect(t *testing.T) {
c, cancel := testCluster(t)
defer cancel()
if err := c.Connect(grpc.WithInsecure(), grpc.WithBlock()); err != nil {
if err := c.Connect(context.TODO(), grpc.WithInsecure(), grpc.WithBlock()); err != nil {
t.Fatalf("unexpected error: %s", err.Error())
}
}
Expand Down
Loading

0 comments on commit c7195c9

Please sign in to comment.