Skip to content

Commit

Permalink
add support for metrics collection in scaling config
Browse files Browse the repository at this point in the history
add name to humans.txt

reset go.mod

make metrics optional

add cloudformation mapping

regenerate

fix if statement

apply pr review changes

apply pr review changes

WIP

update schema and generated deepcopy

add tests and update docs

cleanup test comments
  • Loading branch information
Mahmoud Saada committed Apr 27, 2020
1 parent 7276297 commit 183c3ff
Show file tree
Hide file tree
Showing 8 changed files with 123 additions and 2 deletions.
13 changes: 12 additions & 1 deletion examples/05-advanced-nodegroups.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# An advanced example of ClusterConfig object with customised nodegroups:
---
---
apiVersion: eksctl.io/v1alpha5
kind: ClusterConfig

Expand Down Expand Up @@ -42,6 +42,17 @@ nodeGroups:
nodegroup-type: very-special-science-workloads
classicLoadBalancerNames:
- ng3-classic-load-balancer
asgMetricsCollection:
- granularity: 1Minute
metrics:
- GroupMinSize
- GroupMaxSize
- GroupDesiredCapacity
- GroupInServiceInstances
- GroupPendingInstances
- GroupStandbyInstances
- GroupTerminatingInstances
- GroupTotalInstances
taints:
special: "true:NoSchedule"
privateNetworking: true
Expand Down
11 changes: 11 additions & 0 deletions pkg/apis/eksctl.io/v1alpha5/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -619,6 +619,8 @@ type NodeGroup struct {
MinSize *int `json:"minSize,omitempty"`
// +optional
MaxSize *int `json:"maxSize,omitempty"`
// +optional
ASGMetricsCollection []MetricsCollection `json:"asgMetricsCollection,omitempty"`

// +optional
EBSOptimized *bool `json:"ebsOptimized,omitempty"`
Expand Down Expand Up @@ -787,6 +789,15 @@ type (
}
)

// MetricsCollection used by the scaling config
// https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-as-metricscollection.html
type MetricsCollection struct {
// +required
Granularity string `json:"granularity"`
// +optional
Metrics []string `json:"metrics,omitempty"`
}

// ScalingConfig defines the scaling config
type ScalingConfig struct {
// +optional
Expand Down
28 changes: 28 additions & 0 deletions pkg/apis/eksctl.io/v1alpha5/zz_generated.deepcopy.go

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

26 changes: 25 additions & 1 deletion pkg/cfn/builder/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ type Properties struct {
VPCZoneIdentifier interface{}

LoadBalancerNames []string
MetricsCollection []interface{}
TargetGroupARNs []string
DesiredCapacity, MinSize, MaxSize string

Expand Down Expand Up @@ -811,7 +812,15 @@ var _ = Describe("CloudFormation template builder API", func() {

Context("NodeGroupAutoScaling", func() {
cfg, ng := newClusterConfigAndNodegroup(true)

ng.ASGMetricsCollection = []api.MetricsCollection{
{
Granularity: "1Minute",
Metrics: []string{
"GroupMinSize",
"GroupMaxSize",
},
},
}
ng.ClassicLoadBalancerNames = []string{"clb-1", "clb-2"}
ng.TargetGroupARNs = []string{"tg-arn-1", "tg-arn-2"}

Expand Down Expand Up @@ -916,6 +925,21 @@ var _ = Describe("CloudFormation template builder API", func() {
Expect(ng.Properties.LoadBalancerNames).To(Equal([]string{"clb-1", "clb-2"}))
})

It("should have metrics collections set", func() {
Expect(ngTemplate.Resources).To(HaveKey("NodeGroup"))
ng := ngTemplate.Resources["NodeGroup"]
Expect(ng).ToNot(BeNil())
Expect(ng.Properties).ToNot(BeNil())

Expect(ng.Properties.MetricsCollection).ToNot(BeEmpty())
var metricsCollection map[string]interface{} = ng.Properties.MetricsCollection[0].(map[string]interface{})
Expect(metricsCollection).To(HaveKey("granularity"))
Expect(metricsCollection).To(HaveKey("metrics"))
Expect(metricsCollection["granularity"]).To(Equal("1Minute"))
Expect(metricsCollection["metrics"]).To(ContainElement("GroupMinSize"))
Expect(metricsCollection["metrics"]).To(ContainElement("GroupMaxSize"))
})

It("should have target groups ARNs set", func() {
Expect(ngTemplate.Resources).To(HaveKey("NodeGroup"))
ng := ngTemplate.Resources["NodeGroup"]
Expand Down
18 changes: 18 additions & 0 deletions pkg/cfn/builder/nodegroup.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,9 @@ func nodeGroupResource(launchTemplateName *gfn.Value, vpcZoneIdentifier interfac
if ng.MaxSize != nil {
ngProps["MaxSize"] = fmt.Sprintf("%d", *ng.MaxSize)
}
if len(ng.ASGMetricsCollection) > 0 {
ngProps["MetricsCollection"] = *metricsCollectionResource(ng.ASGMetricsCollection)
}
if len(ng.ClassicLoadBalancerNames) > 0 {
ngProps["LoadBalancerNames"] = ng.ClassicLoadBalancerNames
}
Expand Down Expand Up @@ -345,3 +348,18 @@ func mixedInstancesPolicy(launchTemplateName *gfn.Value, ng *api.NodeGroup) *map

return &policy
}

func metricsCollectionResource(asgMetricsCollection []api.MetricsCollection) *[]map[string]interface{} {
metricsCollections := make([]map[string]interface{}, len(asgMetricsCollection))
for _, m := range asgMetricsCollection {
newCollection := make(map[string]interface{})

metrics := make([]string, len(m.Metrics))
metrics = append(metrics, m.Metrics...)
newCollection["Metrics"] = metrics
newCollection["Granularity"] = m.Granularity

metricsCollections = append(metricsCollections, newCollection)
}
return &metricsCollections
}
1 change: 1 addition & 0 deletions userdocs/src/usage/eks-managed-nodes.md
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ the provisioned Autoscaling Group like in unmanaged nodegroups.
- Control over the node bootstrapping process and customization of the kubelet are not supported. This includes the
following fields: `classicLoadBalancerNames`, `maxPodsPerNode`, `taints`, `targetGroupARNs`, `preBootstrapCommands`, `overrideBootstrapCommand`,
`clusterDNS` and `kubeletExtraConfig`.
- No support for enabling metrics on AutoScalingGroups using `asgMetricsCollection`

## Note for eksctl versions below 0.12.0
- For clusters upgraded from EKS 1.13 to EKS 1.14, managed nodegroups will not be able to communicate with unmanaged
Expand Down
11 changes: 11 additions & 0 deletions userdocs/src/usage/managing-nodegroups.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,17 @@ nodeGroups:
classicLoadBalancerNames:
- dev-clb-1
- dev-clb-2
asgMetricsCollection:
- granularity: 1Minute
metrics:
- GroupMinSize
- GroupMaxSize
- GroupDesiredCapacity
- GroupInServiceInstances
- GroupPendingInstances
- GroupStandbyInstances
- GroupTerminatingInstances
- GroupTotalInstances
- name: ng-2-api
labels: { role: api }
instanceType: m5.2xlarge
Expand Down
17 changes: 17 additions & 0 deletions userdocs/src/usage/schema.md
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,18 @@ ManagedNodeGroup:
- ScalingConfig
- privateNetworking
type: object
MetricsCollection:
additionalProperties: false
properties:
granularity:
type: string
metrics:
items:
type: string
type: array
required:
- granularity
type: object
Network:
additionalProperties: false
properties:
Expand All @@ -369,6 +381,11 @@ NodeGroup:
type: string
amiFamily:
type: string
asgMetricsCollection:
items:
$ref: '#/definitions/MetricsCollection'
$schema: http://json-schema.org/draft-04/schema#
type: array
availabilityZones:
items:
type: string
Expand Down

0 comments on commit 183c3ff

Please sign in to comment.