Skip to content

Commit

Permalink
added tests
Browse files Browse the repository at this point in the history
Signed-off-by: Jan-Otto Kröpke <[email protected]>
  • Loading branch information
jkroepke committed Dec 21, 2024
1 parent 370bfc1 commit 9e859ad
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 7 deletions.
6 changes: 3 additions & 3 deletions cmd/windows_exporter/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ func run() int {
}
}

logger.Debug("Logging has Started")
logger.LogAttrs(ctx, slog.LevelDebug, "logging has Started")

if err = setPriorityWindows(logger, os.Getpid(), *processPriority); err != nil {
logger.Error("failed to set process priority",
Expand Down Expand Up @@ -243,7 +243,7 @@ func run() int {
mux.HandleFunc("GET /debug/pprof/trace", pprof.Trace)
}

logger.InfoContext(ctx, fmt.Sprintf("starting windows_exporter in %s", time.Since(startTime)),
logger.LogAttrs(ctx, slog.LevelInfo, fmt.Sprintf("starting windows_exporter in %s", time.Since(startTime)),
slog.String("version", version.Version),
slog.String("branch", version.Branch),
slog.String("revision", version.GetRevision()),
Expand Down Expand Up @@ -334,7 +334,7 @@ func setPriorityWindows(logger *slog.Logger, pid int, priority string) error {
return nil
}

logger.Debug("setting process priority to " + priority)
logger.LogAttrs(context.Background(), slog.LevelDebug, "setting process priority to "+priority)

// https://learn.microsoft.com/en-us/windows/win32/procthread/process-security-and-access-rights
handle, err := windows.OpenProcess(
Expand Down
7 changes: 5 additions & 2 deletions internal/collector/mssql/mssql.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package mssql

import (
"context"
"errors"
"fmt"
"log/slog"
Expand Down Expand Up @@ -373,6 +374,8 @@ func (c *Collector) collect(
) error {
errs := make([]error, 0, len(perfDataCollectors))

ctx := context.Background()

for sqlInstance, perfDataCollector := range perfDataCollectors {
begin := time.Now()
success := 1.0
Expand All @@ -383,11 +386,11 @@ func (c *Collector) collect(
errs = append(errs, err)
success = 0.0

c.logger.Debug(fmt.Sprintf("mssql class collector %s for instance %s failed after %s", collector, sqlInstance, duration),
c.logger.LogAttrs(ctx, slog.LevelDebug, fmt.Sprintf("mssql class collector %s for instance %s failed after %s", collector, sqlInstance, duration),
slog.Any("err", err),
)
} else {
c.logger.Debug(fmt.Sprintf("mssql class collector %s for instance %s succeeded after %s", collector, sqlInstance, duration))
c.logger.LogAttrs(ctx, slog.LevelDebug, fmt.Sprintf("mssql class collector %s for instance %s succeeded after %s", collector, sqlInstance, duration))
}

if collector == "" {
Expand Down
3 changes: 2 additions & 1 deletion internal/collector/process/process_v1.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package process

import (
"context"
"fmt"
"log/slog"
"runtime/debug"
Expand Down Expand Up @@ -118,7 +119,7 @@ func (c *Collector) collectWorkerV1() {

cmdLine, processOwner, processGroupID, err := c.getProcessInformation(uint32(pid))
if err != nil {
c.logger.Debug("Failed to get process information",
slog.LogAttrs(context.Background(), slog.LevelDebug, "Failed to get process information",
slog.Uint64("pid", pid),
slog.Any("err", err),
)
Expand Down
3 changes: 2 additions & 1 deletion internal/collector/process/process_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package process

import (
"context"
"fmt"
"log/slog"
"runtime/debug"
Expand Down Expand Up @@ -118,7 +119,7 @@ func (c *Collector) collectWorkerV2() {

cmdLine, processOwner, processGroupID, err := c.getProcessInformation(uint32(pid))
if err != nil {
c.logger.Debug("Failed to get process information",
slog.LogAttrs(context.Background(), slog.LevelDebug, "Failed to get process information",
slog.Uint64("pid", pid),
slog.Any("err", err),
)
Expand Down

0 comments on commit 9e859ad

Please sign in to comment.