Skip to content

feature: add MetricsUpdateIntervalSeconds args option in trimaran plugins #905

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions apis/config/scheme/scheme_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,8 @@ func TestCodecsEncodePluginConfig(t *testing.T) {
Type: config.Prometheus,
Address: "http://prometheus-k8s.monitoring.svc.cluster.local:9090",
},
WatcherAddress: "http://deadbeef:2020"},
MetricsUpdateIntervalSeconds: 30,
WatcherAddress: "http://deadbeef:2020"},
TargetUtilization: 60,
DefaultRequests: corev1.ResourceList{
corev1.ResourceCPU: testCPUQuantity,
Expand All @@ -297,7 +298,8 @@ func TestCodecsEncodePluginConfig(t *testing.T) {
Address: "http://prometheus-k8s.monitoring.svc.cluster.local:9090",
InsecureSkipVerify: false,
},
WatcherAddress: "http://deadbeef:2020"},
MetricsUpdateIntervalSeconds: 30,
WatcherAddress: "http://deadbeef:2020"},
SafeVarianceMargin: v1.DefaultSafeVarianceMargin,
SafeVarianceSensitivity: v1.DefaultSafeVarianceSensitivity,
},
Expand All @@ -311,7 +313,8 @@ func TestCodecsEncodePluginConfig(t *testing.T) {
Address: "http://prometheus-k8s.monitoring.svc.cluster.local:9090",
InsecureSkipVerify: false,
},
WatcherAddress: "http://deadbeef:2020"},
MetricsUpdateIntervalSeconds: 30,
WatcherAddress: "http://deadbeef:2020"},
SmoothingWindowSize: v1.DefaultSmoothingWindowSize,
RiskLimitWeights: map[corev1.ResourceName]float64{
corev1.ResourceCPU: v1.DefaultRiskLimitWeight,
Expand Down Expand Up @@ -387,6 +390,7 @@ profiles:
insecureSkipVerify: false
token: ""
type: Prometheus
metricsUpdateIntervalSeconds: 30
targetUtilization: 60
watcherAddress: http://deadbeef:2020
name: TargetLoadPacking
Expand All @@ -398,6 +402,7 @@ profiles:
insecureSkipVerify: false
token: ""
type: Prometheus
metricsUpdateIntervalSeconds: 30
safeVarianceMargin: 1
safeVarianceSensitivity: 1
watcherAddress: http://deadbeef:2020
Expand All @@ -410,6 +415,7 @@ profiles:
insecureSkipVerify: false
token: ""
type: Prometheus
metricsUpdateIntervalSeconds: 30
riskLimitWeights:
cpu: 0.5
memory: 0.5
Expand Down
2 changes: 2 additions & 0 deletions apis/config/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ type TrimaranSpec struct {
MetricProvider MetricProviderSpec
// Address of load watcher service
WatcherAddress string
// Interval in seconds for periodic metrics updates. Default is 30 seconds if not set.
MetricsUpdateIntervalSeconds int32
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

usually optional values are pointers to let disambiguate between "value not set" and "value explicitely set to zero". In this case, does the zero value make sense? do we have the possible ambiguity? if not we can probably use the value (vs the pointer) but the API side will need more consideration.

}

// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
Expand Down
5 changes: 5 additions & 0 deletions apis/config/v1/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ var (
// DefaultInsecureSkipVerify is whether to skip the certificate verification
DefaultInsecureSkipVerify = true

DefaultMetricsUpdateIntervalSeconds int32 = 30

defaultResourceSpec = []schedulerconfigv1.ResourceSpec{
{Name: string(v1.ResourceCPU), Weight: 1},
{Name: string(v1.ResourceMemory), Weight: 1},
Expand Down Expand Up @@ -133,6 +135,9 @@ func SetDefaultTrimaranSpec(args *TrimaranSpec) {
if args.MetricProvider.Type == Prometheus && args.MetricProvider.InsecureSkipVerify == nil {
args.MetricProvider.InsecureSkipVerify = &DefaultInsecureSkipVerify
}
if args.MetricsUpdateIntervalSeconds == nil {
args.MetricsUpdateIntervalSeconds = &DefaultMetricsUpdateIntervalSeconds
}
}

// SetDefaults_TargetLoadPackingArgs sets the default parameters for TargetLoadPacking plugin
Expand Down
28 changes: 21 additions & 7 deletions apis/config/v1/defaults_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,9 @@ func TestSchedulingDefaults(t *testing.T) {
TrimaranSpec: TrimaranSpec{
MetricProvider: MetricProviderSpec{
Type: "KubernetesMetricsServer",
}},
},
MetricsUpdateIntervalSeconds: pointer.Int32(30),
},
DefaultRequests: v1.ResourceList{v1.ResourceCPU: resource.MustParse(
strconv.FormatInt(DefaultRequestsMilliCores, 10) + "m")},
DefaultRequestsMultiplier: pointer.StringPtr("1.5"),
Expand All @@ -104,7 +106,9 @@ func TestSchedulingDefaults(t *testing.T) {
},
expect: &TargetLoadPackingArgs{
TrimaranSpec: TrimaranSpec{
WatcherAddress: pointer.StringPtr("http://localhost:2020")},
WatcherAddress: pointer.StringPtr("http://localhost:2020"),
MetricsUpdateIntervalSeconds: pointer.Int32(30),
},
DefaultRequests: v1.ResourceList{v1.ResourceCPU: resource.MustParse("100m")},
DefaultRequestsMultiplier: pointer.StringPtr("2.5"),
TargetUtilization: pointer.Int64Ptr(50),
Expand All @@ -117,7 +121,9 @@ func TestSchedulingDefaults(t *testing.T) {
TrimaranSpec: TrimaranSpec{
MetricProvider: MetricProviderSpec{
Type: "KubernetesMetricsServer",
}},
},
MetricsUpdateIntervalSeconds: pointer.Int32(30),
},
SafeVarianceMargin: pointer.Float64Ptr(1.0),
SafeVarianceSensitivity: pointer.Float64Ptr(1.0),
},
Expand All @@ -132,7 +138,9 @@ func TestSchedulingDefaults(t *testing.T) {
TrimaranSpec: TrimaranSpec{
MetricProvider: MetricProviderSpec{
Type: "KubernetesMetricsServer",
}},
},
MetricsUpdateIntervalSeconds: pointer.Int32(30),
},
SafeVarianceMargin: pointer.Float64Ptr(2.0),
SafeVarianceSensitivity: pointer.Float64Ptr(2.0),
},
Expand All @@ -144,7 +152,9 @@ func TestSchedulingDefaults(t *testing.T) {
TrimaranSpec: TrimaranSpec{
MetricProvider: MetricProviderSpec{
Type: "KubernetesMetricsServer",
}},
},
MetricsUpdateIntervalSeconds: pointer.Int32(30),
},
SmoothingWindowSize: pointer.Int64Ptr(5),
RiskLimitWeights: map[v1.ResourceName]float64{
v1.ResourceCPU: 0.5,
Expand All @@ -165,7 +175,9 @@ func TestSchedulingDefaults(t *testing.T) {
TrimaranSpec: TrimaranSpec{
MetricProvider: MetricProviderSpec{
Type: "KubernetesMetricsServer",
}},
},
MetricsUpdateIntervalSeconds: pointer.Int32(30),
},
SmoothingWindowSize: pointer.Int64Ptr(10),
RiskLimitWeights: map[v1.ResourceName]float64{
v1.ResourceCPU: 0.2,
Expand All @@ -186,7 +198,9 @@ func TestSchedulingDefaults(t *testing.T) {
TrimaranSpec: TrimaranSpec{
MetricProvider: MetricProviderSpec{
Type: "KubernetesMetricsServer",
}},
},
MetricsUpdateIntervalSeconds: pointer.Int32(30),
},
SmoothingWindowSize: pointer.Int64Ptr(10),
RiskLimitWeights: map[v1.ResourceName]float64{
v1.ResourceCPU: 0.5,
Expand Down
2 changes: 2 additions & 0 deletions apis/config/v1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ type TrimaranSpec struct {
MetricProvider MetricProviderSpec `json:"metricProvider,omitempty"`
// Address of load watcher service
WatcherAddress *string `json:"watcherAddress,omitempty"`
// Interval in seconds for periodic metrics updates. Default is 30 seconds if not set.
MetricsUpdateIntervalSeconds *int32 `json:"metricsUpdateIntervalSeconds,omitempty"`
}

// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
Expand Down
6 changes: 6 additions & 0 deletions apis/config/v1/zz_generated.conversion.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions apis/config/v1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 7 additions & 2 deletions pkg/trimaran/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import (
)

const (
metricsUpdateIntervalSeconds = 30
defaultMetricsUpdateIntervalSeconds = 30
)

// Collector : get data from load watcher, encapsulating the load watcher and its operations
Expand Down Expand Up @@ -69,6 +69,11 @@ func NewCollector(logger klog.Logger, trimaranSpec *pluginConfig.TrimaranSpec) (
client, _ = loadwatcherapi.NewLibraryClient(opts)
}

metricsUpdateIntervalSeconds := trimaranSpec.MetricsUpdateIntervalSeconds
if metricsUpdateIntervalSeconds == 0 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

int32 can be negative. Do we have some validation preventing negative values?

metricsUpdateIntervalSeconds = defaultMetricsUpdateIntervalSeconds
}

collector := &Collector{
client: client,
}
Expand All @@ -80,7 +85,7 @@ func NewCollector(logger klog.Logger, trimaranSpec *pluginConfig.TrimaranSpec) (
}
// start periodic updates
go func() {
metricsUpdaterTicker := time.NewTicker(time.Second * metricsUpdateIntervalSeconds)
metricsUpdaterTicker := time.NewTicker(time.Second * time.Duration(metricsUpdateIntervalSeconds))
for range metricsUpdaterTicker.C {
err = collector.updateMetrics(logger)
if err != nil {
Expand Down