Skip to content

Commit

Permalink
remove diagnostics hook
Browse files Browse the repository at this point in the history
  • Loading branch information
belimawr committed Jan 22, 2024
1 parent f8253aa commit 0065ecd
Showing 1 changed file with 0 additions and 45 deletions.
45 changes: 0 additions & 45 deletions libbeat/cmd/instance/beat.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
package instance

import (
"bytes"
"context"
cryptRand "crypto/rand"
"encoding/json"
Expand All @@ -32,7 +31,6 @@ import (
"net"
"os"
"os/user"
"path/filepath"
"runtime"
"runtime/debug"
"strconv"
Expand Down Expand Up @@ -404,11 +402,6 @@ func (b *Beat) createBeater(bt beat.Creator) (beat.Beater, error) {
sensitiveLoggerCfg.Files.Name = sensitiveLoggerCfg.Files.Name + "-events-data"
}

// Now that the events logger is configured, we can register it's diagnostic
// hook
b.Manager.RegisterDiagnosticHook("events log",
"log files containing raw events", "events_log.ndjson",
"application/x-ndjson", b.eventsLogDiagnosticsHook(sensitiveLoggerCfg))
outputFactory := b.makeOutputFactory(b.Config.Output, sensitiveLoggerCfg)
settings := pipeline.Settings{
Processors: b.processors,
Expand All @@ -434,44 +427,6 @@ func (b *Beat) createBeater(bt beat.Creator) (beat.Beater, error) {
return beater, nil
}

func (b *Beat) eventsLogDiagnosticsHook(logCfg logp.Config) func() []byte {
// Setup a no-op function to return in case of an error
data := []byte{}
fn := func() []byte {
return data
}

glob := fmt.Sprintf("%s*.ndjson",
paths.Resolve(
paths.Logs,
filepath.Join(
logCfg.Files.Path,
logCfg.LogFilename(),
)))

files, err := filepath.Glob(glob)
if err != nil {
logp.Warn("could not get 'event log' files: %s", err)
return fn
}

filesData := [][]byte{}
fn = func() []byte {
return bytes.Join(filesData, []byte{})
}

for _, f := range files {
logData, err := os.ReadFile(f)
if err != nil {
logp.Warn("could not read event log file '%s': %s", f, err)
return fn
}
filesData = append(filesData, logData)
}

return fn
}

func (b *Beat) launch(settings Settings, bt beat.Creator) error {
defer func() {
_ = logp.Sync()
Expand Down

0 comments on commit 0065ecd

Please sign in to comment.