Skip to content

Commit

Permalink
Merge pull request kubernetes#557 from vteratipally/adfad
Browse files Browse the repository at this point in the history
Make sure the path to known-modules.json is relative
  • Loading branch information
k8s-ci-robot authored May 14, 2021
2 parents f0ab653 + a79b87c commit 9c54169
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 7 deletions.
2 changes: 1 addition & 1 deletion config/system-stats-monitor.json
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@
}
},
"osFeature": {
"KnownModulesConfigPath": "config/guestosconfig/known-modules.json",
"KnownModulesConfigPath": "guestosconfig/known-modules.json",
"metricsConfigs": {
"system/os_feature": {
"displayName": "system/os_feature"
Expand Down
3 changes: 2 additions & 1 deletion pkg/systemstatsmonitor/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
7 changes: 7 additions & 0 deletions pkg/systemstatsmonitor/system_stats_monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package systemstatsmonitor
import (
"encoding/json"
"io/ioutil"
"path/filepath"
"time"

"github.com/golang/glog"
Expand Down Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion pkg/systemstatsmonitor/system_stats_monitor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.")
}
}
2 changes: 1 addition & 1 deletion pkg/systemstatsmonitor/types/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
6 changes: 3 additions & 3 deletions pkg/systemstatsmonitor/types/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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",
},
},
},
Expand Down

0 comments on commit 9c54169

Please sign in to comment.