Skip to content

Commit

Permalink
[Elastic Log Driver] Fix file check bug, deal with logging (#15935) (#…
Browse files Browse the repository at this point in the history
…16094)

* 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 d60e65b)
  • Loading branch information
fearful-symmetry authored Feb 5, 2020
1 parent 67f24e0 commit aa25d3c
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 10 deletions.
6 changes: 3 additions & 3 deletions x-pack/dockerlogbeat/handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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)
}
}()

Expand Down
3 changes: 3 additions & 0 deletions x-pack/dockerlogbeat/magefile.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 5 additions & 1 deletion x-pack/dockerlogbeat/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions x-pack/dockerlogbeat/pipelinemanager/libbeattools.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions x-pack/dockerlogbeat/pipelinemanager/pipelineManager.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
}
Expand Down

0 comments on commit aa25d3c

Please sign in to comment.