Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix import dashboards when ulimit -n is low #4246

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ https://github.com/elastic/beats/compare/v6.0.0-alpha1...master[Check the HEAD d

*Affecting all Beats*

- Fix importing the dashboards when the limit for max open files is too low. {issue}4244[4244]

*Filebeat*

*Heartbeat*
Expand Down
23 changes: 16 additions & 7 deletions libbeat/dashboards/importer.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ func (imp Importer) CreateKibanaIndex() error {
},
})
if err != nil {
fmt.Fprintln(os.Stderr, fmt.Sprintf("Failed to set the mapping - %s", err))
imp.statusMsg("Failed to set the mapping: %v", err)
}
return nil
}
Expand Down Expand Up @@ -360,12 +360,13 @@ func (imp Importer) unzip(archive, target string) error {
return err
}

for _, file := range reader.File {
// Closure to close the files on each iteration
unzipFile := func(file *zip.File) error {
filePath := filepath.Join(target, file.Name)

if file.FileInfo().IsDir() {
os.MkdirAll(filePath, file.Mode())
continue
return nil
}
fileReader, err := file.Open()
if err != nil {
Expand All @@ -382,6 +383,14 @@ func (imp Importer) unzip(archive, target string) error {
if _, err := io.Copy(targetFile, fileReader); err != nil {
return err
}
return nil
}

for _, file := range reader.File {
err := unzipFile(file)
if err != nil {
return err
}
}
return nil
}
Expand All @@ -392,16 +401,16 @@ func (imp Importer) ImportArchive() error {

target, err := ioutil.TempDir("", "tmp")
if err != nil {
return errors.New("Failed to generate a temporary directory name")
return fmt.Errorf("Failed to generate a temporary directory name: %v", err)
}

if err = os.MkdirAll(target, 0755); err != nil {
return fmt.Errorf("Failed to create a temporary directory: %v", target)
return fmt.Errorf("Failed to create a temporary directory %s: %v", target, err)
}

defer os.RemoveAll(target) // clean up

imp.statusMsg("Create temporary directory %s", target)
imp.statusMsg("Created temporary directory %s", target)
if imp.cfg.File != "" {
archive = imp.cfg.File
} else if imp.cfg.Snapshot {
Expand All @@ -422,7 +431,7 @@ func (imp Importer) ImportArchive() error {

err = imp.unzip(archive, target)
if err != nil {
return fmt.Errorf("Failed to unzip the archive: %s", archive)
return fmt.Errorf("Failed to unzip the archive: %s: %v", archive, err)
}
dirs, err := getDirectories(target)
if err != nil {
Expand Down