Skip to content

Commit 96e74f2

Browse files
authored
Merge pull request #174 from awprice/issue-125
add corresponding node group name to cloud provider node group metrics
2 parents 2f9659f + 53fa9a9 commit 96e74f2

File tree

6 files changed

+73
-38
lines changed

6 files changed

+73
-38
lines changed

cmd/main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ func setupCloudProvider(nodegroups []controller.NodeGroupOptions) cloudprovider.
6767
var nodeGroupConfigs []cloudprovider.NodeGroupConfig
6868
for _, n := range nodegroups {
6969
nodeGroupConfigs = append(nodeGroupConfigs, cloudprovider.NodeGroupConfig{
70+
Name: n.Name,
7071
GroupID: n.CloudProviderGroupName,
7172
AWSConfig: cloudprovider.AWSNodeGroupConfig{
7273
LaunchTemplateID: n.AWS.LaunchTemplateID,

pkg/cloudprovider/aws/aws.go

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,10 @@ func (c *CloudProvider) RegisterNodeGroups(groups ...cloudprovider.NodeGroupConf
8989

9090
// Update metrics for each node group
9191
for _, nodeGroup := range c.nodeGroups {
92-
metrics.CloudProviderMinSize.WithLabelValues(c.Name(), nodeGroup.ID()).Set(float64(nodeGroup.MinSize()))
93-
metrics.CloudProviderMaxSize.WithLabelValues(c.Name(), nodeGroup.ID()).Set(float64(nodeGroup.MaxSize()))
94-
metrics.CloudProviderTargetSize.WithLabelValues(c.Name(), nodeGroup.ID()).Set(float64(nodeGroup.TargetSize()))
95-
metrics.CloudProviderSize.WithLabelValues(c.Name(), nodeGroup.ID()).Set(float64(nodeGroup.Size()))
92+
metrics.CloudProviderMinSize.WithLabelValues(c.Name(), nodeGroup.ID(), nodeGroup.Name()).Set(float64(nodeGroup.MinSize()))
93+
metrics.CloudProviderMaxSize.WithLabelValues(c.Name(), nodeGroup.ID(), nodeGroup.Name()).Set(float64(nodeGroup.MaxSize()))
94+
metrics.CloudProviderTargetSize.WithLabelValues(c.Name(), nodeGroup.ID(), nodeGroup.Name()).Set(float64(nodeGroup.TargetSize()))
95+
metrics.CloudProviderSize.WithLabelValues(c.Name(), nodeGroup.ID(), nodeGroup.Name()).Set(float64(nodeGroup.Size()))
9696
}
9797

9898
return nil
@@ -155,8 +155,9 @@ func (i *Instance) ID() string {
155155

156156
// NodeGroup implements a aws nodegroup
157157
type NodeGroup struct {
158-
id string
159-
asg *autoscaling.Group
158+
id string
159+
name string
160+
asg *autoscaling.Group
160161

161162
provider *CloudProvider
162163
config *cloudprovider.NodeGroupConfig
@@ -166,6 +167,7 @@ type NodeGroup struct {
166167
func NewNodeGroup(config *cloudprovider.NodeGroupConfig, asg *autoscaling.Group, provider *CloudProvider) *NodeGroup {
167168
return &NodeGroup{
168169
id: config.GroupID,
170+
name: config.Name,
169171
asg: asg,
170172
provider: provider,
171173
config: config,
@@ -181,6 +183,11 @@ func (n *NodeGroup) ID() string {
181183
return n.id
182184
}
183185

186+
// Name returns the name of the node group for this cloud provider node group.
187+
func (n *NodeGroup) Name() string {
188+
return n.name
189+
}
190+
184191
// MinSize returns minimum size of the node group.
185192
func (n *NodeGroup) MinSize() int64 {
186193
return awsapi.Int64Value(n.asg.MinSize)

pkg/cloudprovider/interface.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ type CloudProvider interface {
2626
// In particular the list of node groups returned by NodeGroups can change as a result of CloudProvider.Refresh().
2727
Refresh() error
2828

29+
// GetInstance returns a cloud provider Instance for the provided node. Contains the cloud provider specific
30+
// instance for cloud provider specific results.
2931
GetInstance(node *v1.Node) (Instance, error)
3032
}
3133

@@ -47,6 +49,9 @@ type NodeGroup interface {
4749
// ID returns an unique identifier of the node group.
4850
ID() string
4951

52+
// Name returns the name of the node group for this cloud provider node group.
53+
Name() string
54+
5055
// MinSize returns minimum size of the node group.
5156
MinSize() int64
5257

@@ -99,6 +104,7 @@ type BuildOpts struct {
99104

100105
// NodeGroupConfig contains the configuration for a node group
101106
type NodeGroupConfig struct {
107+
Name string
102108
GroupID string
103109
AWSConfig AWSNodeGroupConfig
104110
}

pkg/controller/controller_scale_node_group_test.go

Lines changed: 41 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -67,15 +67,16 @@ func buildTestClient(nodes []*v1.Node, pods []*v1.Pod, nodeGroups []NodeGroupOpt
6767
// the controller should untaint all tainted nodes to get above the new min ASG size instead of bringing up new nodes first
6868
func TestUntaintNodeGroupMinNodes(t *testing.T) {
6969
t.Run("10 minNodes, 10 tainted, 0 untainted - scale up by untainting", func(t *testing.T) {
70-
nodeGroupName := "default"
7170
minNodes := 10
7271
maxNodes := 20
73-
nodeGroups := []NodeGroupOptions{{
74-
Name: nodeGroupName,
72+
nodeGroup := NodeGroupOptions{
73+
Name: "default",
74+
CloudProviderGroupName: "default",
7575
MinNodes: minNodes,
7676
MaxNodes: maxNodes,
7777
ScaleUpThresholdPercent: 100,
78-
}}
78+
}
79+
nodeGroups := []NodeGroupOptions{nodeGroup}
7980

8081
nodes := test.BuildTestNodes(10, test.NodeOpts{
8182
CPU: 1000,
@@ -91,7 +92,8 @@ func TestUntaintNodeGroupMinNodes(t *testing.T) {
9192
// Create a test (mock) cloud provider
9293
testCloudProvider := test.NewCloudProvider(nodeGroupSize)
9394
testNodeGroup := test.NewNodeGroup(
94-
nodeGroupName,
95+
nodeGroup.CloudProviderGroupName,
96+
nodeGroup.Name,
9597
int64(minNodes),
9698
int64(maxNodes),
9799
int64(len(nodes)),
@@ -112,10 +114,10 @@ func TestUntaintNodeGroupMinNodes(t *testing.T) {
112114
cloudProvider: testCloudProvider,
113115
}
114116

115-
_, err := controller.scaleNodeGroup(nodeGroupName, nodeGroupsState[nodeGroupName])
117+
_, err := controller.scaleNodeGroup(nodeGroup.Name, nodeGroupsState[nodeGroup.Name])
116118
assert.NoError(t, err)
117119

118-
untainted, tainted, _ := controller.filterNodes(nodeGroupsState[nodeGroupName], nodes)
120+
untainted, tainted, _ := controller.filterNodes(nodeGroupsState[nodeGroup.Name], nodes)
119121
// Ensure that the tainted nodes where untainted
120122
assert.Equal(t, minNodes, len(untainted))
121123
assert.Equal(t, 0, len(tainted))
@@ -126,15 +128,16 @@ func TestUntaintNodeGroupMinNodes(t *testing.T) {
126128
// it will untaint them before trying to scale up the cloud provider
127129
func TestUntaintNodeGroupMaxNodes(t *testing.T) {
128130
t.Run("10 maxNodes, 5 tainted, 5 untainted - scale up", func(t *testing.T) {
129-
nodeGroupName := "default"
130131
minNodes := 2
131132
maxNodes := 10
132-
nodeGroups := []NodeGroupOptions{{
133-
Name: nodeGroupName,
133+
nodeGroup := NodeGroupOptions{
134+
Name: "default",
135+
CloudProviderGroupName: "default",
134136
MinNodes: minNodes,
135137
MaxNodes: maxNodes,
136138
ScaleUpThresholdPercent: 70,
137-
}}
139+
}
140+
nodeGroups := []NodeGroupOptions{nodeGroup}
138141

139142
nodes := test.BuildTestNodes(5, test.NodeOpts{
140143
CPU: 1000,
@@ -155,7 +158,8 @@ func TestUntaintNodeGroupMaxNodes(t *testing.T) {
155158
// Create a test (mock) cloud provider
156159
testCloudProvider := test.NewCloudProvider(nodeGroupSize)
157160
testNodeGroup := test.NewNodeGroup(
158-
nodeGroupName,
161+
nodeGroup.CloudProviderGroupName,
162+
nodeGroup.Name,
159163
int64(minNodes),
160164
int64(maxNodes),
161165
int64(len(nodes)),
@@ -176,9 +180,9 @@ func TestUntaintNodeGroupMaxNodes(t *testing.T) {
176180
cloudProvider: testCloudProvider,
177181
}
178182

179-
controller.scaleNodeGroup(nodeGroupName, nodeGroupsState[nodeGroupName])
183+
controller.scaleNodeGroup(nodeGroup.Name, nodeGroupsState[nodeGroup.Name])
180184

181-
untainted, tainted, _ := controller.filterNodes(nodeGroupsState[nodeGroupName], nodes)
185+
untainted, tainted, _ := controller.filterNodes(nodeGroupsState[nodeGroup.Name], nodes)
182186
// Ensure that the tainted nodes where untainted
183187
assert.Equal(t, maxNodes, len(untainted))
184188
assert.Equal(t, 0, len(tainted))
@@ -307,8 +311,9 @@ func TestScaleNodeGroup(t *testing.T) {
307311
nodeArgs{1, 0, 0},
308312
buildTestPods(0, 0, 0),
309313
NodeGroupOptions{
310-
Name: "default",
311-
MinNodes: 5,
314+
Name: "default",
315+
CloudProviderGroupName: "default",
316+
MinNodes: 5,
312317
},
313318
ListerOptions{},
314319
},
@@ -320,8 +325,9 @@ func TestScaleNodeGroup(t *testing.T) {
320325
nodeArgs{10, 0, 0},
321326
buildTestPods(0, 0, 0),
322327
NodeGroupOptions{
323-
Name: "default",
324-
MaxNodes: 5,
328+
Name: "default",
329+
CloudProviderGroupName: "default",
330+
MaxNodes: 5,
325331
},
326332
ListerOptions{},
327333
},
@@ -333,9 +339,10 @@ func TestScaleNodeGroup(t *testing.T) {
333339
nodeArgs{10, 0, 0},
334340
buildTestPods(5, 0, 0),
335341
NodeGroupOptions{
336-
Name: "default",
337-
MinNodes: 1,
338-
MaxNodes: 100,
342+
Name: "default",
343+
CloudProviderGroupName: "default",
344+
MinNodes: 1,
345+
MaxNodes: 100,
339346
},
340347
ListerOptions{},
341348
},
@@ -347,9 +354,10 @@ func TestScaleNodeGroup(t *testing.T) {
347354
nodeArgs{10, -100, 0},
348355
buildTestPods(5, 0, -100),
349356
NodeGroupOptions{
350-
Name: "default",
351-
MinNodes: 1,
352-
MaxNodes: 100,
357+
Name: "default",
358+
CloudProviderGroupName: "default",
359+
MinNodes: 1,
360+
MaxNodes: 100,
353361
},
354362
ListerOptions{},
355363
},
@@ -361,9 +369,10 @@ func TestScaleNodeGroup(t *testing.T) {
361369
nodeArgs{10, -100, -100},
362370
buildTestPods(5, -100, -100),
363371
NodeGroupOptions{
364-
Name: "default",
365-
MinNodes: 1,
366-
MaxNodes: 100,
372+
Name: "default",
373+
CloudProviderGroupName: "default",
374+
MinNodes: 1,
375+
MaxNodes: 100,
367376
},
368377
ListerOptions{},
369378
},
@@ -376,6 +385,7 @@ func TestScaleNodeGroup(t *testing.T) {
376385
buildTestPods(5, 1000, 2000),
377386
NodeGroupOptions{
378387
Name: "default",
388+
CloudProviderGroupName: "default",
379389
MinNodes: 1,
380390
MaxNodes: 100,
381391
ScaleUpThresholdPercent: 70,
@@ -395,6 +405,7 @@ func TestScaleNodeGroup(t *testing.T) {
395405
buildTestPods(5, 1000, 2000),
396406
NodeGroupOptions{
397407
Name: "default",
408+
CloudProviderGroupName: "default",
398409
MinNodes: 1,
399410
MaxNodes: 100,
400411
ScaleUpThresholdPercent: 70,
@@ -414,6 +425,7 @@ func TestScaleNodeGroup(t *testing.T) {
414425
buildTestPods(5, 1000, 2000),
415426
NodeGroupOptions{
416427
Name: "default",
428+
CloudProviderGroupName: "default",
417429
MinNodes: 1,
418430
MaxNodes: 100,
419431
ScaleUpThresholdPercent: 70,
@@ -453,6 +465,7 @@ func TestScaleNodeGroup(t *testing.T) {
453465
// Create a test (mock) cloud provider
454466
testCloudProvider := test.NewCloudProvider(nodeGroupSize)
455467
testNodeGroup := test.NewNodeGroup(
468+
tt.args.nodeGroupOptions.CloudProviderGroupName,
456469
tt.args.nodeGroupOptions.Name,
457470
int64(tt.args.nodeGroupOptions.MinNodes),
458471
int64(tt.args.nodeGroupOptions.MaxNodes),
@@ -673,6 +686,7 @@ func TestScaleNodeGroup_MultipleRuns(t *testing.T) {
673686
// Create a test (mock) cloud provider
674687
testCloudProvider := test.NewCloudProvider(nodeGroupSize)
675688
testNodeGroup := test.NewNodeGroup(
689+
tt.args.nodeGroupOptions.CloudProviderGroupName,
676690
tt.args.nodeGroupOptions.Name,
677691
int64(tt.args.nodeGroupOptions.MinNodes),
678692
int64(tt.args.nodeGroupOptions.MaxNodes),

pkg/metrics/metrics.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ var (
197197
Namespace: NAMESPACE,
198198
Help: "current cloud provider minimum size",
199199
},
200-
[]string{"cloud_provider", "id"},
200+
[]string{"cloud_provider", "id", "node_group"},
201201
)
202202
// CloudProviderMaxSize indicates the current cloud provider maximum size
203203
CloudProviderMaxSize = prometheus.NewGaugeVec(
@@ -206,7 +206,7 @@ var (
206206
Namespace: NAMESPACE,
207207
Help: "current cloud provider maximum size",
208208
},
209-
[]string{"cloud_provider", "id"},
209+
[]string{"cloud_provider", "id", "node_group"},
210210
)
211211
// CloudProviderTargetSize indicates the current cloud provider target size
212212
CloudProviderTargetSize = prometheus.NewGaugeVec(
@@ -215,7 +215,7 @@ var (
215215
Namespace: NAMESPACE,
216216
Help: "current cloud provider target size",
217217
},
218-
[]string{"cloud_provider", "id"},
218+
[]string{"cloud_provider", "id", "node_group"},
219219
)
220220
// CloudProviderSize indicates the current cloud provider size
221221
CloudProviderSize = prometheus.NewGaugeVec(
@@ -224,7 +224,7 @@ var (
224224
Namespace: NAMESPACE,
225225
Help: "current cloud provider size",
226226
},
227-
[]string{"cloud_provider", "id"},
227+
[]string{"cloud_provider", "id", "node_group"},
228228
)
229229
)
230230

pkg/test/cloud_provider.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,16 +80,18 @@ func (i Instance) ID() string {
8080
// NodeGroup is a mock implementation of NodeGroup for testing
8181
type NodeGroup struct {
8282
id string
83+
name string
8384
minSize int64
8485
maxSize int64
8586
actualSize int64
8687
targetSize int64
8788
}
8889

8990
// NewNodeGroup creates a new mock NodeGroup
90-
func NewNodeGroup(id string, minSize int64, maxSize int64, targetSize int64) *NodeGroup {
91+
func NewNodeGroup(id string, name string, minSize int64, maxSize int64, targetSize int64) *NodeGroup {
9192
return &NodeGroup{
9293
id,
94+
name,
9395
minSize,
9496
maxSize,
9597
targetSize,
@@ -107,6 +109,11 @@ func (n *NodeGroup) ID() string {
107109
return n.id
108110
}
109111

112+
// Name mock implementation for NodeGroup
113+
func (n *NodeGroup) Name() string {
114+
return n.name
115+
}
116+
110117
// MinSize mock implementation for NodeGroup
111118
func (n *NodeGroup) MinSize() int64 {
112119
return n.minSize

0 commit comments

Comments
 (0)