Skip to content
Open
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
6 changes: 4 additions & 2 deletions filewatcher/filewatcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,15 @@ import (
)

type FileWatcher struct {
logger *logp.Logger
files []string
lastScan time.Time
lastHash uint64
}

func New(files ...string) *FileWatcher {
func New(logger *logp.Logger, files ...string) *FileWatcher {
return &FileWatcher{
logger: logger,
lastScan: time.Time{},
lastHash: 0,
files: files,
Expand All @@ -57,7 +59,7 @@ func (f *FileWatcher) Scan() ([]string, bool, error) {
for _, path := range f.files {
info, err := os.Stat(path)
if err != nil {
logp.Err("Error getting stats for file: %s", path)
f.logger.Errorf("Error getting stats for file: %s", path)
continue
}

Expand Down
3 changes: 2 additions & 1 deletion filewatcher/filewatcher_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"testing"
"time"

"github.com/elastic/elastic-agent-libs/logp/logptest"
"github.com/stretchr/testify/assert"
)

Expand All @@ -44,7 +45,7 @@ func TestFileWatcher(t *testing.T) {
filenames = append(filenames, filename)
}

watcher := New(filenames...)
watcher := New(logptest.NewTestingLogger(t, ""), filenames...)

// Modification timestamps usually have second precision,
// we wait to make sure we're not in the second the files were created
Expand Down
2 changes: 1 addition & 1 deletion service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
}()

// Handle the Windows service events
go ProcessWindowsControlEvents(func() {
go ProcessWindowsControlEvents(logger, func() {
logger.Info("Received Windows SVC stop/shutdown request")
callback.Do(stopFunction)
})
Expand Down Expand Up @@ -125,7 +125,7 @@

go func() {
// Serve returns always a non-nil error
err := http.Serve(listener, mux)

Check failure on line 128 in service/service.go

View workflow job for this annotation

GitHub Actions / lint (ubuntu-latest)

G114: Use of net/http serve function that has no support for setting timeouts (gosec)
logger.Infof("Finished pprof endpoint: %v", err)
}()
}
Expand Down
4 changes: 3 additions & 1 deletion service/service_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@

package service

import "github.com/elastic/elastic-agent-libs/logp"

// ProcessWindowsControlEvents is not used on non-windows platforms.
func ProcessWindowsControlEvents(stopCallback func()) {
func ProcessWindowsControlEvents(logger *logp.Logger, stopCallback func()) {
}

func notifyWindowsServiceStopped() {
Expand Down
10 changes: 5 additions & 5 deletions service/service_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,16 +122,16 @@ const couldNotConnect syscall.Errno = 1063
// On non-windows platforms, the function does nothing. The
// stopCallback function is called when the Stop/Shutdown
// request is received.
func ProcessWindowsControlEvents(stopCallback func()) {
func ProcessWindowsControlEvents(logger *logp.Logger, stopCallback func()) {
defer close(serviceInstance.executeFinished)

//nolint:staticcheck // keep using the deprecated method in order to maintain the existing behavior
isInteractive, err := svc.IsAnInteractiveSession()
if err != nil {
logp.Err("IsAnInteractiveSession: %v", err)
logger.Errorf("IsAnInteractiveSession: %v", err)
return
}
logp.Debug("service", "Windows is interactive: %v", isInteractive)
logger.Named("service")..Debugf("Windows is interactive: %v", isInteractive)

run := svc.Run
if isInteractive {
Expand Down Expand Up @@ -160,11 +160,11 @@ func ProcessWindowsControlEvents(stopCallback func()) {
If the program will be run as a console application for debugging purposes, structure it such that
service-specific code is not called when this error is returned."
*/
logp.Info("Attempted to register Windows service handlers, but this is not a service. No action necessary")
logger.Info("Attempted to register Windows service handlers, but this is not a service. No action necessary")
return
}

logp.Err("Windows service setup failed: %+v", err)
logger.Errorf("Windows service setup failed: %+v", err)
}

// WaitExecutionDone returns only after stop was reported to service manager.
Expand Down
Loading