Skip to content
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

[Improvement] state/elasticsearch: add option to spread nodes in 3-AZs #524

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
40 changes: 30 additions & 10 deletions state/elasticsearch.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ Metadata:
- ElasticsearchVersion
- EBSEnabled
- EBSVolumeSize
- AvailabilityZones
- ClusterInstanceCount
- ClusterInstanceType
- DedicatedMasterCount
Expand Down Expand Up @@ -78,8 +79,13 @@ Parameters:
Type: String
Default: '5.5'
AllowedValues: ['7.7', '7.4', '7.1', '6.8', '6.7', '6.5', '6.4', '6.3', '6.2', '6.0', '5.6', '5.5'] # aws es list-elasticsearch-versions --query "ElasticsearchVersions[]"
AvailabilityZones:
Copy link
Contributor

Choose a reason for hiding this comment

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

What's the benefit of using a String instead of a Number type?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I can find the configuration value faster in the list of parameters, because it looks differently visually. I do not know anymore why I choose a string instead of a number, because the change was made months ago. It could be that I wanted to create a similarity to the 2azs and 3azs vpc templates.

Description: 'Number of Availability Zones nodes are spread across.'
Type: String
Default: '2-AZ'
AllowedValues: ['1-AZ', '2-AZ', '3-AZ']
ClusterInstanceCount:
Description: 'The number of data nodes (instances) to use in the Amazon ES domain.'
Description: 'The number of data nodes (instances) to use in the Amazon ES domain. If the defaul value of 1 is used, then automatically 1 node per Availability Zones is used. Therefore if 3-AZ is selected the value 1 and 3 produces the same result and 2 is not supported.'
Type: Number
Default: 1
ClusterInstanceType:
Expand All @@ -103,10 +109,12 @@ Conditions:
HasZone: !Not [!Equals [!Ref ParentZoneStack, '']]
HasSSHBastionSecurityGroup: !Not [!Equals [!Ref ParentSSHBastionStack, '']]
HasAlertTopic: !Not [!Equals [!Ref ParentAlertStack, '']]
HasSingleClusterInstance: !Equals [!Ref ClusterInstanceCount, '1']
HasDedicatedMasterNodes: !Not [!Equals [!Ref DedicatedMasterCount, 0]]
HasEBSEnabled: !Equals [!Ref EBSEnabled, 'true']
HasAlertTopicAndNotSingleClusterInstance: !And [!Condition HasAlertTopic, !Not [!Condition HasSingleClusterInstance]]
HasZoneAwareness: !Not [!Equals [!Ref AvailabilityZones, '1-AZ']]
HasAlertTopicAndZoneAwareness: !And [!Condition HasAlertTopic, !Condition HasZoneAwareness]
Has3AvailabilityZones: !Equals [!Ref AvailabilityZones, '3-AZ']
HasCustomClusterInstanceCount: !Not [!Equals [!Ref ClusterInstanceCount, 1]]
Resources:
RecordSet:
Condition: HasZone
Expand Down Expand Up @@ -163,25 +171,37 @@ Resources:
DedicatedMasterCount: !If [HasDedicatedMasterNodes, !Ref DedicatedMasterCount, !Ref 'AWS::NoValue']
DedicatedMasterEnabled: !If [HasDedicatedMasterNodes, true, false]
DedicatedMasterType: !If [HasDedicatedMasterNodes, !Ref DedicatedMasterType, !Ref 'AWS::NoValue']
InstanceCount: !Ref ClusterInstanceCount
InstanceCount: !If
Copy link
Contributor

Choose a reason for hiding this comment

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

Why did you decide to do it like that? Why not just use the InstanceCount in any case? Wouldn't that be less complex?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I always try to automatically set the correct values for dependent values and the count of instances must be at least the number of availability zones. I contemplated setting the default value to 0 and only then use the number of availability zones as instance count. But I was not sure if this will cause an issue if someone updates the template and is not aware, that the default value has changed.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should add one parameter AvailabilityZoneCount that can be either 2 or 3.

If InstanceCount = 1: we ignore AvailabilityZoneCount and use subnet A.
If InstanceCount > 1 && AvailabilityZoneCount = 2: we use subnet A, and B.
If InstanceCount > 1 && AvailabilityZoneCount = 3: we use subnetA, B, and C.

Would that make sense?

- HasCustomClusterInstanceCount
- !Ref ClusterInstanceCount
- !Select ['0', {'Fn::Split': ['-', !Ref AvailabilityZones]}]
InstanceType: !Ref ClusterInstanceType
ZoneAwarenessEnabled: !If [HasSingleClusterInstance, false, true]
ZoneAwarenessEnabled: !If [HasZoneAwareness, true, false]
ZoneAwarenessConfig: !If
- HasZoneAwareness
- AvailabilityZoneCount: !Select ['0', {'Fn::Split': ['-', !Ref AvailabilityZones]}]
- !Ref 'AWS::NoValue'
ElasticsearchVersion: !Ref ElasticsearchVersion
EncryptionAtRestOptions: !If [HasKmsKey, {Enabled: true, KmsKeyId: {'Fn::ImportValue': !Sub '${ParentKmsKeyStack}-KeyId'}}, !Ref 'AWS::NoValue']
SnapshotOptions:
AutomatedSnapshotStartHour: 10
VPCOptions:
SecurityGroupIds:
- !Ref SecurityGroup
SubnetIds: !If
- HasSingleClusterInstance
- - {'Fn::ImportValue': !Sub '${ParentVPCStack}-SubnetAPrivate'}
- - {'Fn::ImportValue': !Sub '${ParentVPCStack}-SubnetAPrivate'}
SubnetIds:
- {'Fn::ImportValue': !Sub '${ParentVPCStack}-SubnetAPrivate'}
- !If
- HasZoneAwareness
- {'Fn::ImportValue': !Sub '${ParentVPCStack}-SubnetBPrivate'}
- !Ref 'AWS::NoValue'
- !If
- Has3AvailabilityZones
- {'Fn::ImportValue': !Sub '${ParentVPCStack}-SubnetCPrivate'}
- !Ref 'AWS::NoValue'
UpdatePolicy:
EnableVersionUpgrade: true
ClusterStatusYellowAlarm:
Condition: HasAlertTopicAndNotSingleClusterInstance
Condition: HasAlertTopicAndZoneAwareness
Type: 'AWS::CloudWatch::Alarm'
Properties:
AlarmActions:
Expand Down