From 22157af0e5dacc0375fdfb153c2d7c88a3be6e1c Mon Sep 17 00:00:00 2001 From: Mike Miranda Date: Thu, 13 Apr 2023 18:45:37 +0000 Subject: [PATCH] Split proc default and validation between Linux and Windows --- pkg/systemstatsmonitor/types/config.go | 4 +-- pkg/systemstatsmonitor/types/config_linux.go | 28 +++++++++++++++++++ .../types/config_windows.go | 24 ++++++++++++++++ 3 files changed, 53 insertions(+), 3 deletions(-) create mode 100644 pkg/systemstatsmonitor/types/config_linux.go create mode 100644 pkg/systemstatsmonitor/types/config_windows.go diff --git a/pkg/systemstatsmonitor/types/config.go b/pkg/systemstatsmonitor/types/config.go index f3306e20..1c916af3 100644 --- a/pkg/systemstatsmonitor/types/config.go +++ b/pkg/systemstatsmonitor/types/config.go @@ -18,7 +18,6 @@ package types import ( "fmt" - "os" "regexp" "time" ) @@ -27,7 +26,6 @@ var ( defaultInvokeIntervalString = (60 * time.Second).String() defaultlsblkTimeoutString = (5 * time.Second).String() defaultKnownModulesConfigPath = "guestosconfig/known-modules.json" - defaultProcPath = "/proc" ) type MetricConfig struct { @@ -135,7 +133,7 @@ func (ssc *SystemStatsConfig) Validate() error { if ssc.InvokeInterval <= time.Duration(0) { return fmt.Errorf("InvokeInterval %v must be above 0s", ssc.InvokeInterval) } - if _, err := os.Stat(ssc.ProcPath); err != nil { + if err := ssc.validateProcPath(); err != nil { return fmt.Errorf("ProcPath %v check failed: %s", ssc.ProcPath, err) } if ssc.DiskConfig.LsblkTimeout <= time.Duration(0) { diff --git a/pkg/systemstatsmonitor/types/config_linux.go b/pkg/systemstatsmonitor/types/config_linux.go new file mode 100644 index 00000000..4d917328 --- /dev/null +++ b/pkg/systemstatsmonitor/types/config_linux.go @@ -0,0 +1,28 @@ +/* +Copyright 2019 The Kubernetes Authors All rights reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package types + +import ( + "os" +) + +const defaultProcPath = "/proc" + +func (ssc *SystemStatsConfig) validateProcPath() error { + _, err := os.Stat(ssc.ProcPath) + return err +} diff --git a/pkg/systemstatsmonitor/types/config_windows.go b/pkg/systemstatsmonitor/types/config_windows.go new file mode 100644 index 00000000..f147be45 --- /dev/null +++ b/pkg/systemstatsmonitor/types/config_windows.go @@ -0,0 +1,24 @@ +/* +Copyright 2019 The Kubernetes Authors All rights reserved. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +package types + +const defaultProcPath = "" + +func (ssc *SystemStatsConfig) validateProcPath() error { + // not supported + return nil +}