From 5f3cb769fe2addff1a50b0781e4164a7a1a61176 Mon Sep 17 00:00:00 2001 From: Alex K <8418476+fearful-symmetry@users.noreply.github.com> Date: Wed, 5 Feb 2020 06:50:14 -0800 Subject: [PATCH] Cherry-pick #15935 to 7.6: [Elastic Log Driver] Fix file check bug, deal with logging (#16095) * [Elastic Log Driver] Fix file check bug, deal with logging (#15935) * fix file check bug, deal with logging * add logging env fix * remove space * fix nil pointer deref * add missing blocking read call (cherry picked from commit d60e65b3d5f903958c698d19092974b75f56fbba) * remove space --- x-pack/dockerlogbeat/config.json | 2 +- x-pack/dockerlogbeat/handlers.go | 6 +++--- x-pack/dockerlogbeat/magefile.go | 3 +++ x-pack/dockerlogbeat/main.go | 6 +++++- x-pack/dockerlogbeat/pipelinemanager/libbeattools.go | 8 ++++---- x-pack/dockerlogbeat/pipelinemanager/pipelineManager.go | 3 +-- 6 files changed, 17 insertions(+), 11 deletions(-) diff --git a/x-pack/dockerlogbeat/config.json b/x-pack/dockerlogbeat/config.json index 657e32d17a4..d3072a841bc 100644 --- a/x-pack/dockerlogbeat/config.json +++ b/x-pack/dockerlogbeat/config.json @@ -33,4 +33,4 @@ "value": "/contmount/controller.sock" } ] -} +} \ No newline at end of file diff --git a/x-pack/dockerlogbeat/handlers.go b/x-pack/dockerlogbeat/handlers.go index 4348b948f52..12320cee232 100644 --- a/x-pack/dockerlogbeat/handlers.go +++ b/x-pack/dockerlogbeat/handlers.go @@ -39,7 +39,7 @@ func startLoggingHandler(pm *pipelinemanager.PipelineManager) func(w http.Respon } pm.Logger.Debugf("Homepath: %v\n", filepath.Dir(os.Args[0])) - pm.Logger.Debugf("Got start request object from container %#v\n", startReq.Info.ContainerName) + pm.Logger.Infof("Got start request object from container %#v\n", startReq.Info.ContainerName) pm.Logger.Debugf("Got a container with the following labels: %#v\n", startReq.Info.ContainerLabels) pm.Logger.Debugf("Got a container with the following log opts: %#v\n", startReq.Info.Config) @@ -64,13 +64,13 @@ func stopLoggingHandler(pm *pipelinemanager.PipelineManager) func(w http.Respons http.Error(w, errors.Wrap(err, "error decoding json request").Error(), http.StatusBadRequest) return } - pm.Logger.Infof(" Got stop request object %#v\n", stopReq) + pm.Logger.Infof("Got stop request object %#v\n", stopReq) // Run the stop async, since nothing 'depends' on it, // and we can break people's docker automation if this times out. go func() { err = pm.CloseClientWithFile(stopReq.File) if err != nil { - pm.Logger.Infof(" Got stop request error %#v\n", err) + pm.Logger.Errorf(" Got stop request error %#v\n", err) } }() diff --git a/x-pack/dockerlogbeat/magefile.go b/x-pack/dockerlogbeat/magefile.go index 837905e6220..e6921509600 100644 --- a/x-pack/dockerlogbeat/magefile.go +++ b/x-pack/dockerlogbeat/magefile.go @@ -102,6 +102,9 @@ func createContainer(ctx context.Context, cli *client.Client) error { } //build, wait for output buildResp, err := cli.ImageBuild(ctx, buildContext, buildOpts) + if err != nil { + return errors.Wrap(err, "error building final container image") + } defer buildResp.Body.Close() // This blocks until the build operation completes buildStr, errBufRead := ioutil.ReadAll(buildResp.Body) diff --git a/x-pack/dockerlogbeat/main.go b/x-pack/dockerlogbeat/main.go index d763126f2dc..60dcf70537f 100644 --- a/x-pack/dockerlogbeat/main.go +++ b/x-pack/dockerlogbeat/main.go @@ -26,8 +26,12 @@ import ( // genNewMonitoringConfig is a hacked-in function to enable a debug stderr logger func genNewMonitoringConfig() (*common.Config, error) { + lvl, isSet := os.LookupEnv("LOG_DRIVER_LEVEL") + if !isSet { + lvl = "info" + } cfgObject := make(map[string]string) - cfgObject["level"] = "debug" + cfgObject["level"] = lvl cfgObject["to_stderr"] = "true" cfg, err := common.NewConfigFrom(cfgObject) diff --git a/x-pack/dockerlogbeat/pipelinemanager/libbeattools.go b/x-pack/dockerlogbeat/pipelinemanager/libbeattools.go index f4db79155d5..8f1e55f342e 100644 --- a/x-pack/dockerlogbeat/pipelinemanager/libbeattools.go +++ b/x-pack/dockerlogbeat/pipelinemanager/libbeattools.go @@ -245,21 +245,21 @@ func loadMeta(metaPath string) (uuid.UUID, error) { func openRegular(filename string) (*os.File, error) { f, err := os.Open(filename) if err != nil { - return f, errors.Wrapf(err, "error opening file %s", filename) + return f, err } info, err := f.Stat() if err != nil { f.Close() - return nil, errors.Wrapf(err, "error statting %s", filename) + return nil, err } if !info.Mode().IsRegular() { f.Close() if info.IsDir() { - return nil, fmt.Errorf("%s is a directory", filename) + return nil, err } - return nil, fmt.Errorf("%s is not a regular file", filename) + return nil, err } return f, nil diff --git a/x-pack/dockerlogbeat/pipelinemanager/pipelineManager.go b/x-pack/dockerlogbeat/pipelinemanager/pipelineManager.go index d0df1dba5d2..37696101e7c 100644 --- a/x-pack/dockerlogbeat/pipelinemanager/pipelineManager.go +++ b/x-pack/dockerlogbeat/pipelinemanager/pipelineManager.go @@ -43,8 +43,7 @@ type PipelineManager struct { // NewPipelineManager creates a new Pipeline map func NewPipelineManager(logCfg *common.Config) *PipelineManager { return &PipelineManager{ - Logger: logp.NewLogger("PipelineManager"), - //mu: new(sync.Mutex), + Logger: logp.NewLogger("PipelineManager"), pipelines: make(map[string]*Pipeline), clients: make(map[string]*ClientLogger), }