Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: unistack-org/micro
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v3.3.4
Choose a base ref
...
head repository: unistack-org/micro
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v3.3.5
Choose a head ref
  • 4 commits
  • 9 files changed
  • 2 contributors

Commits on Mar 26, 2021

  1. Copy the full SHA
    2df0c76 View commit details

Commits on Mar 27, 2021

  1. Copy the full SHA
    14026d1 View commit details

Commits on Mar 28, 2021

  1. server/health: add health check handler

    Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
    vtolstov committed Mar 28, 2021
    Copy the full SHA
    ce4c96a View commit details
  2. meter/handler: fix proto and generated code

    Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
    vtolstov committed Mar 28, 2021
    Copy the full SHA
    d2935ef View commit details
Showing with 236 additions and 6 deletions.
  1. +1 −1 go.mod
  2. +1 −2 go.sum
  3. +0 −2 meter/handler/handler.go
  4. +1 −1 meter/handler/handler.proto
  5. +3 −0 server/generate.go
  6. +87 −0 server/health/health.go
  7. +62 −0 server/health/health.proto
  8. +38 −0 server/health/health_micro.pb.go
  9. +43 −0 server/health/health_micro_http.pb.go
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -9,5 +9,5 @@ require (
github.com/imdario/mergo v0.3.12
github.com/patrickmn/go-cache v2.1.0+incompatible
github.com/silas/dag v0.0.0-20210121180416-41cf55125c34
golang.org/x/net v0.0.0-20210324205630-d1beb07c2056
golang.org/x/net v0.0.0-20210326220855-61e056675ecf
)
3 changes: 1 addition & 2 deletions go.sum
Original file line number Diff line number Diff line change
@@ -10,8 +10,7 @@ github.com/patrickmn/go-cache v2.1.0+incompatible h1:HRMgzkcYKYpi3C8ajMPV8OFXaaR
github.com/patrickmn/go-cache v2.1.0+incompatible/go.mod h1:3Qf8kWWT7OJRJbdiICTKqZju1ZixQ/KpMGzzAfe6+WQ=
github.com/silas/dag v0.0.0-20210121180416-41cf55125c34 h1:vBfVmA5mZhsQa2jr1FOL9nfA37N/jnbBmi5XUfviVTI=
github.com/silas/dag v0.0.0-20210121180416-41cf55125c34/go.mod h1:7RTUFBdIRC9nZ7/3RyRNH1bdqIShrDejd1YbLwgPS+I=
golang.org/x/net v0.0.0-20210324205630-d1beb07c2056 h1:sANdAef76Ioam9aQUUdcAqricwY/WUaMc4+7LY4eGg8=
golang.org/x/net v0.0.0-20210324205630-d1beb07c2056/go.mod h1:uSPa2vr4CLtc/ILN5odXGNXS6mhrKVzTaCXzk9m6W3k=
golang.org/x/net v0.0.0-20210326220855-61e056675ecf/go.mod h1:uSPa2vr4CLtc/ILN5odXGNXS6mhrKVzTaCXzk9m6W3k=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210324051608-47abb6519492/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
2 changes: 0 additions & 2 deletions meter/handler/handler.go
Original file line number Diff line number Diff line change
@@ -13,8 +13,6 @@ var (
_ MeterServer = &handler{}
)

type Empty struct{}

type handler struct {
meter meter.Meter
opts []meter.Option
2 changes: 1 addition & 1 deletion meter/handler/handler.proto
Original file line number Diff line number Diff line change
@@ -17,7 +17,7 @@ service Meter {
description: "Error response";
schema: {
json_schema: {
ref: "Empty";
ref: "micro.codec.Frame";
}
}
}
3 changes: 3 additions & 0 deletions server/generate.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package server

//go:generate protoc -I./health -I../ -I/home/vtolstov/.cache/go-path/pkg/mod/github.com/unistack-org/micro-proto@v0.0.1 --micro_out=components=micro|http|server,standalone=false,debug=true,paths=source_relative:./health health/health.proto
87 changes: 87 additions & 0 deletions server/health/health.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
package pb

import (
"context"

"github.com/unistack-org/micro/v3/codec"
"github.com/unistack-org/micro/v3/errors"
"github.com/unistack-org/micro/v3/server"
)

var (
// guard to fail early
_ HealthServer = &handler{}
)

type handler struct {
server server.Server
opts Options
}

type CheckFunc func(context.Context) error

type Option func(*Options)

type Options struct {
LiveChecks []CheckFunc
ReadyChecks []CheckFunc
Version string
Name string
}

func LiveChecks(fns ...CheckFunc) Option {
return func(o *Options) {
o.LiveChecks = append(o.LiveChecks, fns...)
}
}

func ReadyChecks(fns ...CheckFunc) Option {
return func(o *Options) {
o.ReadyChecks = append(o.ReadyChecks, fns...)
}
}

func Name(name string) Option {
return func(o *Options) {
o.Name = name
}
}

func Version(version string) Option {
return func(o *Options) {
o.Version = version
}
}

func NewHealth(opts ...Option) *handler {
options := Options{}
for _, o := range opts {
o(&options)
}
return &handler{opts: options}
}

func (h *handler) Live(ctx context.Context, req *codec.Frame, rsp *codec.Frame) error {
var err error
for _, fn := range h.opts.LiveChecks {
if err = fn(ctx); err != nil {
return errors.ServiceUnavailable(h.opts.Name, "%v", err)
}
}
return nil
}

func (h *handler) Ready(ctx context.Context, req *codec.Frame, rsp *codec.Frame) error {
var err error
for _, fn := range h.opts.ReadyChecks {
if err = fn(ctx); err != nil {
return errors.ServiceUnavailable(h.opts.Name, "%v", err)
}
}
return nil
}

func (h *handler) Version(ctx context.Context, req *codec.Frame, rsp *codec.Frame) error {
rsp.Data = []byte(h.opts.Version)
return nil
}
62 changes: 62 additions & 0 deletions server/health/health.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
syntax = "proto3";

package health;
option go_package = "github.com/unistack-org/micro/v3/server/health;pb";

import "api/annotations.proto";
import "openapiv2/annotations.proto";
import "codec/frame.proto";

service Health {
rpc Live(micro.codec.Frame) returns (micro.codec.Frame) {
option (micro.openapiv2.openapiv2_operation) = {
operation_id: "Live";
responses: {
key: "default";
value: {
description: "Error response";
schema: {
json_schema: {
ref: "micro.codec.Frame";
}
}
}
}
};
option (micro.api.http) = { get: "/live"; };
};
rpc Ready(micro.codec.Frame) returns (micro.codec.Frame) {
option (micro.openapiv2.openapiv2_operation) = {
operation_id: "Ready";
responses: {
key: "default";
value: {
description: "Error response";
schema: {
json_schema: {
ref: "micro.codec.Frame";
}
}
}
}
};
option (micro.api.http) = { get: "/ready"; };
};
rpc Version(micro.codec.Frame) returns (micro.codec.Frame) {
option (micro.openapiv2.openapiv2_operation) = {
operation_id: "Version";
responses: {
key: "default";
value: {
description: "Error response";
schema: {
json_schema: {
ref: "micro.codec.Frame";
}
}
}
}
};
option (micro.api.http) = { get: "/version"; };
};
};
38 changes: 38 additions & 0 deletions server/health/health_micro.pb.go

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

43 changes: 43 additions & 0 deletions server/health/health_micro_http.pb.go

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