Skip to content

Commit 9dcd9a9

Browse files
authored
Fix Add OTel Receiver After Config Apply & Fix Reload Monitoring Old Log (#1057)
1 parent 288b158 commit 9dcd9a9

30 files changed

+988
-559
lines changed

internal/app.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import (
1111

1212
"github.com/nginx/agent/v3/internal/bus"
1313
"github.com/nginx/agent/v3/internal/config"
14-
"github.com/nginx/agent/v3/internal/logger"
1514
"github.com/nginx/agent/v3/internal/plugin"
1615
"github.com/spf13/cobra"
1716
)
@@ -46,9 +45,6 @@ func (a *App) Run(ctx context.Context) error {
4645
return
4746
}
4847

49-
slogger := logger.New(*agentConfig.Log)
50-
slog.SetDefault(slogger)
51-
5248
slog.InfoContext(ctx, "Starting NGINX Agent",
5349
slog.String("version", a.version),
5450
slog.String("commit", a.commit),

internal/collector/nginxossreceiver/internal/scraper/stubstatus/stub_status_scraper.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import (
2525
)
2626

2727
type NginxStubStatusScraper struct {
28+
logger *zap.Logger
2829
httpClient *http.Client
2930
client *client.NginxClient
3031
cfg *config.Config
@@ -50,6 +51,7 @@ func NewScraper(
5051
cfg: cfg,
5152
mb: mb,
5253
rb: rb,
54+
logger: logger,
5355
}
5456
}
5557

@@ -59,6 +61,7 @@ func (s *NginxStubStatusScraper) ID() component.ID {
5961

6062
// nolint: unparam
6163
func (s *NginxStubStatusScraper) Start(_ context.Context, _ component.Host) error {
64+
s.logger.Info("Starting NGINX stub status scraper")
6265
httpClient := http.DefaultClient
6366
httpClient.Timeout = s.cfg.ClientConfig.Timeout
6467

@@ -74,7 +77,9 @@ func (s *NginxStubStatusScraper) Start(_ context.Context, _ component.Host) erro
7477
return nil
7578
}
7679

80+
// nolint: unparam
7781
func (s *NginxStubStatusScraper) Shutdown(_ context.Context) error {
82+
s.logger.Info("Shutting down NGINX stub status scraper")
7883
return nil
7984
}
8085

internal/config/config.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ import (
1919
"strings"
2020
"time"
2121

22-
"github.com/nginx/agent/v3/internal/datasource/host"
23-
2422
"github.com/nginx/agent/v3/internal/datasource/file"
23+
"github.com/nginx/agent/v3/internal/datasource/host"
24+
"github.com/nginx/agent/v3/internal/logger"
2525

2626
"github.com/goccy/go-yaml"
2727
uuidLibrary "github.com/nginx/agent/v3/pkg/id"
@@ -83,6 +83,10 @@ func ResolveConfig() (*Config, error) {
8383
directories := viperInstance.GetStringSlice(AllowedDirectoriesKey)
8484
allowedDirs := []string{AgentDirName}
8585

86+
log := resolveLog()
87+
slogger := logger.New(log.Path, log.Level)
88+
slog.SetDefault(slogger)
89+
8690
// Check directories in allowed_directories are valid
8791
for _, dir := range directories {
8892
if dir == "" || !filepath.IsAbs(dir) {
@@ -111,7 +115,7 @@ func ResolveConfig() (*Config, error) {
111115
UUID: viperInstance.GetString(UUIDKey),
112116
Version: viperInstance.GetString(VersionKey),
113117
Path: viperInstance.GetString(ConfigPathKey),
114-
Log: resolveLog(),
118+
Log: log,
115119
DataPlaneConfig: resolveDataPlaneConfig(),
116120
Client: resolveClient(),
117121
AllowedDirectories: allowedDirs,

internal/datasource/config/configfakes/fake_config_parser.go

Lines changed: 121 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)