diff --git a/config/system-stats-monitor.json b/config/system-stats-monitor.json index d3aa107dadc16..8b6cf19138037 100644 --- a/config/system-stats-monitor.json +++ b/config/system-stats-monitor.json @@ -92,7 +92,7 @@ } }, "osFeature": { - "KnownModulesConfigPath": "config/guestosconfig/known-modules.json", + "KnownModulesConfigPath": "guestosconfig/known-modules.json", "metricsConfigs": { "system/os_feature": { "displayName": "system/os_feature" diff --git a/pkg/systemstatsmonitor/README.md b/pkg/systemstatsmonitor/README.md index 5f6cfe24ae743..fd807fac20b53 100644 --- a/pkg/systemstatsmonitor/README.md +++ b/pkg/systemstatsmonitor/README.md @@ -92,7 +92,8 @@ UnknownModules are derived from the /proc/modules compared with the known-module And an option: `knownModulesConfigPath`: The path to the file that contains the known modules(default -modules) can be set. By default, the path is set to `known-modules.json` +modules) can be set. By default, the path is set to `guestosconfig/known-modules.json` +(relative to the system-stats-monitor config path). ### IP Stats (Net Dev) diff --git a/pkg/systemstatsmonitor/system_stats_monitor.go b/pkg/systemstatsmonitor/system_stats_monitor.go index 717e9617a150b..f419c6ded7ae8 100644 --- a/pkg/systemstatsmonitor/system_stats_monitor.go +++ b/pkg/systemstatsmonitor/system_stats_monitor.go @@ -19,6 +19,7 @@ package systemstatsmonitor import ( "encoding/json" "io/ioutil" + "path/filepath" "time" "github.com/golang/glog" @@ -89,6 +90,12 @@ func NewSystemStatsMonitorOrDie(configPath string) types.Monitor { ssm.memoryCollector = NewMemoryCollectorOrDie(&ssm.config.MemoryConfig) } if len(ssm.config.OsFeatureConfig.MetricsConfigs) > 0 { + // update the KnownModulesConfigPath to relative the system-stats-monitors path + // only when the KnownModulesConfigPath path is relative + if !filepath.IsAbs(ssm.config.OsFeatureConfig.KnownModulesConfigPath) { + ssm.config.OsFeatureConfig.KnownModulesConfigPath = filepath.Join(filepath.Dir(configPath), + ssm.config.OsFeatureConfig.KnownModulesConfigPath) + } ssm.osFeatureCollector = NewOsFeatureCollectorOrDie(&ssm.config.OsFeatureConfig) } if len(ssm.config.NetConfig.MetricsConfigs) > 0 { diff --git a/pkg/systemstatsmonitor/system_stats_monitor_test.go b/pkg/systemstatsmonitor/system_stats_monitor_test.go index 5beb550cedca8..2f74b81c81d54 100644 --- a/pkg/systemstatsmonitor/system_stats_monitor_test.go +++ b/pkg/systemstatsmonitor/system_stats_monitor_test.go @@ -28,4 +28,4 @@ func TestRegistration(t *testing.T) { assert.NotPanics(t, func() { problemdaemon.GetProblemDaemonHandlerOrDie(SystemStatsMonitorName) }, "System stats monitor failed to register itself as a problem daemon.") -} +} \ No newline at end of file diff --git a/pkg/systemstatsmonitor/types/config.go b/pkg/systemstatsmonitor/types/config.go index 54594f72497d7..e2f265bd2ea7d 100644 --- a/pkg/systemstatsmonitor/types/config.go +++ b/pkg/systemstatsmonitor/types/config.go @@ -24,7 +24,7 @@ import ( var ( defaultInvokeIntervalString = (60 * time.Second).String() defaultlsblkTimeoutString = (5 * time.Second).String() - defaultKnownModulesConfigPath = "config/guestosconfig/known-modules.json" + defaultKnownModulesConfigPath = "guestosconfig/known-modules.json" ) type MetricConfig struct { diff --git a/pkg/systemstatsmonitor/types/config_test.go b/pkg/systemstatsmonitor/types/config_test.go index 31059b9a312a6..ebc933a3ec9b4 100644 --- a/pkg/systemstatsmonitor/types/config_test.go +++ b/pkg/systemstatsmonitor/types/config_test.go @@ -44,7 +44,7 @@ func TestApplyConfiguration(t *testing.T) { LsblkTimeoutString: "5s", }, OsFeatureConfig: OSFeatureStatsConfig{ - KnownModulesConfigPath: "config/guestosconfig/known-modules.json", + KnownModulesConfigPath: "guestosconfig/known-modules.json", }, InvokeIntervalString: "60s", InvokeInterval: 60 * time.Second, @@ -62,7 +62,7 @@ func TestApplyConfiguration(t *testing.T) { LsblkTimeoutString: "5s", }, OsFeatureConfig: OSFeatureStatsConfig{ - KnownModulesConfigPath: "config/guestosconfig/known-modules.json", + KnownModulesConfigPath: "guestosconfig/known-modules.json", }, InvokeIntervalString: "1m0s", InvokeInterval: 60 * time.Second, @@ -79,7 +79,7 @@ func TestApplyConfiguration(t *testing.T) { wantedConfig: SystemStatsConfig{ DiskConfig: DiskStatsConfig{}, OsFeatureConfig: OSFeatureStatsConfig{ - KnownModulesConfigPath: "config/guestosconfig/known-modules.json", + KnownModulesConfigPath: "guestosconfig/known-modules.json", }, }, },