Skip to content

Commit

Permalink
Update to support 15+, 16+ (#15)
Browse files Browse the repository at this point in the history
* Update to support 15+, 16+

Includes instance class map and updated script to buildm dropdowns

* rebased + new versions

* add warning to massdriver.yaml

* adding a codeowners file
  • Loading branch information
coryodaniel authored May 7, 2024
1 parent feed219 commit a120f09
Show file tree
Hide file tree
Showing 5 changed files with 887 additions and 839 deletions.
4 changes: 4 additions & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# This is a CODEOWNERS file
# It defines the individuals or teams responsible for code in this repository.

* @coryodaniel
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ release:
massdriver.yaml:
./hack/update-engine-versions.rb
./hack/update-instance-classes.rb
echo "# This file is autogenerated, do not edit directly. See 'make massdriver.yaml'" > /tmp/aws-aurora-postgres.txt
cat massdriver.yaml >> /tmp/aws-aurora-postgres.txt
mv /tmp/aws-aurora-postgres.txt massdriver.yaml

publish: massdriver.yaml build
mass bundle publish
Expand Down
56 changes: 28 additions & 28 deletions hack/update-instance-classes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,18 @@
$engine = "aurora-postgresql"
$region = "us-east-1"
$engines_file = "/tmp/aws-rds-#{$engine}-engines.json"
# db instance name to ec2 details

# Map of instance class name to instance details
$instance_classes = {}

# tracks group id to list of aws instance classes
# tracks JSON Schema group id to list of aws instance classes
$instances_classes_in_group = {}

# This is an optimization around minimizing the number of oneOfs w/ repeated instance classes
engine_version_to_instance_class_group = {}

def generate_instance_class_group_jsonschema_id(instance_classes)
group_id = Digest::SHA2.hexdigest(instance_classes.sort.join(','))
group_id = Digest::SHA2.hexdigest(instance_classes.uniq.sort.join(','))

$instances_classes_in_group[group_id] = instance_classes

Expand All @@ -29,7 +30,7 @@ def generate_instance_class_group_jsonschema_id(instance_classes)
conf = YAML.load(File.read($mdyaml))

def maybe_get_data(cmd, file, force)
if !File.exists?(file) || force
if !File.exist?(file) || force
`#{cmd} > #{file}`
else
puts "#{file} exists, skipping fetch..."
Expand Down Expand Up @@ -93,7 +94,6 @@ def transform_instance_class_from(t, from)
instances["OrderableDBInstanceOptions"].each do |v|
next if !supported_engine_versions.member?(v["EngineVersion"])
rds_instance_class = v["DBInstanceClass"]

supported_engine_versions_to_instance_class_map[engine_version].push(rds_instance_class)

if rds_instance_class == "db.serverless"
Expand All @@ -116,6 +116,7 @@ def transform_instance_class_from(t, from)
engine_version_to_instance_class_group[engine_version] = group_id
end

# Get instance details, only 100 at a time supported by API
$instance_classes.each_slice(100) do |instance_class_chunk|
chunked_ec2_names = instance_class_chunk.map{|_k, v| v[:EC2InstanceType]}
joined_for_cli = chunked_ec2_names.join(' ')
Expand All @@ -126,37 +127,36 @@ def transform_instance_class_from(t, from)
details = read_json_file(file)

details["InstanceTypes"].each do |deets|
if deets["CurrentGeneration"]
rds_instance_class = transform_instance_class_from(deets["InstanceType"], :ec2)
gib = deets["MemoryInfo"]["SizeInMiB"] / 1_024
vcpus = deets["VCpuInfo"]["DefaultVCpus"]

note = if deets["InstanceType"].start_with?("t")
"Burstable"
else
"Memory Optimized"
end

$instance_classes[rds_instance_class].merge!({
RDSInstanceType: rds_instance_class,
EC2InstanceType: deets["InstanceType"],
DefaultVCpus: vcpus,
SizeInGiB: gib,
Note: note,
Label: "#{note} #{gib} GiB, #{vcpus} vCPUs (#{rds_instance_class})"
})
rds_instance_class = transform_instance_class_from(deets["InstanceType"], :ec2)
gib = deets["MemoryInfo"]["SizeInMiB"] / 1_024
vcpus = deets["VCpuInfo"]["DefaultVCpus"]

note = if deets["InstanceType"].start_with?("t")
"Burstable"
else
"Memory Optimized"
end

$instance_classes[rds_instance_class].merge!({
CurrentGeneration: deets["CurrentGeneration"],
RDSInstanceType: rds_instance_class,
EC2InstanceType: deets["InstanceType"],
DefaultVCpus: vcpus,
SizeInGiB: gib,
Note: note,
Label: "#{note} #{gib} GiB, #{vcpus} vCPUs (#{rds_instance_class})"
})
end
end

## Build params $defs of instance group ids
conf["params"]["$defs"] = {}

engine_version_to_instance_class_group.values.uniq.each do |group_id|
formatted_instance_classes = $instances_classes_in_group[group_id].
map {|rds_instance_class| $instance_classes[rds_instance_class]}.
sort { |a,b| [a[:DefaultVCpus], a[:SizeInGiB]] <=> [b[:DefaultVCpus] , b[:SizeInGiB]]}.
map {|ic| {"title" => ic[:Label], "const" => ic[:RDSInstanceType]}}
formatted_instance_classes = $instances_classes_in_group[group_id].uniq.
map { |rds_instance_class| $instance_classes[rds_instance_class]}.
sort { |a,b| [a[:DefaultVCpus], a[:SizeInGiB]] <=> [b[:DefaultVCpus] , b[:SizeInGiB]] }.
map { |ic| {"title" => ic[:Label], "const" => ic[:RDSInstanceType]}}

conf["params"]["$defs"]["instance-class-group-#{group_id}"] = {
"title" => "Instance Class",
Expand Down
Loading

0 comments on commit a120f09

Please sign in to comment.