Skip to content

Commit d02660b

Browse files
committed
fix linting issues
1 parent 8d4c3aa commit d02660b

File tree

3 files changed

+36
-12
lines changed

3 files changed

+36
-12
lines changed

cluster-autoscaler/core/scaledown/latencytracker/node_latency_tracker.go

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
/*
2+
Copyright 2019 The Kubernetes Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
117
package latencytracker
218

319
import (
@@ -8,25 +24,31 @@ import (
824
"k8s.io/klog/v2"
925
)
1026

27+
// LatencyTracker defines the interface for tracking node removal latency.
28+
// Implementations record when nodes become unneeded, observe deletion events,
29+
// and expose thresholds for measuring node removal duration.
1130
type LatencyTracker interface {
1231
ObserveDeletion(nodeName string, timestamp time.Time)
1332
UpdateStateWithUnneededList(list []*apiv1.Node, currentlyInDeletion map[string]bool, timestamp time.Time)
1433
UpdateThreshold(nodeName string, threshold time.Duration)
1534
GetTrackedNodes() []string
1635
}
17-
type NodeInfo struct {
36+
type nodeInfo struct {
1837
UnneededSince time.Time
1938
Threshold time.Duration
2039
}
2140

41+
// NodeLatencyTracker is a concrete implementation of LatencyTracker.
42+
// It keeps track of nodes that are marked as unneeded, when they became unneeded,
43+
// and thresholds to adjust node removal latency metrics.
2244
type NodeLatencyTracker struct {
23-
nodes map[string]NodeInfo
45+
nodes map[string]nodeInfo
2446
}
2547

2648
// NewNodeLatencyTracker creates a new tracker.
2749
func NewNodeLatencyTracker() *NodeLatencyTracker {
2850
return &NodeLatencyTracker{
29-
nodes: make(map[string]NodeInfo),
51+
nodes: make(map[string]nodeInfo),
3052
}
3153
}
3254

@@ -41,7 +63,7 @@ func (t *NodeLatencyTracker) UpdateStateWithUnneededList(
4163
currentSet[node.Name] = struct{}{}
4264

4365
if _, exists := t.nodes[node.Name]; !exists {
44-
t.nodes[node.Name] = NodeInfo{
66+
t.nodes[node.Name] = nodeInfo{
4567
UnneededSince: timestamp,
4668
Threshold: 0,
4769
}

cluster-autoscaler/core/scaledown/latencytracker/node_latency_tracker_test.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
/*
2-
Copyright 2024 The Kubernetes Authors.
2+
Copyright 2019 The Kubernetes Authors.
33
44
Licensed under the Apache License, Version 2.0 (the "License");
55
you may not use this file except in compliance with the License.
66
You may obtain a copy of the License at
77
88
http://www.apache.org/licenses/LICENSE-2.0
99
10-
Unless required by applicable law or agreed to in writing,
11-
software distributed under the License is distributed on an "AS IS" BASIS,
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
1212
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1313
See the License for the specific language governing permissions and
1414
limitations under the License.
@@ -29,7 +29,7 @@ func TestNodeLatencyTracker(t *testing.T) {
2929

3030
tests := []struct {
3131
name string
32-
setupNodes map[string]NodeInfo
32+
setupNodes map[string]nodeInfo
3333
unneededList []string
3434
currentlyInDeletion map[string]bool
3535
updateThresholds map[string]time.Duration
@@ -39,7 +39,7 @@ func TestNodeLatencyTracker(t *testing.T) {
3939
}{
4040
{
4141
name: "add new unneeded nodes",
42-
setupNodes: map[string]NodeInfo{},
42+
setupNodes: map[string]nodeInfo{},
4343
unneededList: []string{"node1", "node2"},
4444
currentlyInDeletion: map[string]bool{},
4545
updateThresholds: map[string]time.Duration{},
@@ -48,7 +48,7 @@ func TestNodeLatencyTracker(t *testing.T) {
4848
},
4949
{
5050
name: "observe deletion with threshold",
51-
setupNodes: map[string]NodeInfo{
51+
setupNodes: map[string]nodeInfo{
5252
"node1": {UnneededSince: baseTime, Threshold: 2 * time.Second},
5353
},
5454
unneededList: []string{},
@@ -62,7 +62,7 @@ func TestNodeLatencyTracker(t *testing.T) {
6262
},
6363
{
6464
name: "remove unneeded node not in deletion",
65-
setupNodes: map[string]NodeInfo{
65+
setupNodes: map[string]nodeInfo{
6666
"node1": {UnneededSince: baseTime, Threshold: 1 * time.Second},
6767
"node2": {UnneededSince: baseTime, Threshold: 0},
6868
},
@@ -77,7 +77,7 @@ func TestNodeLatencyTracker(t *testing.T) {
7777
},
7878
{
7979
name: "update threshold",
80-
setupNodes: map[string]NodeInfo{
80+
setupNodes: map[string]nodeInfo{
8181
"node1": {UnneededSince: baseTime, Threshold: 1 * time.Second},
8282
},
8383
unneededList: []string{"node1"},

cluster-autoscaler/metrics/metrics.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -761,6 +761,8 @@ func ObserveBinpackingHeterogeneity(instanceType, cpuCount, namespaceCount strin
761761
binpackingHeterogeneity.WithLabelValues(instanceType, cpuCount, namespaceCount).Observe(float64(pegCount))
762762
}
763763

764+
// UpdateScaleDownNodeDeletionDuration records the time after which node was deleted/needed
765+
// again after being marked unneded
764766
func UpdateScaleDownNodeDeletionDuration(deleted string, duration time.Duration) {
765767
scaleDownNodeDeletionDuration.WithLabelValues(deleted).Observe(duration.Seconds())
766768
}

0 commit comments

Comments
 (0)