From 4bd9de29dfbf9e8c775741425781e5502214ed46 Mon Sep 17 00:00:00 2001 From: Spencer Ugbo Date: Thu, 27 Nov 2025 11:09:22 +0000 Subject: [PATCH 1/3] make max access log file configurable --- internal/config/config.go | 7 +++ internal/config/defaults.go | 1 + internal/config/flags.go | 1 + internal/config/types.go | 27 +++++---- .../datasource/config/nginx_config_parser.go | 15 ++++- .../config/nginx_config_parser_test.go | 55 ++++++++++++++++++- 6 files changed, 90 insertions(+), 16 deletions(-) diff --git a/internal/config/config.go b/internal/config/config.go index 242bf6671..284583229 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -158,6 +158,7 @@ func ResolveConfig() (*Config, error) { Labels: resolveLabels(), LibDir: viperInstance.GetString(LibDirPathKey), SyslogServer: resolveSyslogServer(), + MaxAccessLogFiles: viperInstance.GetInt(MaxAccessLogFilesKey), } defaultCollector(collector, config) @@ -469,6 +470,12 @@ func registerFlags() { "The port Agent will start the syslog server on for logs collection", ) + fs.Int( + MaxAccessLogFilesKey, + DefMaxAccessLogFiles, + "The maximum number of access log files to monitor", + ) + registerCommonFlags(fs) registerCommandFlags(fs) registerAuxiliaryCommandFlags(fs) diff --git a/internal/config/defaults.go b/internal/config/defaults.go index 0f1e08075..1cb9bf943 100644 --- a/internal/config/defaults.go +++ b/internal/config/defaults.go @@ -15,6 +15,7 @@ const ( DefNginxReloadMonitoringPeriod = 10 * time.Second DefTreatErrorsAsWarnings = false DefNginxApiTlsCa = "" + DefMaxAccessLogFiles = 10 // Nginx Reload Backoff defaults DefNginxReloadBackoffInitialInterval = 500 * time.Millisecond diff --git a/internal/config/flags.go b/internal/config/flags.go index d0f664540..750628312 100644 --- a/internal/config/flags.go +++ b/internal/config/flags.go @@ -25,6 +25,7 @@ const ( InstanceHealthWatcherMonitoringFrequencyKey = "watchers_instance_health_watcher_monitoring_frequency" FileWatcherKey = "watchers_file_watcher" LibDirPathKey = "lib_dir" + MaxAccessLogFilesKey = "max_access_log_files" ) var ( diff --git a/internal/config/types.go b/internal/config/types.go index 72eda1369..f7b71b9d8 100644 --- a/internal/config/types.go +++ b/internal/config/types.go @@ -36,21 +36,22 @@ func parseServerType(str string) (ServerType, bool) { type ( Config struct { - Command *Command `yaml:"command" mapstructure:"command"` - AuxiliaryCommand *Command `yaml:"auxiliary_command" mapstructure:"auxiliary_command"` - Log *Log `yaml:"log" mapstructure:"log"` - DataPlaneConfig *DataPlaneConfig `yaml:"data_plane_config" mapstructure:"data_plane_config"` - Client *Client `yaml:"client" mapstructure:"client"` - Collector *Collector `yaml:"collector" mapstructure:"collector"` - Watchers *Watchers `yaml:"watchers" mapstructure:"watchers"` - SyslogServer *SyslogServer `yaml:"syslog_server" mapstructure:"syslog_server"` - Labels map[string]any `yaml:"labels" mapstructure:"labels"` + Command *Command `yaml:"command" mapstructure:"command"` + AuxiliaryCommand *Command `yaml:"auxiliary_command" mapstructure:"auxiliary_command"` + Log *Log `yaml:"log" mapstructure:"log"` + DataPlaneConfig *DataPlaneConfig `yaml:"data_plane_config" mapstructure:"data_plane_config"` + Client *Client `yaml:"client" mapstructure:"client"` + Collector *Collector `yaml:"collector" mapstructure:"collector"` + Watchers *Watchers `yaml:"watchers" mapstructure:"watchers"` + SyslogServer *SyslogServer `yaml:"syslog_server" mapstructure:"syslog_server"` + Labels map[string]any `yaml:"labels" mapstructure:"labels"` Version string `yaml:"-"` Path string `yaml:"-"` UUID string `yaml:"-"` LibDir string `yaml:"-"` - AllowedDirectories []string `yaml:"allowed_directories" mapstructure:"allowed_directories"` - Features []string `yaml:"features" mapstructure:"features"` + AllowedDirectories []string `yaml:"allowed_directories" mapstructure:"allowed_directories"` + Features []string `yaml:"features" mapstructure:"features"` + MaxAccessLogFiles int `yaml:"max_access_log_files" mapstructure:"max_access_log_files"` } Log struct { @@ -477,6 +478,10 @@ func (c *Config) IsCommandServerProxyConfigured() bool { return c.Command.Server.Proxy.URL != "" } +func (c *Config) IsMaxAccessLogFilesConfigured() bool { + return c.MaxAccessLogFiles != 0 +} + // isAllowedDir checks if the given path is in the list of allowed directories. // It recursively checks the parent directories of the path, until it finds a match or reaches the root directory. func isAllowedDir(path string, allowedDirs []string) bool { diff --git a/internal/datasource/config/nginx_config_parser.go b/internal/datasource/config/nginx_config_parser.go index 057821119..d234e4795 100644 --- a/internal/datasource/config/nginx_config_parser.go +++ b/internal/datasource/config/nginx_config_parser.go @@ -228,7 +228,13 @@ func (ncp *NginxConfigParser) createNginxConfigContext( if !ncp.ignoreLog(directive.Args[0]) { accessLog := ncp.accessLog(directive.Args[0], ncp.accessLogDirectiveFormat(directive), formatMap) - nginxConfigContext.AccessLogs = ncp.addAccessLog(accessLog, nginxConfigContext.AccessLogs) + if ncp.agentConfig.IsMaxAccessLogFilesConfigured() { + nginxConfigContext.AccessLogs = ncp.addAccessLog(accessLog, + nginxConfigContext.AccessLogs, ncp.agentConfig.MaxAccessLogFiles) + } else { + nginxConfigContext.AccessLogs = ncp.addAccessLog(accessLog, + nginxConfigContext.AccessLogs, config.DefMaxAccessLogFiles) + } } case "error_log": if !ncp.ignoreLog(directive.Args[0]) { @@ -344,7 +350,7 @@ func (ncp *NginxConfigParser) parseIncludeDirective( } func (ncp *NginxConfigParser) addAccessLog(accessLog *model.AccessLog, - accessLogs []*model.AccessLog, + accessLogs []*model.AccessLog, maxAccessLogFiles int, ) []*model.AccessLog { for i, log := range accessLogs { if accessLog.Name == log.Name { @@ -361,6 +367,11 @@ func (ncp *NginxConfigParser) addAccessLog(accessLog *model.AccessLog, } } + if len(accessLogs) >= maxAccessLogFiles { + slog.Warn("Maximum access log files have been reached, additional logs will be skipped") + return accessLogs + } + slog.Debug("Found valid access log", "access_log", accessLog.Name) return append(accessLogs, accessLog) diff --git a/internal/datasource/config/nginx_config_parser_test.go b/internal/datasource/config/nginx_config_parser_test.go index 37e915ab3..d19e365a4 100644 --- a/internal/datasource/config/nginx_config_parser_test.go +++ b/internal/datasource/config/nginx_config_parser_test.go @@ -755,6 +755,7 @@ func TestNginxConfigParser_checkLog(t *testing.T) { accessLog *model.AccessLog currentAccessLogs []*model.AccessLog expectedAccessLogs []*model.AccessLog + maxAccessLogFiles int }{ { name: "Test 1: valid access log", @@ -790,7 +791,8 @@ func TestNginxConfigParser_checkLog(t *testing.T) { Readable: true, }, }, - expectedLog: "Found valid access log", + expectedLog: "Found valid access log", + maxAccessLogFiles: 3, }, { name: "Test 2: Duplicate access log, with same format", @@ -819,7 +821,8 @@ func TestNginxConfigParser_checkLog(t *testing.T) { Readable: true, }, }, - expectedLog: "Found duplicate access log, skipping", + expectedLog: "Found duplicate access log, skipping", + maxAccessLogFiles: 3, }, { @@ -844,13 +847,59 @@ func TestNginxConfigParser_checkLog(t *testing.T) { expectedLog: "Found multiple log_format directives for the same access log. " + "Multiple log formats are not supported in the same access log, metrics from this access log " + "will not be collected", + maxAccessLogFiles: 3, + }, + + { + name: "Test 4: valid access log, maximum access logs reached", + accessLog: &model.AccessLog{ + Name: "/var/log/nginx/access3.log", + Format: "$remote_addr - $remote_user [$time_local] \"$request\" \"$http_user_agent\" " + + "\"$http_x_forwarded_for\"$status $body_bytes_sent \"$http_referer\"", + Permissions: "", + Readable: true, + }, + currentAccessLogs: []*model.AccessLog{ + { + Name: "/var/log/nginx/access.log", + Format: "$remote_addr - $remote_user [$time_local] \"$request\" \"$http_user_agent\" " + + "\"$http_x_forwarded_for\"$status $body_bytes_sent \"$http_referer\"", + Permissions: "", + Readable: true, + }, + { + Name: "/var/log/nginx/access2.log", + Format: "$remote_addr - $remote_user [$time_local] \"$request\" \"$http_user_agent\" " + + "\"$http_x_forwarded_for\"$status $body_bytes_sent \"$http_referer\"", + Permissions: "", + Readable: true, + }, + }, + expectedAccessLogs: []*model.AccessLog{ + { + Name: "/var/log/nginx/access.log", + Format: "$remote_addr - $remote_user [$time_local] \"$request\" \"$http_user_agent\" " + + "\"$http_x_forwarded_for\"$status $body_bytes_sent \"$http_referer\"", + Permissions: "", + Readable: true, + }, + { + Name: "/var/log/nginx/access2.log", + Format: "$remote_addr - $remote_user [$time_local] \"$request\" \"$http_user_agent\" " + + "\"$http_x_forwarded_for\"$status $body_bytes_sent \"$http_referer\"", + Permissions: "", + Readable: true, + }, + }, + expectedLog: "Maximum access log files have been reached, additional logs will be skipped", + maxAccessLogFiles: 2, }, } for _, test := range tests { t.Run(test.name, func(t *testing.T) { ncp := NewNginxConfigParser(types.AgentConfig()) - logs := ncp.addAccessLog(test.accessLog, test.currentAccessLogs) + logs := ncp.addAccessLog(test.accessLog, test.currentAccessLogs, test.maxAccessLogFiles) assert.Equal(t, test.expectedAccessLogs, logs) helpers.ValidateLog(t, test.expectedLog, logBuf) From 7e3379ebfb056084b2500f33addc3288c6bf9645 Mon Sep 17 00:00:00 2001 From: Spencer Ugbo Date: Fri, 5 Dec 2025 16:33:27 +0000 Subject: [PATCH 2/3] refactor max access file definition --- api/grpc/mpi/v1/command_grpc.pb.go | 12 ++++---- api/grpc/mpi/v1/files_grpc.pb.go | 16 +++++------ internal/config/config.go | 2 +- internal/config/flags.go | 2 +- internal/config/types.go | 28 ++++++++----------- .../datasource/config/nginx_config_parser.go | 16 ++++------- .../config/nginx_config_parser_test.go | 5 ++-- test/types/config.go | 1 + 8 files changed, 38 insertions(+), 44 deletions(-) diff --git a/api/grpc/mpi/v1/command_grpc.pb.go b/api/grpc/mpi/v1/command_grpc.pb.go index dbf61a337..ba20831d9 100644 --- a/api/grpc/mpi/v1/command_grpc.pb.go +++ b/api/grpc/mpi/v1/command_grpc.pb.go @@ -8,7 +8,7 @@ // Code generated by protoc-gen-go-grpc. DO NOT EDIT. // versions: -// - protoc-gen-go-grpc v1.5.1 +// - protoc-gen-go-grpc v1.6.0 // - protoc (unknown) // source: mpi/v1/command.proto @@ -144,16 +144,16 @@ type CommandServiceServer interface { type UnimplementedCommandServiceServer struct{} func (UnimplementedCommandServiceServer) CreateConnection(context.Context, *CreateConnectionRequest) (*CreateConnectionResponse, error) { - return nil, status.Errorf(codes.Unimplemented, "method CreateConnection not implemented") + return nil, status.Error(codes.Unimplemented, "method CreateConnection not implemented") } func (UnimplementedCommandServiceServer) UpdateDataPlaneStatus(context.Context, *UpdateDataPlaneStatusRequest) (*UpdateDataPlaneStatusResponse, error) { - return nil, status.Errorf(codes.Unimplemented, "method UpdateDataPlaneStatus not implemented") + return nil, status.Error(codes.Unimplemented, "method UpdateDataPlaneStatus not implemented") } func (UnimplementedCommandServiceServer) UpdateDataPlaneHealth(context.Context, *UpdateDataPlaneHealthRequest) (*UpdateDataPlaneHealthResponse, error) { - return nil, status.Errorf(codes.Unimplemented, "method UpdateDataPlaneHealth not implemented") + return nil, status.Error(codes.Unimplemented, "method UpdateDataPlaneHealth not implemented") } func (UnimplementedCommandServiceServer) Subscribe(grpc.BidiStreamingServer[DataPlaneResponse, ManagementPlaneRequest]) error { - return status.Errorf(codes.Unimplemented, "method Subscribe not implemented") + return status.Error(codes.Unimplemented, "method Subscribe not implemented") } func (UnimplementedCommandServiceServer) testEmbeddedByValue() {} @@ -165,7 +165,7 @@ type UnsafeCommandServiceServer interface { } func RegisterCommandServiceServer(s grpc.ServiceRegistrar, srv CommandServiceServer) { - // If the following call pancis, it indicates UnimplementedCommandServiceServer was + // If the following call panics, it indicates UnimplementedCommandServiceServer was // embedded by pointer and is nil. This will cause panics if an // unimplemented method is ever invoked, so we test this at initialization // time to prevent it from happening at runtime later due to I/O. diff --git a/api/grpc/mpi/v1/files_grpc.pb.go b/api/grpc/mpi/v1/files_grpc.pb.go index 69efda491..80ed54f75 100644 --- a/api/grpc/mpi/v1/files_grpc.pb.go +++ b/api/grpc/mpi/v1/files_grpc.pb.go @@ -5,7 +5,7 @@ // Code generated by protoc-gen-go-grpc. DO NOT EDIT. // versions: -// - protoc-gen-go-grpc v1.5.1 +// - protoc-gen-go-grpc v1.6.0 // - protoc (unknown) // source: mpi/v1/files.proto @@ -174,22 +174,22 @@ type FileServiceServer interface { type UnimplementedFileServiceServer struct{} func (UnimplementedFileServiceServer) GetOverview(context.Context, *GetOverviewRequest) (*GetOverviewResponse, error) { - return nil, status.Errorf(codes.Unimplemented, "method GetOverview not implemented") + return nil, status.Error(codes.Unimplemented, "method GetOverview not implemented") } func (UnimplementedFileServiceServer) UpdateOverview(context.Context, *UpdateOverviewRequest) (*UpdateOverviewResponse, error) { - return nil, status.Errorf(codes.Unimplemented, "method UpdateOverview not implemented") + return nil, status.Error(codes.Unimplemented, "method UpdateOverview not implemented") } func (UnimplementedFileServiceServer) GetFile(context.Context, *GetFileRequest) (*GetFileResponse, error) { - return nil, status.Errorf(codes.Unimplemented, "method GetFile not implemented") + return nil, status.Error(codes.Unimplemented, "method GetFile not implemented") } func (UnimplementedFileServiceServer) UpdateFile(context.Context, *UpdateFileRequest) (*UpdateFileResponse, error) { - return nil, status.Errorf(codes.Unimplemented, "method UpdateFile not implemented") + return nil, status.Error(codes.Unimplemented, "method UpdateFile not implemented") } func (UnimplementedFileServiceServer) GetFileStream(*GetFileRequest, grpc.ServerStreamingServer[FileDataChunk]) error { - return status.Errorf(codes.Unimplemented, "method GetFileStream not implemented") + return status.Error(codes.Unimplemented, "method GetFileStream not implemented") } func (UnimplementedFileServiceServer) UpdateFileStream(grpc.ClientStreamingServer[FileDataChunk, UpdateFileResponse]) error { - return status.Errorf(codes.Unimplemented, "method UpdateFileStream not implemented") + return status.Error(codes.Unimplemented, "method UpdateFileStream not implemented") } func (UnimplementedFileServiceServer) testEmbeddedByValue() {} @@ -201,7 +201,7 @@ type UnsafeFileServiceServer interface { } func RegisterFileServiceServer(s grpc.ServiceRegistrar, srv FileServiceServer) { - // If the following call pancis, it indicates UnimplementedFileServiceServer was + // If the following call panics, it indicates UnimplementedFileServiceServer was // embedded by pointer and is nil. This will cause panics if an // unimplemented method is ever invoked, so we test this at initialization // time to prevent it from happening at runtime later due to I/O. diff --git a/internal/config/config.go b/internal/config/config.go index 284583229..ac05c5ad6 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -158,7 +158,6 @@ func ResolveConfig() (*Config, error) { Labels: resolveLabels(), LibDir: viperInstance.GetString(LibDirPathKey), SyslogServer: resolveSyslogServer(), - MaxAccessLogFiles: viperInstance.GetInt(MaxAccessLogFilesKey), } defaultCollector(collector, config) @@ -1098,6 +1097,7 @@ func resolveDataPlaneConfig() *DataPlaneConfig { RandomizationFactor: viperInstance.GetFloat64(NginxReloadBackoffRandomizationFactorKey), Multiplier: viperInstance.GetFloat64(NginxReloadBackoffMultiplierKey), }, + MaxAccessLogFiles: viperInstance.GetInt(MaxAccessLogFilesKey), }, } } diff --git a/internal/config/flags.go b/internal/config/flags.go index 750628312..a46656b06 100644 --- a/internal/config/flags.go +++ b/internal/config/flags.go @@ -25,7 +25,6 @@ const ( InstanceHealthWatcherMonitoringFrequencyKey = "watchers_instance_health_watcher_monitoring_frequency" FileWatcherKey = "watchers_file_watcher" LibDirPathKey = "lib_dir" - MaxAccessLogFilesKey = "max_access_log_files" ) var ( @@ -137,6 +136,7 @@ var ( NginxReloadBackoffMultiplierKey = pre(NginxReloadBackoffKey) + "multiplier" NginxExcludeLogsKey = pre(DataPlaneConfigRootKey, "nginx") + "exclude_logs" NginxApiTlsCa = pre(DataPlaneConfigRootKey, "nginx") + "api_tls_ca" + MaxAccessLogFilesKey = pre(DataPlaneConfigRootKey, "nginx") + "max_access_log_files" SyslogServerPort = pre("syslog_server") + "port" diff --git a/internal/config/types.go b/internal/config/types.go index f7b71b9d8..8873537bc 100644 --- a/internal/config/types.go +++ b/internal/config/types.go @@ -36,22 +36,21 @@ func parseServerType(str string) (ServerType, bool) { type ( Config struct { - Command *Command `yaml:"command" mapstructure:"command"` - AuxiliaryCommand *Command `yaml:"auxiliary_command" mapstructure:"auxiliary_command"` - Log *Log `yaml:"log" mapstructure:"log"` - DataPlaneConfig *DataPlaneConfig `yaml:"data_plane_config" mapstructure:"data_plane_config"` - Client *Client `yaml:"client" mapstructure:"client"` - Collector *Collector `yaml:"collector" mapstructure:"collector"` - Watchers *Watchers `yaml:"watchers" mapstructure:"watchers"` - SyslogServer *SyslogServer `yaml:"syslog_server" mapstructure:"syslog_server"` - Labels map[string]any `yaml:"labels" mapstructure:"labels"` + Command *Command `yaml:"command" mapstructure:"command"` + AuxiliaryCommand *Command `yaml:"auxiliary_command" mapstructure:"auxiliary_command"` + Log *Log `yaml:"log" mapstructure:"log"` + DataPlaneConfig *DataPlaneConfig `yaml:"data_plane_config" mapstructure:"data_plane_config"` + Client *Client `yaml:"client" mapstructure:"client"` + Collector *Collector `yaml:"collector" mapstructure:"collector"` + Watchers *Watchers `yaml:"watchers" mapstructure:"watchers"` + SyslogServer *SyslogServer `yaml:"syslog_server" mapstructure:"syslog_server"` + Labels map[string]any `yaml:"labels" mapstructure:"labels"` Version string `yaml:"-"` Path string `yaml:"-"` UUID string `yaml:"-"` LibDir string `yaml:"-"` - AllowedDirectories []string `yaml:"allowed_directories" mapstructure:"allowed_directories"` - Features []string `yaml:"features" mapstructure:"features"` - MaxAccessLogFiles int `yaml:"max_access_log_files" mapstructure:"max_access_log_files"` + AllowedDirectories []string `yaml:"allowed_directories" mapstructure:"allowed_directories"` + Features []string `yaml:"features" mapstructure:"features"` } Log struct { @@ -72,6 +71,7 @@ type ( ExcludeLogs []string `yaml:"exclude_logs" mapstructure:"exclude_logs"` ReloadMonitoringPeriod time.Duration `yaml:"reload_monitoring_period" mapstructure:"reload_monitoring_period"` TreatWarningsAsErrors bool `yaml:"treat_warnings_as_errors" mapstructure:"treat_warnings_as_errors"` + MaxAccessLogFiles int `yaml:"max_access_log_files" mapstructure:"max_access_log_files"` } Client struct { @@ -478,10 +478,6 @@ func (c *Config) IsCommandServerProxyConfigured() bool { return c.Command.Server.Proxy.URL != "" } -func (c *Config) IsMaxAccessLogFilesConfigured() bool { - return c.MaxAccessLogFiles != 0 -} - // isAllowedDir checks if the given path is in the list of allowed directories. // It recursively checks the parent directories of the path, until it finds a match or reaches the root directory. func isAllowedDir(path string, allowedDirs []string) bool { diff --git a/internal/datasource/config/nginx_config_parser.go b/internal/datasource/config/nginx_config_parser.go index d234e4795..3cd41acc9 100644 --- a/internal/datasource/config/nginx_config_parser.go +++ b/internal/datasource/config/nginx_config_parser.go @@ -228,13 +228,7 @@ func (ncp *NginxConfigParser) createNginxConfigContext( if !ncp.ignoreLog(directive.Args[0]) { accessLog := ncp.accessLog(directive.Args[0], ncp.accessLogDirectiveFormat(directive), formatMap) - if ncp.agentConfig.IsMaxAccessLogFilesConfigured() { - nginxConfigContext.AccessLogs = ncp.addAccessLog(accessLog, - nginxConfigContext.AccessLogs, ncp.agentConfig.MaxAccessLogFiles) - } else { - nginxConfigContext.AccessLogs = ncp.addAccessLog(accessLog, - nginxConfigContext.AccessLogs, config.DefMaxAccessLogFiles) - } + nginxConfigContext.AccessLogs = ncp.addAccessLog(accessLog, nginxConfigContext.AccessLogs) } case "error_log": if !ncp.ignoreLog(directive.Args[0]) { @@ -350,7 +344,7 @@ func (ncp *NginxConfigParser) parseIncludeDirective( } func (ncp *NginxConfigParser) addAccessLog(accessLog *model.AccessLog, - accessLogs []*model.AccessLog, maxAccessLogFiles int, + accessLogs []*model.AccessLog, ) []*model.AccessLog { for i, log := range accessLogs { if accessLog.Name == log.Name { @@ -367,8 +361,10 @@ func (ncp *NginxConfigParser) addAccessLog(accessLog *model.AccessLog, } } - if len(accessLogs) >= maxAccessLogFiles { - slog.Warn("Maximum access log files have been reached, additional logs will be skipped") + if len(accessLogs) >= ncp.agentConfig.DataPlaneConfig.Nginx.MaxAccessLogFiles { + slog.Warn("Maximum access log files have been reached, unable to monitor access log", + "access_log", accessLog.Name) + return accessLogs } diff --git a/internal/datasource/config/nginx_config_parser_test.go b/internal/datasource/config/nginx_config_parser_test.go index d19e365a4..9b49137da 100644 --- a/internal/datasource/config/nginx_config_parser_test.go +++ b/internal/datasource/config/nginx_config_parser_test.go @@ -891,7 +891,7 @@ func TestNginxConfigParser_checkLog(t *testing.T) { Readable: true, }, }, - expectedLog: "Maximum access log files have been reached, additional logs will be skipped", + expectedLog: "Maximum access log files have been reached", maxAccessLogFiles: 2, }, } @@ -899,7 +899,8 @@ func TestNginxConfigParser_checkLog(t *testing.T) { for _, test := range tests { t.Run(test.name, func(t *testing.T) { ncp := NewNginxConfigParser(types.AgentConfig()) - logs := ncp.addAccessLog(test.accessLog, test.currentAccessLogs, test.maxAccessLogFiles) + ncp.agentConfig.DataPlaneConfig.Nginx.MaxAccessLogFiles = test.maxAccessLogFiles + logs := ncp.addAccessLog(test.accessLog, test.currentAccessLogs) assert.Equal(t, test.expectedAccessLogs, logs) helpers.ValidateLog(t, test.expectedLog, logBuf) diff --git a/test/types/config.go b/test/types/config.go index 97f2165df..41c103538 100644 --- a/test/types/config.go +++ b/test/types/config.go @@ -169,6 +169,7 @@ func AgentConfig() *config.Config { TreatWarningsAsErrors: true, ReloadMonitoringPeriod: reloadMonitoringPeriod, ExcludeLogs: []string{}, + MaxAccessLogFiles: config.DefMaxAccessLogFiles, }, }, Watchers: &config.Watchers{ From 0e37d36f0f5744bae6d103cd9871a4f59839f446 Mon Sep 17 00:00:00 2001 From: Spencer Ugbo Date: Thu, 18 Dec 2025 17:18:28 +0000 Subject: [PATCH 3/3] update unit test to check for MaxAccessLogFiles --- api/grpc/mpi/v1/command.pb.go | 2 +- api/grpc/mpi/v1/common.pb.go | 2 +- api/grpc/mpi/v1/files.pb.go | 2 +- internal/config/config_test.go | 1 + internal/config/testdata/nginx-agent.conf | 1 + 5 files changed, 5 insertions(+), 3 deletions(-) diff --git a/api/grpc/mpi/v1/command.pb.go b/api/grpc/mpi/v1/command.pb.go index 31e94ea7d..3770775cc 100644 --- a/api/grpc/mpi/v1/command.pb.go +++ b/api/grpc/mpi/v1/command.pb.go @@ -8,7 +8,7 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: -// protoc-gen-go v1.36.10 +// protoc-gen-go v1.36.11 // protoc (unknown) // source: mpi/v1/command.proto diff --git a/api/grpc/mpi/v1/common.pb.go b/api/grpc/mpi/v1/common.pb.go index b59f47b5a..a4fc36217 100644 --- a/api/grpc/mpi/v1/common.pb.go +++ b/api/grpc/mpi/v1/common.pb.go @@ -5,7 +5,7 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: -// protoc-gen-go v1.36.10 +// protoc-gen-go v1.36.11 // protoc (unknown) // source: mpi/v1/common.proto diff --git a/api/grpc/mpi/v1/files.pb.go b/api/grpc/mpi/v1/files.pb.go index 0223bae3a..57fdff253 100644 --- a/api/grpc/mpi/v1/files.pb.go +++ b/api/grpc/mpi/v1/files.pb.go @@ -5,7 +5,7 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: -// protoc-gen-go v1.36.10 +// protoc-gen-go v1.36.11 // protoc (unknown) // source: mpi/v1/files.proto diff --git a/internal/config/config_test.go b/internal/config/config_test.go index 40b6a5969..22cc253d2 100644 --- a/internal/config/config_test.go +++ b/internal/config/config_test.go @@ -1209,6 +1209,7 @@ func createConfig() *Config { RandomizationFactor: 1.5, Multiplier: 1.5, }, + MaxAccessLogFiles: 5, }, }, Collector: &Collector{ diff --git a/internal/config/testdata/nginx-agent.conf b/internal/config/testdata/nginx-agent.conf index 2ac87b9ee..00ddc8ac6 100644 --- a/internal/config/testdata/nginx-agent.conf +++ b/internal/config/testdata/nginx-agent.conf @@ -41,6 +41,7 @@ data_plane_config: max_elapsed_time: 15s randomization_factor: 1.5 multiplier: 1.5 + max_access_log_files: 5 client: http: timeout: 15s