summaryrefslogtreecommitdiffstats
path: root/plugin/client_rpc.go
diff options
context:
space:
mode:
authorChristopher Speller <crspeller@gmail.com>2018-07-03 09:58:28 -0700
committerGitHub <noreply@github.com>2018-07-03 09:58:28 -0700
commit83a3ac089cff0d05559e6ba5c2c60b09f5cae176 (patch)
tree51cc53c0a77cf455cf9d700a453b6d57f1604fdb /plugin/client_rpc.go
parent3848cb7e79e019e2f0878d6e2377ad36b3c7ca43 (diff)
downloadchat-83a3ac089cff0d05559e6ba5c2c60b09f5cae176.tar.gz
chat-83a3ac089cff0d05559e6ba5c2c60b09f5cae176.tar.bz2
chat-83a3ac089cff0d05559e6ba5c2c60b09f5cae176.zip
MM-11029 Adding plugin logging functionality. (#9034)
* Capturing stdout, stderr of plugins in logs. * Cleanup go-plugin debug logs. * Adding logging to plugin API * Generating mocks. * godoc convention
Diffstat (limited to 'plugin/client_rpc.go')
-rw-r--r--plugin/client_rpc.go29
1 files changed, 11 insertions, 18 deletions
diff --git a/plugin/client_rpc.go b/plugin/client_rpc.go
index 159d41201..f58bbd22b 100644
--- a/plugin/client_rpc.go
+++ b/plugin/client_rpc.go
@@ -9,9 +9,12 @@ import (
"bytes"
"encoding/gob"
"encoding/json"
+ "fmt"
"io/ioutil"
+ "log"
"net/http"
"net/rpc"
+ "os"
"reflect"
"github.com/hashicorp/go-plugin"
@@ -33,7 +36,6 @@ type HooksRPCServer struct {
impl interface{}
muxBroker *plugin.MuxBroker
apiRPCClient *APIRPCClient
- log *mlog.Logger
}
// Implements hashicorp/go-plugin/plugin.Plugin interface to connect the hooks of a plugin
@@ -156,24 +158,11 @@ func (g *HooksRPCClient) OnActivate() error {
func (s *HooksRPCServer) OnActivate(args *OnActivateArgs, returns *OnActivateReturns) error {
connection, err := s.muxBroker.Dial(args.APIMuxId)
if err != nil {
- return err // Where does this go?
+ return err
}
- // Settings for this should come from the parent process, for now just set it up
- // though stdout.
- logger := mlog.NewLogger(&mlog.LoggerConfiguration{
- EnableConsole: true,
- ConsoleJson: true,
- ConsoleLevel: mlog.LevelDebug,
- EnableFile: false,
- })
- logger = logger.With(mlog.Bool("plugin_subprocess", true))
-
- s.log = logger
-
s.apiRPCClient = &APIRPCClient{
client: rpc.NewClient(connection),
- log: logger,
}
if mmplugin, ok := s.impl.(interface {
@@ -185,6 +174,10 @@ func (s *HooksRPCServer) OnActivate(args *OnActivateArgs, returns *OnActivateRet
mmplugin.OnConfigurationChange()
}
+ // Capture output of standard logger because go-plugin
+ // redirects it.
+ log.SetOutput(os.Stderr)
+
if hook, ok := s.impl.(interface {
OnActivate() error
}); ok {
@@ -293,7 +286,7 @@ func (g *HooksRPCClient) ServeHTTP(w http.ResponseWriter, r *http.Request) {
Request: forwardedRequest,
RequestBodyStream: requestBodyStreamId,
}, nil); err != nil {
- mlog.Error("Plugin failed to ServeHTTP, RPC call failed", mlog.Err(err))
+ g.log.Error("Plugin failed to ServeHTTP, RPC call failed", mlog.Err(err))
http.Error(w, "500 internal server error", http.StatusInternalServerError)
}
return
@@ -302,7 +295,7 @@ func (g *HooksRPCClient) ServeHTTP(w http.ResponseWriter, r *http.Request) {
func (s *HooksRPCServer) ServeHTTP(args *ServeHTTPArgs, returns *struct{}) error {
connection, err := s.muxBroker.Dial(args.ResponseWriterStream)
if err != nil {
- s.log.Debug("Can't connect to remote response writer stream", mlog.Err(err))
+ fmt.Fprintf(os.Stderr, "[ERROR] Can't connect to remote response writer stream, error: %v", err.Error())
return err
}
w := ConnectHTTPResponseWriter(connection)
@@ -312,7 +305,7 @@ func (s *HooksRPCServer) ServeHTTP(args *ServeHTTPArgs, returns *struct{}) error
if args.RequestBodyStream != 0 {
connection, err := s.muxBroker.Dial(args.RequestBodyStream)
if err != nil {
- s.log.Debug("Can't connect to remote response writer stream", mlog.Err(err))
+ fmt.Fprintf(os.Stderr, "[ERROR] Can't connect to remote request body stream, error: %v", err.Error())
return err
}
r.Body = ConnectIOReader(connection)