logmon client to handle grpc closing errors
This commit is contained in:
parent
81d30a8c11
commit
b51f00a7f3
|
@ -4,10 +4,14 @@ import (
|
|||
"context"
|
||||
|
||||
"github.com/hashicorp/nomad/client/logmon/proto"
|
||||
"github.com/hashicorp/nomad/helper/pluginutils/grpcutils"
|
||||
)
|
||||
|
||||
type logmonClient struct {
|
||||
client proto.LogMonClient
|
||||
|
||||
// doneCtx is closed when the plugin exits
|
||||
doneCtx context.Context
|
||||
}
|
||||
|
||||
func (c *logmonClient) Start(cfg *LogConfig) error {
|
||||
|
@ -21,11 +25,11 @@ func (c *logmonClient) Start(cfg *LogConfig) error {
|
|||
StderrFifo: cfg.StderrFifo,
|
||||
}
|
||||
_, err := c.client.Start(context.Background(), req)
|
||||
return err
|
||||
return grpcutils.HandleGrpcErr(err, c.doneCtx)
|
||||
}
|
||||
|
||||
func (c *logmonClient) Stop() error {
|
||||
req := &proto.StopRequest{}
|
||||
_, err := c.client.Stop(context.Background(), req)
|
||||
return err
|
||||
return grpcutils.HandleGrpcErr(err, c.doneCtx)
|
||||
}
|
||||
|
|
|
@ -73,5 +73,8 @@ func (p *Plugin) GRPCServer(broker *plugin.GRPCBroker, s *grpc.Server) error {
|
|||
}
|
||||
|
||||
func (p *Plugin) GRPCClient(ctx context.Context, broker *plugin.GRPCBroker, c *grpc.ClientConn) (interface{}, error) {
|
||||
return &logmonClient{client: proto.NewLogMonClient(c)}, nil
|
||||
return &logmonClient{
|
||||
doneCtx: ctx,
|
||||
client: proto.NewLogMonClient(c),
|
||||
}, nil
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue