Skip to content

Commit 7e3379e

Browse files
committed
refactor max access file definition
1 parent 4bd9de2 commit 7e3379e

File tree

8 files changed

+38
-44
lines changed

8 files changed

+38
-44
lines changed

api/grpc/mpi/v1/command_grpc.pb.go

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

api/grpc/mpi/v1/files_grpc.pb.go

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

internal/config/config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,6 @@ func ResolveConfig() (*Config, error) {
158158
Labels: resolveLabels(),
159159
LibDir: viperInstance.GetString(LibDirPathKey),
160160
SyslogServer: resolveSyslogServer(),
161-
MaxAccessLogFiles: viperInstance.GetInt(MaxAccessLogFilesKey),
162161
}
163162

164163
defaultCollector(collector, config)
@@ -1098,6 +1097,7 @@ func resolveDataPlaneConfig() *DataPlaneConfig {
10981097
RandomizationFactor: viperInstance.GetFloat64(NginxReloadBackoffRandomizationFactorKey),
10991098
Multiplier: viperInstance.GetFloat64(NginxReloadBackoffMultiplierKey),
11001099
},
1100+
MaxAccessLogFiles: viperInstance.GetInt(MaxAccessLogFilesKey),
11011101
},
11021102
}
11031103
}

internal/config/flags.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ const (
2525
InstanceHealthWatcherMonitoringFrequencyKey = "watchers_instance_health_watcher_monitoring_frequency"
2626
FileWatcherKey = "watchers_file_watcher"
2727
LibDirPathKey = "lib_dir"
28-
MaxAccessLogFilesKey = "max_access_log_files"
2928
)
3029

3130
var (
@@ -137,6 +136,7 @@ var (
137136
NginxReloadBackoffMultiplierKey = pre(NginxReloadBackoffKey) + "multiplier"
138137
NginxExcludeLogsKey = pre(DataPlaneConfigRootKey, "nginx") + "exclude_logs"
139138
NginxApiTlsCa = pre(DataPlaneConfigRootKey, "nginx") + "api_tls_ca"
139+
MaxAccessLogFilesKey = pre(DataPlaneConfigRootKey, "nginx") + "max_access_log_files"
140140

141141
SyslogServerPort = pre("syslog_server") + "port"
142142

internal/config/types.go

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -36,22 +36,21 @@ func parseServerType(str string) (ServerType, bool) {
3636

3737
type (
3838
Config struct {
39-
Command *Command `yaml:"command" mapstructure:"command"`
40-
AuxiliaryCommand *Command `yaml:"auxiliary_command" mapstructure:"auxiliary_command"`
41-
Log *Log `yaml:"log" mapstructure:"log"`
42-
DataPlaneConfig *DataPlaneConfig `yaml:"data_plane_config" mapstructure:"data_plane_config"`
43-
Client *Client `yaml:"client" mapstructure:"client"`
44-
Collector *Collector `yaml:"collector" mapstructure:"collector"`
45-
Watchers *Watchers `yaml:"watchers" mapstructure:"watchers"`
46-
SyslogServer *SyslogServer `yaml:"syslog_server" mapstructure:"syslog_server"`
47-
Labels map[string]any `yaml:"labels" mapstructure:"labels"`
39+
Command *Command `yaml:"command" mapstructure:"command"`
40+
AuxiliaryCommand *Command `yaml:"auxiliary_command" mapstructure:"auxiliary_command"`
41+
Log *Log `yaml:"log" mapstructure:"log"`
42+
DataPlaneConfig *DataPlaneConfig `yaml:"data_plane_config" mapstructure:"data_plane_config"`
43+
Client *Client `yaml:"client" mapstructure:"client"`
44+
Collector *Collector `yaml:"collector" mapstructure:"collector"`
45+
Watchers *Watchers `yaml:"watchers" mapstructure:"watchers"`
46+
SyslogServer *SyslogServer `yaml:"syslog_server" mapstructure:"syslog_server"`
47+
Labels map[string]any `yaml:"labels" mapstructure:"labels"`
4848
Version string `yaml:"-"`
4949
Path string `yaml:"-"`
5050
UUID string `yaml:"-"`
5151
LibDir string `yaml:"-"`
52-
AllowedDirectories []string `yaml:"allowed_directories" mapstructure:"allowed_directories"`
53-
Features []string `yaml:"features" mapstructure:"features"`
54-
MaxAccessLogFiles int `yaml:"max_access_log_files" mapstructure:"max_access_log_files"`
52+
AllowedDirectories []string `yaml:"allowed_directories" mapstructure:"allowed_directories"`
53+
Features []string `yaml:"features" mapstructure:"features"`
5554
}
5655

5756
Log struct {
@@ -72,6 +71,7 @@ type (
7271
ExcludeLogs []string `yaml:"exclude_logs" mapstructure:"exclude_logs"`
7372
ReloadMonitoringPeriod time.Duration `yaml:"reload_monitoring_period" mapstructure:"reload_monitoring_period"`
7473
TreatWarningsAsErrors bool `yaml:"treat_warnings_as_errors" mapstructure:"treat_warnings_as_errors"`
74+
MaxAccessLogFiles int `yaml:"max_access_log_files" mapstructure:"max_access_log_files"`
7575
}
7676

7777
Client struct {
@@ -478,10 +478,6 @@ func (c *Config) IsCommandServerProxyConfigured() bool {
478478
return c.Command.Server.Proxy.URL != ""
479479
}
480480

481-
func (c *Config) IsMaxAccessLogFilesConfigured() bool {
482-
return c.MaxAccessLogFiles != 0
483-
}
484-
485481
// isAllowedDir checks if the given path is in the list of allowed directories.
486482
// It recursively checks the parent directories of the path, until it finds a match or reaches the root directory.
487483
func isAllowedDir(path string, allowedDirs []string) bool {

internal/datasource/config/nginx_config_parser.go

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -228,13 +228,7 @@ func (ncp *NginxConfigParser) createNginxConfigContext(
228228
if !ncp.ignoreLog(directive.Args[0]) {
229229
accessLog := ncp.accessLog(directive.Args[0], ncp.accessLogDirectiveFormat(directive),
230230
formatMap)
231-
if ncp.agentConfig.IsMaxAccessLogFilesConfigured() {
232-
nginxConfigContext.AccessLogs = ncp.addAccessLog(accessLog,
233-
nginxConfigContext.AccessLogs, ncp.agentConfig.MaxAccessLogFiles)
234-
} else {
235-
nginxConfigContext.AccessLogs = ncp.addAccessLog(accessLog,
236-
nginxConfigContext.AccessLogs, config.DefMaxAccessLogFiles)
237-
}
231+
nginxConfigContext.AccessLogs = ncp.addAccessLog(accessLog, nginxConfigContext.AccessLogs)
238232
}
239233
case "error_log":
240234
if !ncp.ignoreLog(directive.Args[0]) {
@@ -350,7 +344,7 @@ func (ncp *NginxConfigParser) parseIncludeDirective(
350344
}
351345

352346
func (ncp *NginxConfigParser) addAccessLog(accessLog *model.AccessLog,
353-
accessLogs []*model.AccessLog, maxAccessLogFiles int,
347+
accessLogs []*model.AccessLog,
354348
) []*model.AccessLog {
355349
for i, log := range accessLogs {
356350
if accessLog.Name == log.Name {
@@ -367,8 +361,10 @@ func (ncp *NginxConfigParser) addAccessLog(accessLog *model.AccessLog,
367361
}
368362
}
369363

370-
if len(accessLogs) >= maxAccessLogFiles {
371-
slog.Warn("Maximum access log files have been reached, additional logs will be skipped")
364+
if len(accessLogs) >= ncp.agentConfig.DataPlaneConfig.Nginx.MaxAccessLogFiles {
365+
slog.Warn("Maximum access log files have been reached, unable to monitor access log",
366+
"access_log", accessLog.Name)
367+
372368
return accessLogs
373369
}
374370

internal/datasource/config/nginx_config_parser_test.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -891,15 +891,16 @@ func TestNginxConfigParser_checkLog(t *testing.T) {
891891
Readable: true,
892892
},
893893
},
894-
expectedLog: "Maximum access log files have been reached, additional logs will be skipped",
894+
expectedLog: "Maximum access log files have been reached",
895895
maxAccessLogFiles: 2,
896896
},
897897
}
898898

899899
for _, test := range tests {
900900
t.Run(test.name, func(t *testing.T) {
901901
ncp := NewNginxConfigParser(types.AgentConfig())
902-
logs := ncp.addAccessLog(test.accessLog, test.currentAccessLogs, test.maxAccessLogFiles)
902+
ncp.agentConfig.DataPlaneConfig.Nginx.MaxAccessLogFiles = test.maxAccessLogFiles
903+
logs := ncp.addAccessLog(test.accessLog, test.currentAccessLogs)
903904
assert.Equal(t, test.expectedAccessLogs, logs)
904905

905906
helpers.ValidateLog(t, test.expectedLog, logBuf)

test/types/config.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ func AgentConfig() *config.Config {
169169
TreatWarningsAsErrors: true,
170170
ReloadMonitoringPeriod: reloadMonitoringPeriod,
171171
ExcludeLogs: []string{},
172+
MaxAccessLogFiles: config.DefMaxAccessLogFiles,
172173
},
173174
},
174175
Watchers: &config.Watchers{

0 commit comments

Comments
 (0)