supervisor: implement monitoring

Signed-off-by: Kenfe-Mickael Laventure <mickael.laventure@gmail.com>
This commit is contained in:
Kenfe-Mickael Laventure 2017-02-06 14:57:43 -08:00
parent 31f26fed18
commit 78d7e8b256
13 changed files with 1311 additions and 276 deletions

View file

@ -122,8 +122,7 @@ func (*CreateContainerResponse) ProtoMessage() {}
func (*CreateContainerResponse) Descriptor() ([]byte, []int) { return fileDescriptorExecution, []int{2} } func (*CreateContainerResponse) Descriptor() ([]byte, []int) { return fileDescriptorExecution, []int{2} }
type DeleteContainerRequest struct { type DeleteContainerRequest struct {
ID string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"` ID string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"`
Pid uint32 `protobuf:"varint,2,opt,name=pid,proto3" json:"pid,omitempty"`
} }
func (m *DeleteContainerRequest) Reset() { *m = DeleteContainerRequest{} } func (m *DeleteContainerRequest) Reset() { *m = DeleteContainerRequest{} }
@ -363,10 +362,9 @@ func (this *DeleteContainerRequest) GoString() string {
if this == nil { if this == nil {
return "nil" return "nil"
} }
s := make([]string, 0, 6) s := make([]string, 0, 5)
s = append(s, "&execution.DeleteContainerRequest{") s = append(s, "&execution.DeleteContainerRequest{")
s = append(s, "ID: "+fmt.Sprintf("%#v", this.ID)+",\n") s = append(s, "ID: "+fmt.Sprintf("%#v", this.ID)+",\n")
s = append(s, "Pid: "+fmt.Sprintf("%#v", this.Pid)+",\n")
s = append(s, "}") s = append(s, "}")
return strings.Join(s, "") return strings.Join(s, "")
} }
@ -1220,11 +1218,6 @@ func (m *DeleteContainerRequest) MarshalTo(dAtA []byte) (int, error) {
i = encodeVarintExecution(dAtA, i, uint64(len(m.ID))) i = encodeVarintExecution(dAtA, i, uint64(len(m.ID)))
i += copy(dAtA[i:], m.ID) i += copy(dAtA[i:], m.ID)
} }
if m.Pid != 0 {
dAtA[i] = 0x10
i++
i = encodeVarintExecution(dAtA, i, uint64(m.Pid))
}
return i, nil return i, nil
} }
@ -1936,9 +1929,6 @@ func (m *DeleteContainerRequest) Size() (n int) {
if l > 0 { if l > 0 {
n += 1 + l + sovExecution(uint64(l)) n += 1 + l + sovExecution(uint64(l))
} }
if m.Pid != 0 {
n += 1 + sovExecution(uint64(m.Pid))
}
return n return n
} }
@ -2259,7 +2249,6 @@ func (this *DeleteContainerRequest) String() string {
} }
s := strings.Join([]string{`&DeleteContainerRequest{`, s := strings.Join([]string{`&DeleteContainerRequest{`,
`ID:` + fmt.Sprintf("%v", this.ID) + `,`, `ID:` + fmt.Sprintf("%v", this.ID) + `,`,
`Pid:` + fmt.Sprintf("%v", this.Pid) + `,`,
`}`, `}`,
}, "") }, "")
return s return s
@ -2940,25 +2929,6 @@ func (m *DeleteContainerRequest) Unmarshal(dAtA []byte) error {
} }
m.ID = string(dAtA[iNdEx:postIndex]) m.ID = string(dAtA[iNdEx:postIndex])
iNdEx = postIndex iNdEx = postIndex
case 2:
if wireType != 0 {
return fmt.Errorf("proto: wrong wireType = %d for field Pid", wireType)
}
m.Pid = 0
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowExecution
}
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
m.Pid |= (uint32(b) & 0x7F) << shift
if b < 0x80 {
break
}
}
default: default:
iNdEx = preIndex iNdEx = preIndex
skippy, err := skipExecution(dAtA[iNdEx:]) skippy, err := skipExecution(dAtA[iNdEx:])
@ -5039,68 +5009,68 @@ var (
func init() { proto.RegisterFile("execution.proto", fileDescriptorExecution) } func init() { proto.RegisterFile("execution.proto", fileDescriptorExecution) }
var fileDescriptorExecution = []byte{ var fileDescriptorExecution = []byte{
// 998 bytes of a gzipped FileDescriptorProto // 996 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x09, 0x6e, 0x88, 0x02, 0xff, 0xb4, 0x56, 0xcf, 0x6f, 0xe3, 0x44, 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x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, 0xc0, 0xa5, 0x59, 0xe2, 0x42, 0xb6, 0x6f, 0xa0, 0x18, 0x31, 0xa6, 0x04, 0x5b, 0x9a, 0x05, 0x56, 0xef,
0xfa, 0x9d, 0xc5, 0xa0, 0x20, 0xef, 0xc3, 0xb7, 0x5f, 0x5c, 0x35, 0x56, 0xfe, 0xbc, 0x6a, 0xac, 0x2c, 0x07, 0x05, 0x79, 0x3f, 0x7a, 0xfb, 0xc5, 0x75, 0x6d, 0xed, 0xcf, 0xeb, 0xda, 0xda, 0xbf,
0xfc, 0x7b, 0xd5, 0x50, 0x7e, 0x99, 0x34, 0x94, 0x17, 0x93, 0x86, 0xf2, 0xc7, 0xa4, 0xa1, 0xfc, 0xd7, 0x35, 0xed, 0x97, 0x49, 0x4d, 0x7b, 0x31, 0xa9, 0x69, 0x7f, 0x4c, 0x6a, 0xda, 0xdf, 0x93,
0x3d, 0x69, 0x28, 0xe7, 0x05, 0xa1, 0xe4, 0xc3, 0xff, 0x02, 0x00, 0x00, 0xff, 0xff, 0x24, 0xc6, 0x9a, 0x76, 0x99, 0x93, 0x4a, 0x3e, 0xfc, 0x2f, 0x00, 0x00, 0xff, 0xff, 0xf5, 0x7a, 0x45, 0x38,
0xc8, 0x88, 0x60, 0x0d, 0x00, 0x00, 0x4e, 0x0d, 0x00, 0x00,
} }

View file

@ -43,7 +43,6 @@ message CreateContainerResponse {
message DeleteContainerRequest { message DeleteContainerRequest {
string id = 1 [(gogoproto.customname) = "ID"]; string id = 1 [(gogoproto.customname) = "ID"];
uint32 pid = 2;
} }
message ListContainersRequest { message ListContainersRequest {

View file

@ -249,7 +249,8 @@ func (*StateRequest) Descriptor() ([]byte, []int) { return fileDescriptorShim, [
type StateResponse struct { type StateResponse struct {
ID string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"` ID string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"`
Bundle string `protobuf:"bytes,2,opt,name=bundle,proto3" json:"bundle,omitempty"` Bundle string `protobuf:"bytes,2,opt,name=bundle,proto3" json:"bundle,omitempty"`
Processes []*Process `protobuf:"bytes,3,rep,name=processes" json:"processes,omitempty"` InitPid uint32 `protobuf:"varint,3,opt,name=initPid,proto3" json:"initPid,omitempty"`
Processes []*Process `protobuf:"bytes,4,rep,name=processes" json:"processes,omitempty"`
} }
func (m *StateResponse) Reset() { *m = StateResponse{} } func (m *StateResponse) Reset() { *m = StateResponse{} }
@ -463,10 +464,11 @@ func (this *StateResponse) GoString() string {
if this == nil { if this == nil {
return "nil" return "nil"
} }
s := make([]string, 0, 7) s := make([]string, 0, 8)
s = append(s, "&shim.StateResponse{") s = append(s, "&shim.StateResponse{")
s = append(s, "ID: "+fmt.Sprintf("%#v", this.ID)+",\n") s = append(s, "ID: "+fmt.Sprintf("%#v", this.ID)+",\n")
s = append(s, "Bundle: "+fmt.Sprintf("%#v", this.Bundle)+",\n") s = append(s, "Bundle: "+fmt.Sprintf("%#v", this.Bundle)+",\n")
s = append(s, "InitPid: "+fmt.Sprintf("%#v", this.InitPid)+",\n")
if this.Processes != nil { if this.Processes != nil {
s = append(s, "Processes: "+fmt.Sprintf("%#v", this.Processes)+",\n") s = append(s, "Processes: "+fmt.Sprintf("%#v", this.Processes)+",\n")
} }
@ -1432,9 +1434,14 @@ func (m *StateResponse) MarshalTo(dAtA []byte) (int, error) {
i = encodeVarintShim(dAtA, i, uint64(len(m.Bundle))) i = encodeVarintShim(dAtA, i, uint64(len(m.Bundle)))
i += copy(dAtA[i:], m.Bundle) i += copy(dAtA[i:], m.Bundle)
} }
if m.InitPid != 0 {
dAtA[i] = 0x18
i++
i = encodeVarintShim(dAtA, i, uint64(m.InitPid))
}
if len(m.Processes) > 0 { if len(m.Processes) > 0 {
for _, msg := range m.Processes { for _, msg := range m.Processes {
dAtA[i] = 0x1a dAtA[i] = 0x22
i++ i++
i = encodeVarintShim(dAtA, i, uint64(msg.Size())) i = encodeVarintShim(dAtA, i, uint64(msg.Size()))
n, err := msg.MarshalTo(dAtA[i:]) n, err := msg.MarshalTo(dAtA[i:])
@ -1772,6 +1779,9 @@ func (m *StateResponse) Size() (n int) {
if l > 0 { if l > 0 {
n += 1 + l + sovShim(uint64(l)) n += 1 + l + sovShim(uint64(l))
} }
if m.InitPid != 0 {
n += 1 + sovShim(uint64(m.InitPid))
}
if len(m.Processes) > 0 { if len(m.Processes) > 0 {
for _, e := range m.Processes { for _, e := range m.Processes {
l = e.Size() l = e.Size()
@ -1980,6 +1990,7 @@ func (this *StateResponse) String() string {
s := strings.Join([]string{`&StateResponse{`, s := strings.Join([]string{`&StateResponse{`,
`ID:` + fmt.Sprintf("%v", this.ID) + `,`, `ID:` + fmt.Sprintf("%v", this.ID) + `,`,
`Bundle:` + fmt.Sprintf("%v", this.Bundle) + `,`, `Bundle:` + fmt.Sprintf("%v", this.Bundle) + `,`,
`InitPid:` + fmt.Sprintf("%v", this.InitPid) + `,`,
`Processes:` + strings.Replace(fmt.Sprintf("%v", this.Processes), "Process", "Process", 1) + `,`, `Processes:` + strings.Replace(fmt.Sprintf("%v", this.Processes), "Process", "Process", 1) + `,`,
`}`, `}`,
}, "") }, "")
@ -3725,6 +3736,25 @@ func (m *StateResponse) Unmarshal(dAtA []byte) error {
m.Bundle = string(dAtA[iNdEx:postIndex]) m.Bundle = string(dAtA[iNdEx:postIndex])
iNdEx = postIndex iNdEx = postIndex
case 3: case 3:
if wireType != 0 {
return fmt.Errorf("proto: wrong wireType = %d for field InitPid", wireType)
}
m.InitPid = 0
for shift := uint(0); ; shift += 7 {
if shift >= 64 {
return ErrIntOverflowShim
}
if iNdEx >= l {
return io.ErrUnexpectedEOF
}
b := dAtA[iNdEx]
iNdEx++
m.InitPid |= (uint32(b) & 0x7F) << shift
if b < 0x80 {
break
}
}
case 4:
if wireType != 2 { if wireType != 2 {
return fmt.Errorf("proto: wrong wireType = %d for field Processes", wireType) return fmt.Errorf("proto: wrong wireType = %d for field Processes", wireType)
} }
@ -4072,69 +4102,70 @@ var (
func init() { proto.RegisterFile("shim.proto", fileDescriptorShim) } func init() { proto.RegisterFile("shim.proto", fileDescriptorShim) }
var fileDescriptorShim = []byte{ var fileDescriptorShim = []byte{
// 1018 bytes of a gzipped FileDescriptorProto // 1027 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x09, 0x6e, 0x88, 0x02, 0xff, 0x94, 0x55, 0xcf, 0x6e, 0xe3, 0xb6, 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x09, 0x6e, 0x88, 0x02, 0xff, 0x9c, 0x55, 0xcf, 0x6e, 0xe3, 0xb6,
0x13, 0x8e, 0x2c, 0xf9, 0xdf, 0x38, 0x72, 0xfc, 0x23, 0x16, 0x81, 0xe2, 0xfd, 0xd5, 0x71, 0xd4, 0x13, 0x8e, 0x2c, 0xf9, 0xdf, 0x38, 0x76, 0xfc, 0x23, 0x16, 0x81, 0xe2, 0xfd, 0xd5, 0x71, 0xd4,
0x43, 0xd3, 0xa0, 0x70, 0x9a, 0xb4, 0x97, 0x16, 0xe8, 0x21, 0x1b, 0x0b, 0xdb, 0x00, 0x69, 0x62, 0x43, 0xd3, 0xa0, 0x70, 0x9a, 0xb4, 0x97, 0x16, 0xe8, 0x21, 0x1b, 0x0b, 0xdb, 0x00, 0x69, 0x22,
0xd0, 0x0e, 0xb0, 0x37, 0x43, 0x89, 0x18, 0x9b, 0x80, 0x2c, 0xa9, 0x24, 0x95, 0x3f, 0x3d, 0xf5, 0xd0, 0x0e, 0xb0, 0x37, 0x43, 0x89, 0x18, 0x9b, 0x80, 0x2c, 0xa9, 0x24, 0x95, 0x3f, 0xb7, 0x5e,
0xd2, 0x47, 0xe8, 0x53, 0xf4, 0x45, 0xf6, 0xd8, 0x53, 0xd1, 0x53, 0xd1, 0xe4, 0x09, 0xfa, 0x08, 0xfa, 0x06, 0xed, 0x53, 0xf4, 0x45, 0xf6, 0xd8, 0x53, 0xd1, 0x53, 0xd1, 0xe4, 0x09, 0xfa, 0x08,
0x05, 0x49,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 0x9f, 0x1e, 0xfb, 0xc6, 0xfb, 0xc7, 0xbe, 0xf1, 0xfb, 0x63, 0xdf, 0xf8, 0xfb, 0xb1, 0x6f,
0xff, 0xff, 0x62, 0xce, 0xef, 0x76, 0x44, 0x09, 0x00, 0x00, 0x5c, 0xd6, 0x14, 0xfb, 0xab, 0x7f, 0x03, 0x00, 0x00, 0xff, 0xff, 0xcb, 0x48, 0xee, 0xf6, 0x5f,
0x09, 0x00, 0x00,
} }

View file

@ -105,7 +105,8 @@ message StateRequest {
message StateResponse { message StateResponse {
string id = 1 [(gogoproto.customname) = "ID"]; string id = 1 [(gogoproto.customname) = "ID"];
string bundle = 2; string bundle = 2;
repeated Process processes = 3; uint32 initPid = 3;
repeated Process processes = 4;
} }
// TODO: share core runtime types between shim and execution rpcs // TODO: share core runtime types between shim and execution rpcs

View file

@ -25,8 +25,10 @@ import (
"github.com/docker/containerd/supervisor" "github.com/docker/containerd/supervisor"
"github.com/docker/containerd/utils" "github.com/docker/containerd/utils"
metrics "github.com/docker/go-metrics" metrics "github.com/docker/go-metrics"
"github.com/pkg/errors"
"github.com/urfave/cli" "github.com/urfave/cli"
natsd "github.com/nats-io/gnatsd/server"
"github.com/nats-io/go-nats" "github.com/nats-io/go-nats"
stand "github.com/nats-io/nats-streaming-server/server" stand "github.com/nats-io/nats-streaming-server/server"
) )
@ -41,6 +43,11 @@ const usage = `
high performance container runtime high performance container runtime
` `
const (
StanClusterID = "containerd"
stanClientID = "containerd"
)
func main() { func main() {
app := cli.NewApp() app := cli.NewApp()
app.Name = "containerd" app.Name = "containerd"
@ -126,14 +133,12 @@ func main() {
} }
// Get events publisher // Get events publisher
nec, err := getNATSPublisher(ea) natsPoster, err := events.NewNATSPoster(StanClusterID, stanClientID)
if err != nil { if err != nil {
return err return err
} }
defer nec.Close()
execCtx := log.WithModule(ctx, "execution") execCtx := log.WithModule(ctx, "execution")
execCtx = events.WithPoster(execCtx, events.GetNATSPoster(nec)) execCtx = events.WithPoster(execCtx, natsPoster)
execService, err := supervisor.New(execCtx, context.GlobalString("root")) execService, err := supervisor.New(execCtx, context.GlobalString("root"))
if err != nil { if err != nil {
return err return err
@ -145,7 +150,7 @@ func main() {
switch info.Server.(type) { switch info.Server.(type) {
case api.ExecutionServiceServer: case api.ExecutionServiceServer:
ctx = log.WithModule(ctx, "execution") ctx = log.WithModule(ctx, "execution")
ctx = events.WithPoster(ctx, events.GetNATSPoster(nec)) ctx = events.WithPoster(ctx, natsPoster)
default: default:
fmt.Printf("Unknown type: %#v\n", info.Server) fmt.Printf("Unknown type: %#v\n", info.Server)
} }
@ -211,25 +216,10 @@ func dumpStacks(ctx gocontext.Context) {
log.G(ctx).Infof("=== BEGIN goroutine stack dump ===\n%s\n=== END goroutine stack dump ===", buf) log.G(ctx).Infof("=== BEGIN goroutine stack dump ===\n%s\n=== END goroutine stack dump ===", buf)
} }
func startNATSServer(eventsAddress string) (e *stand.StanServer, err error) { func startNATSServer(address string) (s *stand.StanServer, err error) {
eventsURL, err := url.Parse(eventsAddress)
if err != nil {
return nil, err
}
no := stand.DefaultNatsServerOptions
nOpts := &no
nOpts.NoSigs = true
parts := strings.Split(eventsURL.Host, ":")
nOpts.Host = parts[0]
if len(parts) == 2 {
nOpts.Port, err = strconv.Atoi(parts[1])
} else {
nOpts.Port = nats.DefaultPort
}
defer func() { defer func() {
if r := recover(); r != nil { if r := recover(); r != nil {
e = nil s = nil
if _, ok := r.(error); !ok { if _, ok := r.(error); !ok {
err = fmt.Errorf("failed to start NATS server: %v", r) err = fmt.Errorf("failed to start NATS server: %v", r)
} else { } else {
@ -237,21 +227,32 @@ func startNATSServer(eventsAddress string) (e *stand.StanServer, err error) {
} }
} }
}() }()
s := stand.RunServerWithOpts(nil, nOpts) so, no, err := getServerOptions(address)
return s, nil
}
func getNATSPublisher(eventsAddress string) (*nats.EncodedConn, error) {
nc, err := nats.Connect(eventsAddress)
if err != nil { if err != nil {
return nil, err return nil, err
} }
nec, err := nats.NewEncodedConn(nc, nats.JSON_ENCODER) s = stand.RunServerWithOpts(so, no)
return s, err
}
func getServerOptions(address string) (*stand.Options, *natsd.Options, error) {
url, err := url.Parse(address)
if err != nil { if err != nil {
nc.Close() return nil, nil, errors.Wrapf(err, "failed to parse address url %q", address)
return nil, err
} }
return nec, nil no := stand.DefaultNatsServerOptions
parts := strings.Split(url.Host, ":")
if len(parts) == 2 {
no.Port, err = strconv.Atoi(parts[1])
} else {
no.Port = nats.DefaultPort
}
no.Host = parts[0]
so := stand.GetDefaultOptions()
so.ID = StanClusterID
return so, &no, nil
} }

View file

@ -1,6 +1,7 @@
package main package main
import ( import (
"encoding/json"
"fmt" "fmt"
"os" "os"
"path/filepath" "path/filepath"
@ -8,10 +9,12 @@ import (
gocontext "context" gocontext "context"
"github.com/crosbymichael/console"
"github.com/docker/containerd/api/execution" "github.com/docker/containerd/api/execution"
execEvents "github.com/docker/containerd/execution" execEvents "github.com/docker/containerd/execution"
"github.com/docker/docker/pkg/term"
"github.com/nats-io/go-nats" "github.com/nats-io/go-nats"
"github.com/nats-io/go-nats-streaming"
"github.com/pkg/errors"
"github.com/urfave/cli" "github.com/urfave/cli"
) )
@ -39,20 +42,23 @@ var runCommand = cli.Command{
} }
// setup our event subscriber // setup our event subscriber
nc, err := nats.Connect(nats.DefaultURL) sc, err := stan.Connect("containerd", "ctr", stan.ConnectWait(5*time.Second))
if err != nil { if err != nil {
return err return err
} }
nec, err := nats.NewEncodedConn(nc, nats.JSON_ENCODER) defer sc.Close()
if err != nil {
nc.Close()
return err
}
defer nec.Close()
evCh := make(chan *execEvents.ContainerEvent, 64) evCh := make(chan *execEvents.ContainerEvent, 64)
sub, err := nec.Subscribe(execEvents.ContainersEventsSubjectSubscriber, func(e *execEvents.ContainerEvent) { sub, err := sc.Subscribe(fmt.Sprintf("containers.%s", id), func(m *stan.Msg) {
evCh <- e var e execEvents.ContainerEvent
err := json.Unmarshal(m.Data, &e)
if err != nil {
fmt.Printf("failed to unmarshal event: %v", err)
return
}
evCh <- &e
}) })
if err != nil { if err != nil {
return err return err
@ -78,19 +84,12 @@ var runCommand = cli.Command{
Stderr: filepath.Join(tmpDir, "stderr"), Stderr: filepath.Join(tmpDir, "stderr"),
} }
var oldState *term.State
restoreTerm := func() {
if oldState != nil {
term.RestoreTerminal(os.Stdin.Fd(), oldState)
}
}
if crOpts.Console { if crOpts.Console {
oldState, err = term.SetRawTerminal(os.Stdin.Fd()) con := console.Current()
if err != nil { defer con.Reset()
if err := con.SetRaw(); err != nil {
return err return err
} }
defer restoreTerm()
} }
fwg, err := prepareStdio(crOpts.Stdin, crOpts.Stdout, crOpts.Stderr, crOpts.Console) fwg, err := prepareStdio(crOpts.Stdin, crOpts.Stdout, crOpts.Stderr, crOpts.Console)
@ -100,13 +99,13 @@ var runCommand = cli.Command{
cr, err := executionService.CreateContainer(gocontext.Background(), crOpts) cr, err := executionService.CreateContainer(gocontext.Background(), crOpts)
if err != nil { if err != nil {
return err return errors.Wrap(err, "CreateContainer RPC failed")
} }
if _, err := executionService.StartContainer(gocontext.Background(), &execution.StartContainerRequest{ if _, err := executionService.StartContainer(gocontext.Background(), &execution.StartContainerRequest{
ID: cr.Container.ID, ID: cr.Container.ID,
}); err != nil { }); err != nil {
return err return errors.Wrap(err, "StartContainer RPC failed")
} }
var ec uint32 var ec uint32
@ -123,7 +122,7 @@ var runCommand = cli.Command{
break eventLoop break eventLoop
} }
case <-time.After(1 * time.Second): case <-time.After(1 * time.Second):
if nec.Conn.Status() != nats.CONNECTED { if sc.NatsConn().Status() != nats.CONNECTED {
break eventLoop break eventLoop
} }
} }
@ -132,14 +131,15 @@ var runCommand = cli.Command{
if _, err := executionService.DeleteContainer(gocontext.Background(), &execution.DeleteContainerRequest{ if _, err := executionService.DeleteContainer(gocontext.Background(), &execution.DeleteContainerRequest{
ID: cr.Container.ID, ID: cr.Container.ID,
}); err != nil { }); err != nil {
return err return errors.Wrap(err, "DeleteContainer RPC failed")
} }
// Ensure we read all io // Ensure we read all io
fwg.Wait() fwg.Wait()
restoreTerm() if ec != 0 {
os.Exit(int(ec)) return cli.NewExitError("", int(ec))
}
return nil return nil
}, },

View file

@ -14,8 +14,8 @@ import (
gocontext "context" gocontext "context"
"github.com/Sirupsen/logrus"
"github.com/docker/containerd/api/execution" "github.com/docker/containerd/api/execution"
"github.com/pkg/errors"
"github.com/tonistiigi/fifo" "github.com/tonistiigi/fifo"
"github.com/urfave/cli" "github.com/urfave/cli"
"google.golang.org/grpc" "google.golang.org/grpc"
@ -39,7 +39,6 @@ func prepareStdio(stdin, stdout, stderr string, console bool) (*sync.WaitGroup,
}(f) }(f)
go func(w io.WriteCloser) { go func(w io.WriteCloser) {
io.Copy(w, os.Stdin) io.Copy(w, os.Stdin)
logrus.Info("stdin copy finished")
w.Close() w.Close()
}(f) }(f)
@ -56,7 +55,6 @@ func prepareStdio(stdin, stdout, stderr string, console bool) (*sync.WaitGroup,
go func(r io.ReadCloser) { go func(r io.ReadCloser) {
io.Copy(os.Stdout, r) io.Copy(os.Stdout, r)
r.Close() r.Close()
logrus.Info("stdout copy finished")
wg.Done() wg.Done()
}(f) }(f)
@ -74,7 +72,6 @@ func prepareStdio(stdin, stdout, stderr string, console bool) (*sync.WaitGroup,
go func(r io.ReadCloser) { go func(r io.ReadCloser) {
io.Copy(os.Stderr, r) io.Copy(os.Stderr, r)
r.Close() r.Close()
logrus.Info("stderr copy finished")
wg.Done() wg.Done()
}(f) }(f)
} }
@ -99,7 +96,7 @@ func getGRPCConnection(context *cli.Context) (*grpc.ClientConn, error) {
conn, err := grpc.Dial(fmt.Sprintf("unix://%s", bindSocket), dialOpts...) conn, err := grpc.Dial(fmt.Sprintf("unix://%s", bindSocket), dialOpts...)
if err != nil { if err != nil {
return nil, err return nil, errors.Wrapf(err, "failed to dial %q", bindSocket)
} }
grpcConn = conn grpcConn = conn

View file

@ -2,30 +2,48 @@ package events
import ( import (
"context" "context"
"strings" "encoding/json"
"time"
"github.com/Sirupsen/logrus"
"github.com/docker/containerd/log" "github.com/docker/containerd/log"
nats "github.com/nats-io/go-nats" "github.com/nats-io/go-nats-streaming"
"github.com/pkg/errors"
) )
type natsPoster struct { type natsPoster struct {
nec *nats.EncodedConn sc stan.Conn
} }
func GetNATSPoster(nec *nats.EncodedConn) Poster { func NewNATSPoster(clusterID, clientID string) (Poster, error) {
return &natsPoster{nec} sc, err := stan.Connect(clusterID, clientID, stan.ConnectWait(5*time.Second))
if err != nil {
return nil, errors.Wrap(err, "failed to connect to nats streaming server")
}
return &natsPoster{sc}, nil
} }
func (p *natsPoster) Post(ctx context.Context, e Event) { func (p *natsPoster) Post(ctx context.Context, e Event) {
subject := strings.Replace(log.GetModulePath(ctx), "/", ".", -1)
topic := getTopic(ctx) topic := getTopic(ctx)
if topic != "" { if topic == "" {
subject = strings.Join([]string{subject, topic}, ".") log.G(ctx).WithField("event", e).Warn("unable to post event, topic is empty")
return
} }
if subject == "" { data, err := json.Marshal(e)
log.GetLogger(ctx).WithField("event", e).Warn("unable to post event, subject is empty") if err != nil {
log.G(ctx).WithError(err).WithFields(logrus.Fields{"event": e, "topic": topic}).
Warn("unable to marshal event")
return
} }
p.nec.Publish(subject, e) err = p.sc.Publish(topic, data)
if err != nil {
log.G(ctx).WithError(err).WithFields(logrus.Fields{"event": e, "topic": topic}).
Warn("unable to post event")
}
log.G(ctx).WithFields(logrus.Fields{"event": e, "topic": topic}).
Debug("Posted event")
} }

View file

@ -1,7 +1,6 @@
package shim package shim
import ( import (
"fmt"
"sync" "sync"
"syscall" "syscall"
@ -9,6 +8,7 @@ import (
apishim "github.com/docker/containerd/api/shim" apishim "github.com/docker/containerd/api/shim"
"github.com/docker/containerd/utils" "github.com/docker/containerd/utils"
google_protobuf "github.com/golang/protobuf/ptypes/empty" google_protobuf "github.com/golang/protobuf/ptypes/empty"
"github.com/pkg/errors"
"golang.org/x/net/context" "golang.org/x/net/context"
) )
@ -25,6 +25,7 @@ func New() *Service {
type Service struct { type Service struct {
initProcess *initProcess initProcess *initProcess
id string id string
bundle string
mu sync.Mutex mu sync.Mutex
processes map[int]process processes map[int]process
events chan *apishim.Event events chan *apishim.Event
@ -37,10 +38,11 @@ func (s *Service) Create(ctx context.Context, r *apishim.CreateRequest) (*apishi
return nil, err return nil, err
} }
s.mu.Lock() s.mu.Lock()
s.id = r.ID
s.bundle = r.Bundle
s.initProcess = process s.initProcess = process
pid := process.Pid() pid := process.Pid()
s.processes[pid] = process s.processes[pid] = process
s.id = r.ID
s.mu.Unlock() s.mu.Unlock()
s.events <- &apishim.Event{ s.events <- &apishim.Event{
Type: apishim.EventType_CREATE, Type: apishim.EventType_CREATE,
@ -69,7 +71,7 @@ func (s *Service) Delete(ctx context.Context, r *apishim.DeleteRequest) (*apishi
p, ok := s.processes[int(r.Pid)] p, ok := s.processes[int(r.Pid)]
s.mu.Unlock() s.mu.Unlock()
if !ok { if !ok {
return nil, fmt.Errorf("process does not exist %d", r.Pid) return nil, errors.Errorf("process does not exist %d", r.Pid)
} }
if err := p.Delete(ctx); err != nil { if err := p.Delete(ctx); err != nil {
return nil, err return nil, err
@ -104,7 +106,7 @@ func (s *Service) Exec(ctx context.Context, r *apishim.ExecRequest) (*apishim.Ex
func (s *Service) Pty(ctx context.Context, r *apishim.PtyRequest) (*google_protobuf.Empty, error) { func (s *Service) Pty(ctx context.Context, r *apishim.PtyRequest) (*google_protobuf.Empty, error) {
if r.Pid == 0 { if r.Pid == 0 {
return nil, fmt.Errorf("pid not provided in request") return nil, errors.Errorf("pid not provided in request")
} }
ws := console.WinSize{ ws := console.WinSize{
Width: uint16(r.Width), Width: uint16(r.Width),
@ -114,7 +116,7 @@ func (s *Service) Pty(ctx context.Context, r *apishim.PtyRequest) (*google_proto
p, ok := s.processes[int(r.Pid)] p, ok := s.processes[int(r.Pid)]
s.mu.Unlock() s.mu.Unlock()
if !ok { if !ok {
return nil, fmt.Errorf("process does not exist %d", r.Pid) return nil, errors.Errorf("process does not exist %d", r.Pid)
} }
if err := p.Resize(ws); err != nil { if err := p.Resize(ws); err != nil {
return nil, err return nil, err
@ -134,6 +136,8 @@ func (s *Service) Events(r *apishim.EventsRequest, stream apishim.Shim_EventsSer
func (s *Service) State(ctx context.Context, r *apishim.StateRequest) (*apishim.StateResponse, error) { func (s *Service) State(ctx context.Context, r *apishim.StateRequest) (*apishim.StateResponse, error) {
o := &apishim.StateResponse{ o := &apishim.StateResponse{
ID: s.id, ID: s.id,
Bundle: s.bundle,
InitPid: uint32(s.initProcess.Pid()),
Processes: []*apishim.Process{}, Processes: []*apishim.Process{},
} }
s.mu.Lock() s.mu.Lock()

View file

@ -3,12 +3,19 @@ package supervisor
import ( import (
"fmt" "fmt"
"io/ioutil" "io/ioutil"
"os"
"path/filepath" "path/filepath"
"strings"
"sync" "sync"
"time"
api "github.com/docker/containerd/api/execution" api "github.com/docker/containerd/api/execution"
"github.com/docker/containerd/api/shim" "github.com/docker/containerd/api/shim"
"github.com/docker/containerd/events"
"github.com/docker/containerd/execution"
"github.com/docker/containerd/log"
google_protobuf "github.com/golang/protobuf/ptypes/empty" google_protobuf "github.com/golang/protobuf/ptypes/empty"
"github.com/pkg/errors"
"golang.org/x/net/context" "golang.org/x/net/context"
) )
@ -19,16 +26,22 @@ var (
// New creates a new GRPC services for execution // New creates a new GRPC services for execution
func New(ctx context.Context, root string) (*Service, error) { func New(ctx context.Context, root string) (*Service, error) {
clients, err := loadClients(root) ctx = log.WithModule(ctx, "supervisor")
log.G(ctx).WithField("root", root).Debugf("New()")
if err := os.MkdirAll(root, 0700); err != nil {
return nil, errors.Wrapf(err, "unable to create root directory %q", root)
}
clients, err := loadClients(ctx, root)
if err != nil { if err != nil {
return nil, err return nil, err
} }
s := &Service{ s := &Service{
root: root, root: root,
shims: clients, shims: clients,
ctx: ctx,
} }
for _, c := range clients { for _, c := range clients {
if err := s.monitor(c); err != nil { if err := s.monitor(events.GetPoster(ctx), c); err != nil {
return nil, err return nil, err
} }
} }
@ -38,24 +51,23 @@ func New(ctx context.Context, root string) (*Service, error) {
type Service struct { type Service struct {
mu sync.Mutex mu sync.Mutex
ctx context.Context
root string root string
shims map[string]shim.ShimClient shims map[string]*shimClient
} }
func (s *Service) CreateContainer(ctx context.Context, r *api.CreateContainerRequest) (*api.CreateContainerResponse, error) { func (s *Service) CreateContainer(ctx context.Context, r *api.CreateContainerRequest) (*api.CreateContainerResponse, error) {
s.mu.Lock() client, err := s.newShim(r.ID)
if _, ok := s.shims[r.ID]; ok {
s.mu.Unlock()
return nil, fmt.Errorf("container already exists %q", r.ID)
}
client, err := newShimClient(filepath.Join(s.root, r.ID))
if err != nil { if err != nil {
s.mu.Unlock()
return nil, err return nil, err
} }
s.shims[r.ID] = client defer func() {
s.mu.Unlock() if err != nil {
if err := s.monitor(client); err != nil { s.removeShim(r.ID)
}
}()
if err := s.monitor(events.GetPoster(ctx), client); err != nil {
return nil, err return nil, err
} }
createResponse, err := client.Create(ctx, &shim.CreateRequest{ createResponse, err := client.Create(ctx, &shim.CreateRequest{
@ -67,8 +79,9 @@ func (s *Service) CreateContainer(ctx context.Context, r *api.CreateContainerReq
Stderr: r.Stderr, Stderr: r.Stderr,
}) })
if err != nil { if err != nil {
return nil, err return nil, errors.Wrapf(err, "shim create request failed")
} }
client.initPid = createResponse.Pid
return &api.CreateContainerResponse{ return &api.CreateContainerResponse{
Container: &api.Container{ Container: &api.Container{
ID: r.ID, ID: r.ID,
@ -96,11 +109,12 @@ func (s *Service) DeleteContainer(ctx context.Context, r *api.DeleteContainerReq
return nil, err return nil, err
} }
_, err = client.Delete(ctx, &shim.DeleteRequest{ _, err = client.Delete(ctx, &shim.DeleteRequest{
Pid: r.Pid, Pid: client.initPid,
}) })
if err != nil { if err != nil {
return nil, err return nil, err
} }
s.removeShim(r.ID)
return empty, nil return empty, nil
} }
@ -180,13 +194,65 @@ func (s *Service) ListProcesses(ctx context.Context, r *api.ListProcessesRequest
// monitor monitors the shim's event rpc and forwards container and process // monitor monitors the shim's event rpc and forwards container and process
// events to callers // events to callers
func (s *Service) monitor(client shim.ShimClient) error { func (s *Service) monitor(poster events.Poster, client *shimClient) error {
// we use the service context here because we don't want to be
// tied to the Create rpc call
stream, err := client.Events(s.ctx, &shim.EventsRequest{})
if err != nil {
return errors.Wrapf(err, "failed to get events stream for client at %q", client.root)
}
go func() {
for {
e, err := stream.Recv()
if err != nil {
if err.Error() == "EOF" || strings.Contains(err.Error(), "transport is closing") {
break
}
log.G(s.ctx).WithError(err).WithField("container", client.id).
Warnf("event stream for client at %q got terminated", client.root)
break
}
var topic string
if e.Type == shim.EventType_CREATE {
topic = "containers"
} else {
topic = fmt.Sprintf("containers.%s", e.ID)
}
ctx := events.WithTopic(s.ctx, topic)
poster.Post(ctx, execution.ContainerEvent{
Timestamp: time.Now(),
ID: e.ID,
Type: toExecutionEventType(e.Type),
Pid: e.Pid,
ExitStatus: e.ExitStatus,
})
}
}()
return nil return nil
} }
func (s *Service) getShim(id string) (shim.ShimClient, error) { func (s *Service) newShim(id string) (*shimClient, error) {
s.mu.Lock() s.mu.Lock()
defer s.mu.Unlock() defer s.mu.Unlock()
if _, ok := s.shims[id]; ok {
return nil, errors.Errorf("container %q already exists", id)
}
client, err := newShimClient(filepath.Join(s.root, id), id)
if err != nil {
return nil, err
}
s.shims[id] = client
return client, nil
}
func (s *Service) getShim(id string) (*shimClient, error) {
s.mu.Lock()
defer s.mu.Unlock()
client, ok := s.shims[id] client, ok := s.shims[id]
if !ok { if !ok {
return nil, fmt.Errorf("container does not exist %q", id) return nil, fmt.Errorf("container does not exist %q", id)
@ -194,22 +260,40 @@ func (s *Service) getShim(id string) (shim.ShimClient, error) {
return client, nil return client, nil
} }
func loadClients(root string) (map[string]shim.ShimClient, error) { func (s *Service) removeShim(id string) {
s.mu.Lock()
defer s.mu.Unlock()
client, ok := s.shims[id]
if ok {
client.stop()
delete(s.shims, id)
}
}
func loadClients(ctx context.Context, root string) (map[string]*shimClient, error) {
files, err := ioutil.ReadDir(root) files, err := ioutil.ReadDir(root)
if err != nil { if err != nil {
return nil, err return nil, err
} }
out := make(map[string]shim.ShimClient) out := make(map[string]*shimClient)
for _, f := range files { for _, f := range files {
if !f.IsDir() { if !f.IsDir() {
continue continue
} }
socket := filepath.Join(root, f.Name(), "shim.sock") //
client, err := connectToShim(socket) id := f.Name()
client, err := loadShimClient(filepath.Join(root, id), id)
if err != nil { if err != nil {
return nil, err log.G(ctx).WithError(err).WithField("id", id).Warn("failed to load container")
// TODO: send an exit event with 255 as exit status
continue
} }
out[f.Name()] = client out[f.Name()] = client
} }
return out, nil return out, nil
} }
func toExecutionEventType(et shim.EventType) string {
return strings.Replace(strings.ToLower(et.String()), "_", "-", -1)
}

View file

@ -1,29 +1,106 @@
package supervisor package supervisor
import ( import (
"context"
"fmt" "fmt"
"io/ioutil" "io/ioutil"
"log" "log"
"net" "net"
"os"
"os/exec" "os/exec"
"path/filepath" "path/filepath"
"syscall"
"time" "time"
"github.com/docker/containerd/api/shim" "github.com/docker/containerd/api/shim"
"github.com/pkg/errors"
"google.golang.org/grpc" "google.golang.org/grpc"
"google.golang.org/grpc/grpclog" "google.golang.org/grpc/grpclog"
) )
func newShimClient(root string) (shim.ShimClient, error) { func newShimClient(root, id string) (*shimClient, error) {
// TODO: start the shim process if err := os.Mkdir(root, 0700); err != nil {
cmd := exec.Command("containerd-shim") return nil, errors.Wrap(err, "failed to create shim working dir")
if err := cmd.Start(); err != nil {
return nil, err
} }
cmd := exec.Command("containerd-shim")
cmd.Dir = root cmd.Dir = root
cmd.SysProcAttr = &syscall.SysProcAttr{
Setpgid: true,
}
if err := cmd.Start(); err != nil {
return nil, errors.Wrapf(err, "failed to start shim")
}
socket := filepath.Join(root, "shim.sock") socket := filepath.Join(root, "shim.sock")
return connectToShim(socket) sc, err := connectToShim(socket)
if err != nil {
syscall.Kill(cmd.Process.Pid, syscall.SIGKILL)
cmd.Wait()
return nil, err
}
s := &shimClient{
ShimClient: sc,
shimCmd: cmd,
syncCh: make(chan struct{}),
root: root,
id: id,
}
go func() {
cmd.Wait()
close(s.syncCh)
}()
return s, nil
}
func loadShimClient(root, id string) (*shimClient, error) {
socket := filepath.Join(root, "shim.sock")
client, err := connectToShim(socket)
if err != nil {
// TODO: failed to connect to the shim, check if it's alive
// - if it is kill it
// - in both case call runc killall and runc delete on the id
return nil, err
}
resp, err := client.State(context.Background(), &shim.StateRequest{})
if err != nil {
return nil, errors.Wrapf(err, "failed to fetch state for container %s", id)
}
return &shimClient{
ShimClient: client,
root: root,
id: id,
initPid: resp.InitPid,
}, nil
}
type shimClient struct {
shim.ShimClient
shimCmd *exec.Cmd
syncCh chan struct{}
root string
id string
initPid uint32
}
func (s *shimClient) stop() {
if s.shimCmd != nil {
select {
case <-s.syncCh:
default:
syscall.Kill(s.shimCmd.Process.Pid, syscall.SIGTERM)
select {
case <-s.syncCh:
case <-time.After(10 * time.Second):
syscall.Kill(s.shimCmd.Process.Pid, syscall.SIGKILL)
}
}
}
os.RemoveAll(s.root)
} }
func connectToShim(socket string) (shim.ShimClient, error) { func connectToShim(socket string) (shim.ShimClient, error) {
@ -33,12 +110,13 @@ func connectToShim(socket string) (shim.ShimClient, error) {
dialOpts = append(dialOpts, dialOpts = append(dialOpts,
grpc.WithDialer(func(addr string, timeout time.Duration) (net.Conn, error) { grpc.WithDialer(func(addr string, timeout time.Duration) (net.Conn, error) {
return net.DialTimeout("unix", socket, timeout) return net.DialTimeout("unix", socket, timeout)
}, }),
)) grpc.WithBlock(),
// FIXME: probably need a retry here grpc.WithTimeout(2*time.Second),
)
conn, err := grpc.Dial(fmt.Sprintf("unix://%s", socket), dialOpts...) conn, err := grpc.Dial(fmt.Sprintf("unix://%s", socket), dialOpts...)
if err != nil { if err != nil {
return nil, err return nil, errors.Wrapf(err, "failed to connect to shim via \"%s\"", fmt.Sprintf("unix://%s", socket))
} }
return shim.NewShimClient(conn), nil return shim.NewShimClient(conn), nil
} }

476
vendor/github.com/nats-io/go-nats-streaming/stan.go generated vendored Normal file
View file

@ -0,0 +1,476 @@
// Copyright 2016 Apcera Inc. All rights reserved.
// Package stan is a Go client for the NATS Streaming messaging system (https://nats.io).
package stan
import (
"errors"
"fmt"
"runtime"
"sync"
"time"
"github.com/nats-io/go-nats"
"github.com/nats-io/go-nats-streaming/pb"
"github.com/nats-io/nuid"
)
// Version is the NATS Streaming Go Client version
const Version = "0.3.4"
const (
// DefaultNatsURL is the default URL the client connects to
DefaultNatsURL = "nats://localhost:4222"
// DefaultConnectWait is the default timeout used for the connect operation
DefaultConnectWait = 2 * time.Second
// DefaultDiscoverPrefix is the prefix subject used to connect to the NATS Streaming server
DefaultDiscoverPrefix = "_STAN.discover"
// DefaultACKPrefix is the prefix subject used to send ACKs to the NATS Streaming server
DefaultACKPrefix = "_STAN.acks"
// DefaultMaxPubAcksInflight is the default maximum number of published messages
// without outstanding ACKs from the server
DefaultMaxPubAcksInflight = 16384
)
// Conn represents a connection to the NATS Streaming subsystem. It can Publish and
// Subscribe to messages within the NATS Streaming cluster.
type Conn interface {
// Publish
Publish(subject string, data []byte) error
PublishAsync(subject string, data []byte, ah AckHandler) (string, error)
// Subscribe
Subscribe(subject string, cb MsgHandler, opts ...SubscriptionOption) (Subscription, error)
// QueueSubscribe
QueueSubscribe(subject, qgroup string, cb MsgHandler, opts ...SubscriptionOption) (Subscription, error)
// Close
Close() error
// NatsConn returns the underlying NATS conn. Use this with care. For
// example, closing the wrapped NATS conn will put the NATS Streaming Conn
// in an invalid state.
NatsConn() *nats.Conn
}
// Errors
var (
ErrConnectReqTimeout = errors.New("stan: connect request timeout")
ErrCloseReqTimeout = errors.New("stan: close request timeout")
ErrSubReqTimeout = errors.New("stan: subscribe request timeout")
ErrUnsubReqTimeout = errors.New("stan: unsubscribe request timeout")
ErrConnectionClosed = errors.New("stan: connection closed")
ErrTimeout = errors.New("stan: publish ack timeout")
ErrBadAck = errors.New("stan: malformed ack")
ErrBadSubscription = errors.New("stan: invalid subscription")
ErrBadConnection = errors.New("stan: invalid connection")
ErrManualAck = errors.New("stan: cannot manually ack in auto-ack mode")
ErrNilMsg = errors.New("stan: nil message")
ErrNoServerSupport = errors.New("stan: not supported by server")
)
// AckHandler is used for Async Publishing to provide status of the ack.
// The func will be passed teh GUID and any error state. No error means the
// message was successfully received by NATS Streaming.
type AckHandler func(string, error)
// Options can be used to a create a customized connection.
type Options struct {
NatsURL string
NatsConn *nats.Conn
ConnectTimeout time.Duration
AckTimeout time.Duration
DiscoverPrefix string
MaxPubAcksInflight int
}
// DefaultOptions are the NATS Streaming client's default options
var DefaultOptions = Options{
NatsURL: DefaultNatsURL,
ConnectTimeout: DefaultConnectWait,
AckTimeout: DefaultAckWait,
DiscoverPrefix: DefaultDiscoverPrefix,
MaxPubAcksInflight: DefaultMaxPubAcksInflight,
}
// Option is a function on the options for a connection.
type Option func(*Options) error
// NatsURL is an Option to set the URL the client should connect to.
func NatsURL(u string) Option {
return func(o *Options) error {
o.NatsURL = u
return nil
}
}
// ConnectWait is an Option to set the timeout for establishing a connection.
func ConnectWait(t time.Duration) Option {
return func(o *Options) error {
o.ConnectTimeout = t
return nil
}
}
// PubAckWait is an Option to set the timeout for waiting for an ACK for a
// published message.
func PubAckWait(t time.Duration) Option {
return func(o *Options) error {
o.AckTimeout = t
return nil
}
}
// MaxPubAcksInflight is an Option to set the maximum number of published
// messages without outstanding ACKs from the server.
func MaxPubAcksInflight(max int) Option {
return func(o *Options) error {
o.MaxPubAcksInflight = max
return nil
}
}
// NatsConn is an Option to set the underlying NATS connection to be used
// by a NATS Streaming Conn object.
func NatsConn(nc *nats.Conn) Option {
return func(o *Options) error {
o.NatsConn = nc
return nil
}
}
// A conn represents a bare connection to a stan cluster.
type conn struct {
sync.RWMutex
clientID string
serverID string
pubPrefix string // Publish prefix set by stan, append our subject.
subRequests string // Subject to send subscription requests.
unsubRequests string // Subject to send unsubscribe requests.
subCloseRequests string // Subject to send subscription close requests.
closeRequests string // Subject to send close requests.
ackSubject string // publish acks
ackSubscription *nats.Subscription
hbSubscription *nats.Subscription
subMap map[string]*subscription
pubAckMap map[string]*ack
pubAckChan chan (struct{})
opts Options
nc *nats.Conn
ncOwned bool // NATS Streaming created the connection, so needs to close it.
}
// Closure for ack contexts.
type ack struct {
t *time.Timer
ah AckHandler
ch chan error
}
// Connect will form a connection to the NATS Streaming subsystem.
func Connect(stanClusterID, clientID string, options ...Option) (Conn, error) {
// Process Options
c := conn{clientID: clientID, opts: DefaultOptions}
for _, opt := range options {
if err := opt(&c.opts); err != nil {
return nil, err
}
}
// Check if the user has provided a connection as an option
c.nc = c.opts.NatsConn
// Create a NATS connection if it doesn't exist.
if c.nc == nil {
nc, err := nats.Connect(c.opts.NatsURL)
if err != nil {
return nil, err
}
c.nc = nc
c.ncOwned = true
} else if !c.nc.IsConnected() {
// Bail if the custom NATS connection is disconnected
return nil, ErrBadConnection
}
// Create a heartbeat inbox
hbInbox := nats.NewInbox()
var err error
if c.hbSubscription, err = c.nc.Subscribe(hbInbox, c.processHeartBeat); err != nil {
c.Close()
return nil, err
}
// Send Request to discover the cluster
discoverSubject := c.opts.DiscoverPrefix + "." + stanClusterID
req := &pb.ConnectRequest{ClientID: clientID, HeartbeatInbox: hbInbox}
b, _ := req.Marshal()
reply, err := c.nc.Request(discoverSubject, b, c.opts.ConnectTimeout)
if err != nil {
c.Close()
if err == nats.ErrTimeout {
return nil, ErrConnectReqTimeout
}
return nil, err
}
// Process the response, grab server pubPrefix
cr := &pb.ConnectResponse{}
err = cr.Unmarshal(reply.Data)
if err != nil {
c.Close()
return nil, err
}
if cr.Error != "" {
c.Close()
return nil, errors.New(cr.Error)
}
// Capture cluster configuration endpoints to publish and subscribe/unsubscribe.
c.pubPrefix = cr.PubPrefix
c.subRequests = cr.SubRequests
c.unsubRequests = cr.UnsubRequests
c.subCloseRequests = cr.SubCloseRequests
c.closeRequests = cr.CloseRequests
// Setup the ACK subscription
c.ackSubject = DefaultACKPrefix + "." + nuid.Next()
if c.ackSubscription, err = c.nc.Subscribe(c.ackSubject, c.processAck); err != nil {
c.Close()
return nil, err
}
c.ackSubscription.SetPendingLimits(1024*1024, 32*1024*1024)
c.pubAckMap = make(map[string]*ack)
// Create Subscription map
c.subMap = make(map[string]*subscription)
c.pubAckChan = make(chan struct{}, c.opts.MaxPubAcksInflight)
// Attach a finalizer
runtime.SetFinalizer(&c, func(sc *conn) { sc.Close() })
return &c, nil
}
// Close a connection to the stan system.
func (sc *conn) Close() error {
if sc == nil {
return ErrBadConnection
}
sc.Lock()
defer sc.Unlock()
if sc.nc == nil {
// We are already closed.
return nil
}
// Capture for NATS calls below.
nc := sc.nc
if sc.ncOwned {
defer nc.Close()
}
// Signals we are closed.
sc.nc = nil
// Now close ourselves.
if sc.ackSubscription != nil {
sc.ackSubscription.Unsubscribe()
}
req := &pb.CloseRequest{ClientID: sc.clientID}
b, _ := req.Marshal()
reply, err := nc.Request(sc.closeRequests, b, sc.opts.ConnectTimeout)
if err != nil {
if err == nats.ErrTimeout {
return ErrCloseReqTimeout
}
return err
}
cr := &pb.CloseResponse{}
err = cr.Unmarshal(reply.Data)
if err != nil {
return err
}
if cr.Error != "" {
return errors.New(cr.Error)
}
return nil
}
// NatsConn returns the underlying NATS conn. Use this with care. For example,
// closing the wrapped NATS conn will put the NATS Streaming Conn in an invalid
// state.
func (sc *conn) NatsConn() *nats.Conn {
return sc.nc
}
// Process a heartbeat from the NATS Streaming cluster
func (sc *conn) processHeartBeat(m *nats.Msg) {
// No payload assumed, just reply.
sc.RLock()
nc := sc.nc
sc.RUnlock()
if nc != nil {
nc.Publish(m.Reply, nil)
}
}
// Process an ack from the NATS Streaming cluster
func (sc *conn) processAck(m *nats.Msg) {
pa := &pb.PubAck{}
err := pa.Unmarshal(m.Data)
if err != nil {
// FIXME, make closure to have context?
fmt.Printf("Error processing unmarshal\n")
return
}
// Remove
a := sc.removeAck(pa.Guid)
if a != nil {
// Capture error if it exists.
if pa.Error != "" {
err = errors.New(pa.Error)
}
if a.ah != nil {
// Perform the ackHandler callback
a.ah(pa.Guid, err)
} else if a.ch != nil {
// Send to channel directly
a.ch <- err
}
}
}
// Publish will publish to the cluster and wait for an ACK.
func (sc *conn) Publish(subject string, data []byte) error {
ch := make(chan error)
_, err := sc.publishAsync(subject, data, nil, ch)
if err == nil {
err = <-ch
}
return err
}
// PublishAsync will publish to the cluster on pubPrefix+subject and asynchronously
// process the ACK or error state. It will return the GUID for the message being sent.
func (sc *conn) PublishAsync(subject string, data []byte, ah AckHandler) (string, error) {
return sc.publishAsync(subject, data, ah, nil)
}
func (sc *conn) publishAsync(subject string, data []byte, ah AckHandler, ch chan error) (string, error) {
a := &ack{ah: ah, ch: ch}
sc.Lock()
if sc.nc == nil {
sc.Unlock()
return "", ErrConnectionClosed
}
subj := sc.pubPrefix + "." + subject
// This is only what we need from PubMsg in the timer below,
// so do this so that pe doesn't escape (and we same on new object)
peGUID := nuid.Next()
pe := &pb.PubMsg{ClientID: sc.clientID, Guid: peGUID, Subject: subject, Data: data}
b, _ := pe.Marshal()
// Map ack to guid.
sc.pubAckMap[peGUID] = a
// snapshot
ackSubject := sc.ackSubject
ackTimeout := sc.opts.AckTimeout
pac := sc.pubAckChan
sc.Unlock()
// Use the buffered channel to control the number of outstanding acks.
pac <- struct{}{}
err := sc.nc.PublishRequest(subj, ackSubject, b)
if err != nil {
sc.removeAck(peGUID)
return "", err
}
// Setup the timer for expiration.
sc.Lock()
a.t = time.AfterFunc(ackTimeout, func() {
sc.removeAck(peGUID)
if a.ah != nil {
ah(peGUID, ErrTimeout)
} else if a.ch != nil {
a.ch <- ErrTimeout
}
})
sc.Unlock()
return peGUID, nil
}
// removeAck removes the ack from the pubAckMap and cancels any state, e.g. timers
func (sc *conn) removeAck(guid string) *ack {
var t *time.Timer
sc.Lock()
a := sc.pubAckMap[guid]
if a != nil {
t = a.t
delete(sc.pubAckMap, guid)
}
pac := sc.pubAckChan
sc.Unlock()
// Cancel timer if needed.
if t != nil {
t.Stop()
}
// Remove from channel to unblock PublishAsync
if a != nil && len(pac) > 0 {
<-pac
}
return a
}
// Process an msg from the NATS Streaming cluster
func (sc *conn) processMsg(raw *nats.Msg) {
msg := &Msg{}
err := msg.Unmarshal(raw.Data)
if err != nil {
panic("Error processing unmarshal for msg")
}
// Lookup the subscription
sc.RLock()
nc := sc.nc
isClosed := nc == nil
sub := sc.subMap[raw.Subject]
sc.RUnlock()
// Check if sub is no longer valid or connection has been closed.
if sub == nil || isClosed {
return
}
// Store in msg for backlink
msg.Sub = sub
sub.RLock()
cb := sub.cb
ackSubject := sub.ackInbox
isManualAck := sub.opts.ManualAcks
subsc := sub.sc // Can be nil if sub has been unsubscribed.
sub.RUnlock()
// Perform the callback
if cb != nil && subsc != nil {
cb(msg)
}
// Proces auto-ack
if !isManualAck && nc != nil {
ack := &pb.Ack{Subject: msg.Subject, Sequence: msg.Sequence}
b, _ := ack.Marshal()
if err := nc.Publish(ackSubject, b); err != nil {
// FIXME(dlc) - Async error handler? Retry?
}
}
}

376
vendor/github.com/nats-io/go-nats-streaming/sub.go generated vendored Normal file
View file

@ -0,0 +1,376 @@
// Copyright 2016 Apcera Inc. All rights reserved.
// Package stan is a Go client for the NATS Streaming messaging system (https://nats.io).
package stan
import (
"errors"
"sync"
"time"
"github.com/nats-io/go-nats"
"github.com/nats-io/go-nats-streaming/pb"
)
const (
// DefaultAckWait indicates how long the server should wait for an ACK before resending a message
DefaultAckWait = 30 * time.Second
// DefaultMaxInflight indicates how many messages with outstanding ACKs the server can send
DefaultMaxInflight = 1024
)
// Msg is the client defined message, which includes proto, then back link to subscription.
type Msg struct {
pb.MsgProto // MsgProto: Seq, Subject, Reply[opt], Data, Timestamp, CRC32[opt]
Sub Subscription
}
// Subscriptions and Options
// Subscription represents a subscription within the NATS Streaming cluster. Subscriptions
// will be rate matched and follow at-least delivery semantics.
type Subscription interface {
// Unsubscribe removes interest in the subscription.
// For durables, it means that the durable interest is also removed from
// the server. Restarting a durable with the same name will not resume
// the subscription, it will be considered a new one.
Unsubscribe() error
// Close removes this subscriber from the server, but unlike Unsubscribe(),
// the durable interest is not removed. If the client has connected to a server
// for which this feature is not available, Close() will return a ErrNoServerSupport
// error.
Close() error
}
// A subscription represents a subscription to a stan cluster.
type subscription struct {
sync.RWMutex
sc *conn
subject string
qgroup string
inbox string
ackInbox string
inboxSub *nats.Subscription
opts SubscriptionOptions
cb MsgHandler
}
// SubscriptionOption is a function on the options for a subscription.
type SubscriptionOption func(*SubscriptionOptions) error
// MsgHandler is a callback function that processes messages delivered to
// asynchronous subscribers.
type MsgHandler func(msg *Msg)
// SubscriptionOptions are used to control the Subscription's behavior.
type SubscriptionOptions struct {
// DurableName, if set will survive client restarts.
DurableName string
// Controls the number of messages the cluster will have inflight without an ACK.
MaxInflight int
// Controls the time the cluster will wait for an ACK for a given message.
AckWait time.Duration
// StartPosition enum from proto.
StartAt pb.StartPosition
// Optional start sequence number.
StartSequence uint64
// Optional start time.
StartTime time.Time
// Option to do Manual Acks
ManualAcks bool
}
// DefaultSubscriptionOptions are the default subscriptions' options
var DefaultSubscriptionOptions = SubscriptionOptions{
MaxInflight: DefaultMaxInflight,
AckWait: DefaultAckWait,
}
// MaxInflight is an Option to set the maximum number of messages the cluster will send
// without an ACK.
func MaxInflight(m int) SubscriptionOption {
return func(o *SubscriptionOptions) error {
o.MaxInflight = m
return nil
}
}
// AckWait is an Option to set the timeout for waiting for an ACK from the cluster's
// point of view for delivered messages.
func AckWait(t time.Duration) SubscriptionOption {
return func(o *SubscriptionOptions) error {
o.AckWait = t
return nil
}
}
// StartAt sets the desired start position for the message stream.
func StartAt(sp pb.StartPosition) SubscriptionOption {
return func(o *SubscriptionOptions) error {
o.StartAt = sp
return nil
}
}
// StartAtSequence sets the desired start sequence position and state.
func StartAtSequence(seq uint64) SubscriptionOption {
return func(o *SubscriptionOptions) error {
o.StartAt = pb.StartPosition_SequenceStart
o.StartSequence = seq
return nil
}
}
// StartAtTime sets the desired start time position and state.
func StartAtTime(start time.Time) SubscriptionOption {
return func(o *SubscriptionOptions) error {
o.StartAt = pb.StartPosition_TimeDeltaStart
o.StartTime = start
return nil
}
}
// StartAtTimeDelta sets the desired start time position and state using the delta.
func StartAtTimeDelta(ago time.Duration) SubscriptionOption {
return func(o *SubscriptionOptions) error {
o.StartAt = pb.StartPosition_TimeDeltaStart
o.StartTime = time.Now().Add(-ago)
return nil
}
}
// StartWithLastReceived is a helper function to set start position to last received.
func StartWithLastReceived() SubscriptionOption {
return func(o *SubscriptionOptions) error {
o.StartAt = pb.StartPosition_LastReceived
return nil
}
}
// DeliverAllAvailable will deliver all messages available.
func DeliverAllAvailable() SubscriptionOption {
return func(o *SubscriptionOptions) error {
o.StartAt = pb.StartPosition_First
return nil
}
}
// SetManualAckMode will allow clients to control their own acks to delivered messages.
func SetManualAckMode() SubscriptionOption {
return func(o *SubscriptionOptions) error {
o.ManualAcks = true
return nil
}
}
// DurableName sets the DurableName for the subcriber.
func DurableName(name string) SubscriptionOption {
return func(o *SubscriptionOptions) error {
o.DurableName = name
return nil
}
}
// Subscribe will perform a subscription with the given options to the NATS Streaming cluster.
func (sc *conn) Subscribe(subject string, cb MsgHandler, options ...SubscriptionOption) (Subscription, error) {
return sc.subscribe(subject, "", cb, options...)
}
// QueueSubscribe will perform a queue subscription with the given options to the NATS Streaming cluster.
func (sc *conn) QueueSubscribe(subject, qgroup string, cb MsgHandler, options ...SubscriptionOption) (Subscription, error) {
return sc.subscribe(subject, qgroup, cb, options...)
}
// subscribe will perform a subscription with the given options to the NATS Streaming cluster.
func (sc *conn) subscribe(subject, qgroup string, cb MsgHandler, options ...SubscriptionOption) (Subscription, error) {
sub := &subscription{subject: subject, qgroup: qgroup, inbox: nats.NewInbox(), cb: cb, sc: sc, opts: DefaultSubscriptionOptions}
for _, opt := range options {
if err := opt(&sub.opts); err != nil {
return nil, err
}
}
sc.Lock()
if sc.nc == nil {
sc.Unlock()
return nil, ErrConnectionClosed
}
// Register subscription.
sc.subMap[sub.inbox] = sub
nc := sc.nc
sc.Unlock()
// Hold lock throughout.
sub.Lock()
defer sub.Unlock()
// Listen for actual messages.
nsub, err := nc.Subscribe(sub.inbox, sc.processMsg)
if err != nil {
return nil, err
}
sub.inboxSub = nsub
// Create a subscription request
// FIXME(dlc) add others.
sr := &pb.SubscriptionRequest{
ClientID: sc.clientID,
Subject: subject,
QGroup: qgroup,
Inbox: sub.inbox,
MaxInFlight: int32(sub.opts.MaxInflight),
AckWaitInSecs: int32(sub.opts.AckWait / time.Second),
StartPosition: sub.opts.StartAt,
DurableName: sub.opts.DurableName,
}
// Conditionals
switch sr.StartPosition {
case pb.StartPosition_TimeDeltaStart:
sr.StartTimeDelta = time.Now().UnixNano() - sub.opts.StartTime.UnixNano()
case pb.StartPosition_SequenceStart:
sr.StartSequence = sub.opts.StartSequence
}
b, _ := sr.Marshal()
reply, err := sc.nc.Request(sc.subRequests, b, sc.opts.ConnectTimeout)
if err != nil {
sub.inboxSub.Unsubscribe()
if err == nats.ErrTimeout {
err = ErrSubReqTimeout
}
return nil, err
}
r := &pb.SubscriptionResponse{}
if err := r.Unmarshal(reply.Data); err != nil {
sub.inboxSub.Unsubscribe()
return nil, err
}
if r.Error != "" {
sub.inboxSub.Unsubscribe()
return nil, errors.New(r.Error)
}
sub.ackInbox = r.AckInbox
return sub, nil
}
// closeOrUnsubscribe performs either close or unsubsribe based on
// given boolean.
func (sub *subscription) closeOrUnsubscribe(doClose bool) error {
if sub == nil {
return ErrBadSubscription
}
sub.Lock()
sc := sub.sc
if sc == nil {
// Already closed.
sub.Unlock()
return ErrBadSubscription
}
sub.sc = nil
sub.inboxSub.Unsubscribe()
sub.inboxSub = nil
sub.Unlock()
if sc == nil {
return ErrBadSubscription
}
sc.Lock()
if sc.nc == nil {
sc.Unlock()
return ErrConnectionClosed
}
delete(sc.subMap, sub.inbox)
reqSubject := sc.unsubRequests
if doClose {
reqSubject = sc.subCloseRequests
if reqSubject == "" {
sc.Unlock()
return ErrNoServerSupport
}
}
// Snapshot connection to avoid data race, since the connection may be
// closing while we try to send the request
nc := sc.nc
sc.Unlock()
usr := &pb.UnsubscribeRequest{
ClientID: sc.clientID,
Subject: sub.subject,
Inbox: sub.ackInbox,
}
b, _ := usr.Marshal()
reply, err := nc.Request(reqSubject, b, sc.opts.ConnectTimeout)
if err != nil {
if err == nats.ErrTimeout {
if doClose {
return ErrCloseReqTimeout
}
return ErrUnsubReqTimeout
}
return err
}
r := &pb.SubscriptionResponse{}
if err := r.Unmarshal(reply.Data); err != nil {
return err
}
if r.Error != "" {
return errors.New(r.Error)
}
return nil
}
// Unsubscribe implements the Subscription interface
func (sub *subscription) Unsubscribe() error {
return sub.closeOrUnsubscribe(false)
}
// Close implements the Subscription interface
func (sub *subscription) Close() error {
return sub.closeOrUnsubscribe(true)
}
// Ack manually acknowledges a message.
// The subscriber had to be created with SetManualAckMode() option.
func (msg *Msg) Ack() error {
if msg == nil {
return ErrNilMsg
}
// Look up subscription
sub := msg.Sub.(*subscription)
if sub == nil {
return ErrBadSubscription
}
sub.RLock()
ackSubject := sub.ackInbox
isManualAck := sub.opts.ManualAcks
sc := sub.sc
sub.RUnlock()
// Check for error conditions.
if sc == nil {
return ErrBadSubscription
}
// Get nc from the connection (needs locking to avoid race)
sc.RLock()
nc := sc.nc
sc.RUnlock()
if nc == nil {
return ErrBadConnection
}
if !isManualAck {
return ErrManualAck
}
// Ack here.
ack := &pb.Ack{Subject: msg.Subject, Sequence: msg.Sequence}
b, _ := ack.Marshal()
return nc.Publish(ackSubject, b)
}