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

[Auditbeat] System module: Fix and unify bucket closing logic #10897

Merged
merged 2 commits into from
Mar 1, 2019
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
1 change: 1 addition & 0 deletions CHANGELOG.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ https://github.com/elastic/beats/compare/v7.0.0-alpha2...master[Check the HEAD d
- Enable System module config on Windows. {pull}10237[10237]
- Package: Disable librpm signal handlers. {pull}10694[10694]
- Login: Handle different bad login UTMP types. {pull}10865[10865]
- System module: Fix and unify bucket closing logic. {pull}10897[10897]

*Filebeat*

Expand Down
27 changes: 16 additions & 11 deletions x-pack/auditbeat/module/system/host/host.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,10 @@ func New(base mb.BaseMetricSet) (mb.MetricSet, error) {

// Close cleans up the MetricSet when it finishes.
func (ms *MetricSet) Close() error {
return ms.saveStateToDisk()
if ms.bucket != nil {
return ms.bucket.Close()
}
return nil
}

// Fetch collects data about the host. It is invoked periodically.
Expand Down Expand Up @@ -224,7 +227,7 @@ func (ms *MetricSet) reportState(report mb.ReporterV2) error {

report.Event(hostEvent(host, eventTypeState, eventActionHost))

return nil
return ms.saveStateToDisk()
}

// reportChanges detects and reports any changes to this host since the last call.
Expand Down Expand Up @@ -375,17 +378,19 @@ func inflect(noun string, count int) string {
func (ms *MetricSet) saveStateToDisk() error {
var buf bytes.Buffer
encoder := gob.NewEncoder(&buf)
err := encoder.Encode(*ms.lastHost)
if err != nil {
return errors.Wrap(err, "error encoding host information")
}
if ms.lastHost != nil {
err := encoder.Encode(*ms.lastHost)
if err != nil {
return errors.Wrap(err, "error encoding host information")
}

err = ms.bucket.Store(bucketKeyLastHost, buf.Bytes())
if err != nil {
return errors.Wrap(err, "error writing host information to disk")
}
err = ms.bucket.Store(bucketKeyLastHost, buf.Bytes())
if err != nil {
return errors.Wrap(err, "error writing host information to disk")
}

ms.log.Debug("Wrote host information to disk.")
ms.log.Debug("Wrote host information to disk.")
}
return nil
}

Expand Down
6 changes: 4 additions & 2 deletions x-pack/auditbeat/module/system/login/utmp.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,10 @@ func NewUtmpFileReader(log *logp.Logger, bucket datastore.Bucket, config config)

// Close performs any cleanup tasks when the UTMP reader is done.
func (r *UtmpFileReader) Close() error {
err := r.bucket.Close()
return errors.Wrap(err, "error closing bucket")
if r.bucket != nil {
return r.bucket.Close()
}
return nil
}

// ReadNew returns any new UTMP entries in any files matching the configured pattern.
Expand Down