Skip to content

Commit

Permalink
style: unify the command parameter style of koordlet (#348)
Browse files Browse the repository at this point in the history
Signed-off-by: Jason Liu <jasonliu747@gmail.com>
  • Loading branch information
jasonliu747 committed Jul 11, 2022
1 parent 1ab5c99 commit 0d9d9d4
Show file tree
Hide file tree
Showing 14 changed files with 495 additions and 24 deletions.
6 changes: 3 additions & 3 deletions pkg/koordlet/audit/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func NewDefaultConfig() *Config {
}

func (c *Config) InitFlags(fs *flag.FlagSet) {
fs.StringVar(&c.LogDir, "AuditLogDir", c.LogDir, "The dir of audit log")
fs.IntVar(&c.Verbose, "AuditVerbose", c.Verbose, "The verbose of the audit log")
fs.IntVar(&c.MaxDiskSpaceMB, "AuditMaxDiskSpaceMB", c.MaxDiskSpaceMB, "Max disk space occupied of audit log")
fs.StringVar(&c.LogDir, "audit-log-dir", c.LogDir, "The dir of audit log")
fs.IntVar(&c.Verbose, "audit-verbose", c.Verbose, "The verbose of the audit log")
fs.IntVar(&c.MaxDiskSpaceMB, "audit-max-disk-space-mb", c.MaxDiskSpaceMB, "Max disk space occupied of audit log")
}
92 changes: 92 additions & 0 deletions pkg/koordlet/audit/config_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
/*
Copyright 2022 The Koordinator Authors.
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 audit

import (
"flag"
"testing"
"time"

"github.com/stretchr/testify/assert"
)

func Test_NewDefaultConfig(t *testing.T) {
expectConfig := &Config{
LogDir: "/var/log/koordlet",
Verbose: 3,
MaxDiskSpaceMB: 16,
MaxConcurrentReaders: 4,
ActiveReaderTTL: time.Minute * 10,
DefaultEventsLimit: 256,
MaxEventsLimit: 2048,
TickerDuration: time.Minute,
}
defaultConfig := NewDefaultConfig()
assert.Equal(t, expectConfig, defaultConfig)
}

func Test_InitFlags(t *testing.T) {
cmdArgs := []string{
"",
"--audit-log-dir=/tmp/log/koordlet",
"--audit-verbose=4",
"--audit-max-disk-space-mb=32",
}
fs := flag.NewFlagSet(cmdArgs[0], flag.ExitOnError)

type fields struct {
LogDir string
Verbose int
MaxDiskSpaceMB int
}
type args struct {
fs *flag.FlagSet
}
tests := []struct {
name string
fields fields
args args
}{
{
name: "not default",
fields: fields{
LogDir: "/tmp/log/koordlet",
Verbose: 4,
MaxDiskSpaceMB: 32,
},
args: args{fs: fs},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
raw := &Config{
LogDir: tt.fields.LogDir,
Verbose: tt.fields.Verbose,
MaxDiskSpaceMB: tt.fields.MaxDiskSpaceMB,
MaxConcurrentReaders: 4,
ActiveReaderTTL: time.Minute * 10,
DefaultEventsLimit: 256,
MaxEventsLimit: 2048,
TickerDuration: time.Minute,
}
c := NewDefaultConfig()
c.InitFlags(tt.args.fs)
tt.args.fs.Parse(cmdArgs[1:])
assert.Equal(t, raw, c)
})
}
}
4 changes: 2 additions & 2 deletions pkg/koordlet/metriccache/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,6 @@ func NewDefaultConfig() *Config {
}

func (c *Config) InitFlags(fs *flag.FlagSet) {
fs.IntVar(&c.MetricGCIntervalSeconds, "MetricGCIntervalSeconds", c.MetricGCIntervalSeconds, "Collect node metrics interval by seconds")
fs.IntVar(&c.MetricExpireSeconds, "MetricExpireSeconds", c.MetricExpireSeconds, "Collect pod metrics interval by seconds")
fs.IntVar(&c.MetricGCIntervalSeconds, "metric-gc-interval-seconds", c.MetricGCIntervalSeconds, "Collect node metrics interval by seconds")
fs.IntVar(&c.MetricExpireSeconds, "metric-expire-seconds", c.MetricExpireSeconds, "Collect pod metrics interval by seconds")
}
76 changes: 76 additions & 0 deletions pkg/koordlet/metriccache/config_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/*
Copyright 2022 The Koordinator Authors.
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 metriccache

import (
"flag"
"testing"

"github.com/stretchr/testify/assert"
)

func Test_NewDefaultConfig(t *testing.T) {
expectConfig := &Config{
MetricGCIntervalSeconds: 300,
MetricExpireSeconds: 1800,
}
defaultConfig := NewDefaultConfig()
assert.Equal(t, expectConfig, defaultConfig)
}

func Test_InitFlags(t *testing.T) {
cmdArgs := []string{
"",
"--metric-gc-interval-seconds=100",
"--metric-expire-seconds=600",
}
fs := flag.NewFlagSet(cmdArgs[0], flag.ExitOnError)

type fields struct {
MetricGCIntervalSeconds int
MetricExpireSeconds int
}
type args struct {
fs *flag.FlagSet
}
tests := []struct {
name string
fields fields
args args
}{
{
name: "not default",
fields: fields{
MetricGCIntervalSeconds: 100,
MetricExpireSeconds: 600,
},
args: args{fs: fs},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
raw := &Config{
MetricGCIntervalSeconds: tt.fields.MetricGCIntervalSeconds,
MetricExpireSeconds: tt.fields.MetricExpireSeconds,
}
c := NewDefaultConfig()
c.InitFlags(tt.args.fs)
tt.args.fs.Parse(cmdArgs[1:])
assert.Equal(t, raw, c)
})
}
}
4 changes: 2 additions & 2 deletions pkg/koordlet/metricsadvisor/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,6 @@ func NewDefaultConfig() *Config {
}

func (c *Config) InitFlags(fs *flag.FlagSet) {
fs.IntVar(&c.CollectResUsedIntervalSeconds, "CollectResUsedIntervalSeconds", c.CollectResUsedIntervalSeconds, "Collect node/pod resource usage interval by seconds")
fs.IntVar(&c.CollectNodeCPUInfoIntervalSeconds, "CollectNodeCPUInfoIntervalSeconds", c.CollectNodeCPUInfoIntervalSeconds, "Collect node cpu info interval by seconds")
fs.IntVar(&c.CollectResUsedIntervalSeconds, "collect-res-used-interval-seconds", c.CollectResUsedIntervalSeconds, "Collect node/pod resource usage interval by seconds")
fs.IntVar(&c.CollectNodeCPUInfoIntervalSeconds, "collect-node-cpu-info-interval-seconds", c.CollectNodeCPUInfoIntervalSeconds, "Collect node cpu info interval by seconds")
}
44 changes: 44 additions & 0 deletions pkg/koordlet/metricsadvisor/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ limitations under the License.
package metricsadvisor

import (
"flag"
"testing"

"github.com/stretchr/testify/assert"
Expand All @@ -30,3 +31,46 @@ func Test_NewDefaultConfig(t *testing.T) {
defaultConfig := NewDefaultConfig()
assert.Equal(t, expectConfig, defaultConfig)
}

func Test_InitFlags(t *testing.T) {
cmdArgs := []string{
"",
"--collect-res-used-interval-seconds=3",
"--collect-node-cpu-info-interval-seconds=90",
}
fs := flag.NewFlagSet(cmdArgs[0], flag.ExitOnError)

type fields struct {
CollectResUsedIntervalSeconds int
CollectNodeCPUInfoIntervalSeconds int
}
type args struct {
fs *flag.FlagSet
}
tests := []struct {
name string
fields fields
args args
}{
{
name: "not default",
fields: fields{
CollectResUsedIntervalSeconds: 3,
CollectNodeCPUInfoIntervalSeconds: 90,
},
args: args{fs: fs},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
raw := &Config{
CollectResUsedIntervalSeconds: tt.fields.CollectResUsedIntervalSeconds,
CollectNodeCPUInfoIntervalSeconds: tt.fields.CollectNodeCPUInfoIntervalSeconds,
}
c := NewDefaultConfig()
c.InitFlags(tt.args.fs)
tt.args.fs.Parse(cmdArgs[1:])
assert.Equal(t, raw, c)
})
}
}
2 changes: 1 addition & 1 deletion pkg/koordlet/reporter/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,5 @@ func NewDefaultConfig() *Config {
}

func (c *Config) InitFlags(fs *flag.FlagSet) {
fs.IntVar(&c.ReportIntervalSeconds, "ReportIntervalSeconds", c.ReportIntervalSeconds, "Report interval by seconds")
fs.IntVar(&c.ReportIntervalSeconds, "report-interval-seconds", c.ReportIntervalSeconds, "Report interval by seconds")
}
67 changes: 67 additions & 0 deletions pkg/koordlet/reporter/config_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*
Copyright 2022 The Koordinator Authors.
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 reporter

import (
"flag"
"testing"

"github.com/stretchr/testify/assert"
)

func Test_NewDefaultConfig(t *testing.T) {
expectConfig := &Config{
ReportIntervalSeconds: 60,
}
defaultConfig := NewDefaultConfig()
assert.Equal(t, expectConfig, defaultConfig)
}

func Test_InitFlags(t *testing.T) {
cmdArgs := []string{
"",
"--report-interval-seconds=30",
}
fs := flag.NewFlagSet(cmdArgs[0], flag.ExitOnError)

type fields struct {
ReportIntervalSeconds int
}
type args struct {
fs *flag.FlagSet
}
tests := []struct {
name string
fields fields
args args
}{
{
name: "not default",
fields: fields{ReportIntervalSeconds: 30},
args: args{fs: fs},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
raw := &Config{ReportIntervalSeconds: tt.fields.ReportIntervalSeconds}
c := NewDefaultConfig()
c.InitFlags(tt.args.fs)
tt.args.fs.Parse(cmdArgs[1:])
assert.Equal(t, raw, c)
})
}
}
12 changes: 6 additions & 6 deletions pkg/koordlet/resmanager/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ func NewDefaultConfig() *Config {
}

func (c *Config) InitFlags(fs *flag.FlagSet) {
fs.IntVar(&c.ReconcileIntervalSeconds, "ReconcileIntervalSeconds", c.ReconcileIntervalSeconds, "reconcile be pod cgroup interval by seconds")
fs.IntVar(&c.CPUSuppressIntervalSeconds, "CPUSuppressIntervalSeconds", c.CPUSuppressIntervalSeconds, "suppress be pod cpu resource interval by seconds")
fs.IntVar(&c.CPUEvictIntervalSeconds, "CPUEvictIntervalSeconds", c.CPUEvictIntervalSeconds, "evict be pod(cpu) interval by seconds")
fs.IntVar(&c.MemoryEvictIntervalSeconds, "MemoryEvictIntervalSeconds", c.MemoryEvictIntervalSeconds, "evict be pod(memory) interval by seconds")
fs.IntVar(&c.MemoryEvictCoolTimeSeconds, "MemoryEvictCoolTimeSeconds", c.MemoryEvictCoolTimeSeconds, "cooling time: memory next evict time should after lastEvictTime + MemoryEvictCoolTimeSeconds")
fs.IntVar(&c.CPUEvictCoolTimeSeconds, "CPUEvictCoolTimeSeconds", c.CPUEvictCoolTimeSeconds, "cooltime: CPU next evict time should after lastEvictTime + CPUEvictCoolTimeSeconds")
fs.IntVar(&c.ReconcileIntervalSeconds, "reconcile-interval-seconds", c.ReconcileIntervalSeconds, "reconcile be pod cgroup interval by seconds")
fs.IntVar(&c.CPUSuppressIntervalSeconds, "cpu-suppress-interval-seconds", c.CPUSuppressIntervalSeconds, "suppress be pod cpu resource interval by seconds")
fs.IntVar(&c.CPUEvictIntervalSeconds, "cpu-evict-interval-seconds", c.CPUEvictIntervalSeconds, "evict be pod(cpu) interval by seconds")
fs.IntVar(&c.MemoryEvictIntervalSeconds, "memory-evict-interval-seconds", c.MemoryEvictIntervalSeconds, "evict be pod(memory) interval by seconds")
fs.IntVar(&c.MemoryEvictCoolTimeSeconds, "memory-evict-cool-time-seconds", c.MemoryEvictCoolTimeSeconds, "cooling time: memory next evict time should after lastEvictTime + MemoryEvictCoolTimeSeconds")
fs.IntVar(&c.CPUEvictCoolTimeSeconds, "cpu-evict-cool-time-seconds", c.CPUEvictCoolTimeSeconds, "cooltime: CPU next evict time should after lastEvictTime + CPUEvictCoolTimeSeconds")
}
Loading

0 comments on commit 0d9d9d4

Please sign in to comment.